private void LoadData()
        {
            try
            {
                Progress.SetMessage("Reading proteins from " + proteinFile + " ...");
                format.Progress = Progress;
                proteins        = format.ReadFromFile(proteinFile);

                List <IIdentifiedSpectrum> spectra = proteins.GetSpectra();

                Progress.SetMessage("Reading itraqs from " + itrapFile + " ...");
                ITraqItemUtils.LoadITraq(spectra, itrapFile, true, Progress);

                for (int i = proteins.Count - 1; i >= 0; i--)
                {
                    var group = proteins[i];
                    group[0].Peptides.RemoveAll(m => m.Spectrum.FindIsobaricItem() == null);
                    if (group[0].Peptides.Count == 0)
                    {
                        proteins.Remove(group);
                    }
                }
            }
            catch (UserTerminatedException)
            {
                Progress.SetMessage("User terminated.");
            }
            catch (Exception ex)
            {
                Progress.SetMessage("Error : {0}", ex.Message);
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        protected List <IIdentifiedSpectrum> GetSpectra(string fileName)
        {
            Progress.SetMessage("Reading peptides ...");
            List <IIdentifiedSpectrum> spectra = format.ReadFromFile(fileName);

            Progress.SetMessage("Reading itraq ...");
            IsobaricResult itraq = ITraqResultFileFormatFactory.GetXmlFormat().ReadFromFile(rawFileName);

            Progress.SetMessage("Matching peptide and itraq ...");

            ITraqItemUtils.MatchPeptideWithItraq(itraq, spectra);

            return(spectra);
        }
        public override IEnumerable <string> Process(string fileName)
        {
            option.ProteinFileName = fileName;

            Progress.SetMessage("Reading proteins...");

            IIdentifiedResult ir = GetIdentifiedResult(fileName);

            List <IIdentifiedSpectrum> spectra = ir.GetSpectra();

            if (option.QuantifyModifiedPeptideOnly)
            {
                spectra.RemoveAll(m =>
                {
                    foreach (char c in option.ModificationChars)
                    {
                        if (m.Sequence.Contains(c))
                        {
                            return(false);
                        }
                    }
                    return(true);
                });
            }

            ITraqItemUtils.LoadITraq(spectra, option.ITraqFileName, false, this.Progress);

            var itraqs = (from s in spectra
                          where s.FindIsobaricItem() != null
                          select s.FindIsobaricItem()).ToList();

            if (itraqs.Count == 0)
            {
                throw new Exception("No itraq information matched from " + option.ITraqFileName);
            }

            Progress.SetMessage("Calculating ...");
            var funcs = itraqs[0].PlexType.GetFuncs();

            funcs.RemoveAll(m => option.References.Any(n => n.Name.Equals(m.Name)));

            option.GetValidator().Validate(itraqs);

            foreach (var dsName in option.DatasetMap.Keys)
            {
                var dsSet = new HashSet <string>(option.DatasetMap[dsName]);
                foreach (var func in funcs)
                {
                    var channelName = func.ChannelRatioName;
                    foreach (var group in ir)
                    {
                        CalculateProteinRatio(group, func.GetValue, dsName, channelName, dsSet);
                    }
                }
            }

            if (option.NormalizeByMedianRatio)
            {
                foreach (var dsName in option.DatasetMap.Keys)
                {
                    foreach (var func in funcs)
                    {
                        var channelName = func.ChannelRatioName;
                        var groups      = (from g in ir
                                           let item = g[0].FindITraqChannelItem(dsName, channelName)
                                                      where null != item && item.HasRatio
                                                      select new { Group = g, LogRatio = Math.Log(item.Ratio) }).ToList();


                        var ratios = (from g in groups
                                      select g.LogRatio).ToArray();

                        if (ratios.Length > 1)
                        {
                            var mean = Statistics.Mean(ratios);
                            foreach (var g in groups)
                            {
                                var ratio         = g.Group[0].FindITraqChannelItem(dsName, channelName).Ratio;
                                var logRatio      = Math.Log(ratio);
                                var fixedLogRatio = logRatio - mean;
                                var fixedRatio    = Math.Exp(fixedLogRatio);
                                foreach (var p in g.Group)
                                {
                                    p.FindITraqChannelItem(dsName, channelName).Ratio = fixedRatio;
                                }
                            }
                        }
                    }
                }
            }

            var irFormat = GetFormat(ir);

            var refNames = (from refF in option.References
                            select refF.Name).Merge("");

            string resultFileName = GetResultFileName(fileName, refNames);

            irFormat.WriteToFile(resultFileName, ir);

            string paramFileName = Path.ChangeExtension(resultFileName, ".param");

            option.SaveToFile(paramFileName);

            var statFileName = Path.ChangeExtension(resultFileName, ".stat");

            using (StreamWriter sw = new StreamWriter(statFileName))
            {
                DoStatistic(sw, funcs, ir);
            }

            Progress.SetMessage("Finished.");

            return(new[] { resultFileName, statFileName });
        }