Ejemplo n.º 1
0
        public override IEnumerable <string> Process(string filename)
        {
            SequestResultTextFormat format = new SequestResultTextFormat();

            Progress.SetMessage("Reading from " + filename + "...");
            IIdentifiedResult sr = format.ReadFromFile(filename);

            HashSet <IIdentifiedSpectrum> result = new HashSet <IIdentifiedSpectrum>();

            foreach (IIdentifiedProteinGroup spg in sr)
            {
                if (acceptFunc(spg))
                {
                    result.UnionWith(spg[0].GetSpectra());
                }
            }

            List <IIdentifiedSpectrum> spectra = new List <IIdentifiedSpectrum>(result);

            spectra.Sort();

            string resultFilename = MyConvert.Format("{0}.{1}.peptides", filename, uniqueStr);

            Progress.SetMessage("Writing to " + resultFilename + "...");
            new SequestPeptideTextFormat(format.PeptideFormat.GetHeader()).WriteToFile(resultFilename, spectra);
            Progress.SetMessage("Finished");

            return(new[] { resultFilename });
        }
Ejemplo n.º 2
0
        protected override void ParseToCalculationItems()
        {
            IIdentifiedResult sr = format.ReadFromFile(option.SourceFileName);

            calculationItems =
                (from proteinGroup in sr
                 select new CalculationItem()
            {
                Key = proteinGroup,
                Peptides = proteinGroup[0].GetDistinctPeptides()
            }).ToList();
        }
        public override IEnumerable <string> Process(string fileName)
        {
            var format = new SequestResultTextFormat();

            format.Progress = this.Progress;

            Progress.SetMessage("Reading identified result from " + fileName + " ...");
            IIdentifiedResult ir = format.ReadFromFile(fileName);

            Progress.SetMessage("Removing duplicated peptide ...");
            Progress.SetRange(0, ir.Count);
            for (int i = 0; i < ir.Count; i++)
            {
                Progress.SetPosition(i);
                IIdentifiedProteinGroup    group = ir[i];
                List <IIdentifiedSpectrum> peps  = UniquePeptideDistiller.KeepMaxScorePeptideOnly(group.GetPeptides());
                foreach (var protein in group)
                {
                    protein.Peptides.RemoveAll(m => !peps.Contains(m.Spectrum));
                }
            }

            string resultFileName = fileName + ".unique";

            Progress.SetMessage("Saving proteins to " + resultFileName + " ...");
            format.WriteToFile(resultFileName, ir);

            List <IIdentifiedSpectrum> spectra = ir.GetSpectra();
            var    peptideFormat   = new SequestPeptideTextFormat(format.PeptideFormat.GetHeader());
            string peptideFileName = fileName + ".unique.peptides";

            Progress.SetMessage("Saving peptides to " + peptideFileName + " ...");
            peptideFormat.WriteToFile(peptideFileName, spectra);

            Progress.SetMessage("Finished.");
            return(new[] { resultFileName, peptideFileName });
        }
        public override IEnumerable <string> Process(string fileName)
        {
            SequestResultTextFormat format = new SequestResultTextFormat();

            IIdentifiedResult sr = format.ReadFromFile(fileName);

            Dictionary <string, HashSet <IIdentifiedSpectrum> > peptideMap = sr.GetExperimentalPeptideMap();

            Dictionary <IIdentifiedSpectrum, int> confused = new Dictionary <IIdentifiedSpectrum, int>();
            List <IIdentifiedSpectrum>            wrongMs2 = new List <IIdentifiedSpectrum>();
            List <IIdentifiedSpectrum>            wrongMs3 = new List <IIdentifiedSpectrum>();

            int pepcount = 0;

            List <string> exps = new List <string>(peptideMap.Keys);

            exps.Sort();
            foreach (string exp in exps)
            {
                Console.Out.WriteLine(exp);

                HashSet <IIdentifiedSpectrum> peps = peptideMap[exp];
                pepcount += peps.Count;
                using (IRawFile rawFile = new RawFileImpl(expRawMap[exp]))
                {
                    foreach (IIdentifiedSpectrum pep in peps)
                    {
                        int msLevel = rawFile.GetMsLevel(pep.Query.FileScan.FirstScan);

                        bool bMs2 = ms2seqPattern.Match(pep.Sequence).Success;
                        bool bMs3 = ms3seqPattern.Match(pep.Sequence).Success;

                        if (bMs2 && bMs3)
                        {
                            confused[pep] = msLevel;
                            continue;
                        }

                        if (bMs3)
                        {
                            if (msLevel != 3)
                            {
                                wrongMs3.Add(pep);
                                continue;
                            }
                        }
                        else if (bMs2)
                        {
                            if (msLevel != 2)
                            {
                                wrongMs2.Add(pep);
                                continue;
                            }
                        }
                    }
                }
            }

            string incorrectFilename = FileUtils.ChangeExtension(fileName, ".incorrect.peptides.txt");

            using (StreamWriter sw = new StreamWriter(incorrectFilename))
            {
                sw.WriteLine("Type\tFilename\tSequence\tScore\tDeltaScore\tmsLevel");
                foreach (IIdentifiedSpectrum pep in confused.Keys)
                {
                    sw.WriteLine(MyConvert.Format("Confused\t{0}\t{1}\t{2:0.00}\t{3:0.00}\t{4}",
                                                  pep.Query.FileScan.LongFileName,
                                                  pep.Sequence,
                                                  pep.Score,
                                                  pep.DeltaScore,
                                                  confused[pep]));
                }

                foreach (IIdentifiedSpectrum pep in wrongMs2)
                {
                    sw.WriteLine(MyConvert.Format("WrongMS2\t{0}\t{1}\t{2:0.00}\t{3:0.00}\t3",
                                                  pep.Query.FileScan.LongFileName,
                                                  pep.Sequence,
                                                  pep.Score,
                                                  pep.DeltaScore));
                }

                foreach (IIdentifiedSpectrum pep in wrongMs3)
                {
                    sw.WriteLine(MyConvert.Format("WrongMS3\t{0}\t{1}\t{2:0.00}\t{3:0.00}\t2",
                                                  pep.Query.FileScan.LongFileName,
                                                  pep.Sequence,
                                                  pep.Score,
                                                  pep.DeltaScore));
                }

                sw.WriteLine();
                sw.WriteLine("Total\t" + pepcount);
                sw.WriteLine("Confused\t" + confused.Count);
                sw.WriteLine("WrongMs2\t" + wrongMs2.Count);
                sw.WriteLine("WrongMs3\t" + wrongMs3.Count);
            }

            List <string> incorrectDtafilenames = new List <string>();

            foreach (IIdentifiedSpectrum pep in confused.Keys)
            {
                incorrectDtafilenames.Add(pep.Query.FileScan.LongFileName);
            }
            foreach (IIdentifiedSpectrum pep in wrongMs2)
            {
                incorrectDtafilenames.Add(pep.Query.FileScan.LongFileName);
            }
            foreach (IIdentifiedSpectrum pep in wrongMs3)
            {
                incorrectDtafilenames.Add(pep.Query.FileScan.LongFileName);
            }

            for (int i = sr.Count - 1; i >= 0; i--)
            {
                foreach (IIdentifiedProtein sp in sr[i])
                {
                    for (int j = sp.Peptides.Count - 1; j >= 0; j--)
                    {
                        if (incorrectDtafilenames.Contains(sp.Peptides[j].Spectrum.Query.FileScan.Experimental))
                        {
                            sp.Peptides.RemoveAt(j);
                        }
                    }
                }

                if (sr[i][0].Peptides.Count == 0)
                {
                    sr.RemoveAt(i);
                }
            }

            string correctFilename = FileUtils.ChangeExtension(fileName, ".correct.txt");

            //BuildSummaryResultUtils.Write(correctFilename, cr);
            return(new[] { correctFilename });
        }