예제 #1
0
        public MsGfResults(string resultFilePath)
        {
            _msGfMatches = new List <MsGfMatch>();
            MsGfPlusHeaderInformation headerInfo = null;
            var prevScanNum = -1;

            foreach (var line in File.ReadLines(resultFilePath))
            {
                if (headerInfo == null && line.StartsWith("#"))
                {
                    headerInfo = new MsGfPlusHeaderInformation(line);
                    continue;
                }

                var match = new MsGfMatch(line, headerInfo);

                if (match.ScanNum == prevScanNum)
                {
                    continue;
                }
                prevScanNum = match.ScanNum;

                if (!match.IsValid || match.Protein.StartsWith(FastaDatabase.DecoyProteinPrefix))
                {
                    continue;
                }

                _msGfMatches.Add(match);
            }
            _msGfMatches.Sort();
        }
예제 #2
0
        public int PostProcessing(string outputFilePath)
        {
            // Parse MS-GF+ results
            var pepToResults = new Dictionary <string, MsGfMatch>();

            MsGfPlusHeaderInformation headerInfo = null;

            foreach (var line in File.ReadLines(MsGfResultPath))
            {
                if (line.StartsWith("#"))
                {
                    headerInfo = new MsGfPlusHeaderInformation(line);
                    continue;
                }

                var match = new MsGfMatch(line, headerInfo);
                if (!match.IsValid)
                {
                    continue;
                }

                if (match.SpecEValue > SpecEValueThreshold)
                {
                    continue;
                }

                if (!IsValid(match))
                {
                    continue;
                }

                MsGfMatch prevMatch;
                if (!pepToResults.TryGetValue(match.Peptide, out prevMatch))
                {
                    pepToResults[match.Peptide] = match;
                    match.NumMatches            = 1;
                }
                else
                {
                    if (match.SpecEValue < prevMatch.SpecEValue)
                    {
                        pepToResults[match.Peptide] = match;
                        match.NumMatches           += prevMatch.NumMatches;
                    }
                    else
                    {
                        ++prevMatch.NumMatches;
                    }
                }
            }

            //var filteredPsms = pepToResults.Select(entry => entry.Value).Where(IsValid).ToList();
            var filteredPsms = pepToResults.Select(entry => entry.Value).ToList();

            filteredPsms.Sort();

            // compute FDR
            var qValue = GetQValues(filteredPsms);

            var index = -1;
            var numId = 0;

            using (var writer = new StreamWriter(outputFilePath))
            {
                writer.WriteLine("#SpecFile\tPeptide\tScanNum\tPrecursorMz\tCharge\tProtein\tNumMatches\tDeNovoScore\tMSGFScore\tSpecEValue\tPepQValue");
                foreach (var match in filteredPsms)
                {
                    //if (match.Protein.StartsWith("DecoyPrefix")) continue;
                    writer.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}",
                                     match.SpecFile
                                     //, match.Peptide.Replace("C+57.021", "C")
                                     , match.Peptide
                                     , match.ScanNum
                                     , new Ion(match.Formula, match.Charge).GetMonoIsotopicMz()
                                     , match.Charge
                                     , match.Protein
                                     , match.NumMatches
                                     , match.DeNovoScore
                                     , match.MsgfScore
                                     , match.SpecEValue
                                     , qValue[++index]
                                     );
                    if (!match.Protein.StartsWith(DecoyPrefix))
                    {
                        if (qValue[index] <= 0.01)
                        {
                            ++numId;
                        }
                    }
                }
            }

            return(numId);
        }
예제 #3
0
        private bool IsValid(MsGfMatch match)
        {
            var specFileKey = Path.GetFileNameWithoutExtension(match.SpecFile);

            if (specFileKey == null)
            {
                return(false);
            }

            var precursorIon   = new Ion(match.Formula, match.Charge);
            var prevMs1ScanNum = Run[specFileKey].GetPrecursorScanNum(match.ScanNum);
            var nextMs1ScanNum = Run[specFileKey].GetNextScanNum(prevMs1ScanNum, 1);

            //var isotopeMzs =
            //    precursorIon.GetIsotopes(NumIsotopesToCheckForValidation)
            //        .Select(isotope => precursorIon.GetIsotopeMz(isotope.Index)).ToArray();
            var isotopes = precursorIon.GetIsotopes(NumIsotopesToCheckForValidation).ToArray();

            Array.Sort(isotopes);   // sort by indices

            var prevMs1Spec = Run[specFileKey].GetSpectrum(prevMs1ScanNum);

            if (prevMs1Spec != null)
            {
                //if (prevMs1Spec.ContainsIon(precursorIon, ToleranceForBaseXic, 0.9)) return true;
                var isPrevIsotopeValid = false;
                foreach (var isotope in isotopes)
                {
                    var mz = precursorIon.GetIsotopeMz(isotope.Index);
                    if (prevMs1Spec.FindPeak(mz, ToleranceForBaseXic) != null)  // match
                    {
                        if (isPrevIsotopeValid)
                        {
                            return(true);
                        }
                        isPrevIsotopeValid = true;
                    }
                }
            }

            var nextMs1Spec = Run[specFileKey].GetSpectrum(nextMs1ScanNum);

            if (nextMs1Spec != null)
            {
                var isPrevIsotopeValid = false;
                foreach (var isotope in isotopes)
                {
                    var mz = precursorIon.GetIsotopeMz(isotope.Index);
                    if (nextMs1Spec.FindPeak(mz, ToleranceForBaseXic) != null)  // match
                    {
                        if (isPrevIsotopeValid)
                        {
                            return(true);
                        }
                        isPrevIsotopeValid = true;
                    }
                }
            }

            return(false);
        }