public static void TestCompIons_MatchIonsScore() { TestDataFile t = new TestDataFile(); Tolerance productMassTolerance = new AbsoluteTolerance(0.01); double precursorMass = 300; //The below theoretical does not accurately represent B-Y ions double[] sorted_theoretical_product_masses_for_this_peptide = new double[] { precursorMass + (2 * Constants.ProtonMass) - 275.1350, precursorMass + (2 * Constants.ProtonMass) - 258.127, precursorMass + (2 * Constants.ProtonMass) - 257.1244, 50, 60, 70, 147.0764, precursorMass + (2 * Constants.ProtonMass) - 147.0764, precursorMass + (2 * Constants.ProtonMass) - 70, precursorMass + (2 * Constants.ProtonMass) - 60, precursorMass + (2 * Constants.ProtonMass) - 50, 257.1244, 258.127, 275.1350 }; //{ 50, 60, 70, 147.0764, 257.1244, 258.127, 275.1350 } List <Product> productsWithLocalizedMassDiff = new List <Product>(); foreach (double d in sorted_theoretical_product_masses_for_this_peptide) { productsWithLocalizedMassDiff.Add(new Product(ProductType.b, FragmentationTerminus.Both, d, 1, 1, 0)); } CommonParameters commonParametersNoComp = new CommonParameters { ProductMassTolerance = new AbsoluteTolerance(0.01) }; CommonParameters commonParametersWithComp = new CommonParameters(productMassTolerance: new AbsoluteTolerance(0.01), addCompIons: true); MsDataScan scan = t.GetOneBasedScan(2); var scanWithMass = new Ms2ScanWithSpecificMass(scan, precursorMass.ToMz(1), 1, "", new CommonParameters()); List <MatchedFragmentIon> matchedIons = MetaMorpheusEngine.MatchFragmentIons(scanWithMass, productsWithLocalizedMassDiff, commonParametersNoComp); List <MatchedFragmentIon> matchedCompIons = MetaMorpheusEngine.MatchFragmentIons(scanWithMass, productsWithLocalizedMassDiff, commonParametersWithComp); matchedCompIons.AddRange(matchedIons); // score when the mass-diff is on this residue double localizedScore = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedIons); double scoreNormal = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedIons); double scoreComp = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedCompIons); Assert.IsTrue(scoreNormal * 2 == scoreComp && scoreComp > scoreNormal + 1); }
//[Test] public static void TestGetCombinedMs2Scans() { var myMsDataFile = new TestDataFile(5); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); //Write prime code to combine MS2MS3 Dictionary <int, double> listOfScanPrecusor = new Dictionary <int, double>(); List <MsDataScan> ListOfSortedMsScans = new List <MsDataScan>(); List <Ms2ScanWithSpecificMass> test = new List <Ms2ScanWithSpecificMass>(); foreach (var ms2scan in myMsDataFile.GetAllScansList().Where(x => x.MsnOrder != 1)) { if (ms2scan.MsnOrder == 2 && !listOfScanPrecusor.Contains(new KeyValuePair <int, double>(ms2scan.OneBasedPrecursorScanNumber.Value, ms2scan.SelectedIonMZ.Value))) { if (ms2scan.OneBasedPrecursorScanNumber.HasValue) { listOfScanPrecusor.Add(ms2scan.OneBasedPrecursorScanNumber.Value, ms2scan.SelectedIonMZ.Value); List <int> currentScanMS2OneBasedScanNumber = new List <int> { ms2scan.OneBasedScanNumber }; var mz2 = ms2scan.MassSpectrum.XArray.ToList(); var intensities2 = ms2scan.MassSpectrum.YArray.ToList(); for (int i = 1; i < 7; i++) { if (ms2scan.OneBasedScanNumber + i <= myMsDataFile.NumSpectra) { var x = myMsDataFile.GetOneBasedScan(ms2scan.OneBasedScanNumber + i); //var x = myMsDataFile.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().ElementAt(i); if (x.MsnOrder == 2 && x.SelectedIonMZ == ms2scan.SelectedIonMZ) { currentScanMS2OneBasedScanNumber.Add(x.OneBasedScanNumber); mz2.AddRange(x.MassSpectrum.XArray.ToList()); intensities2.AddRange(x.MassSpectrum.YArray.ToList()); } if (x.MsnOrder == 3 && currentScanMS2OneBasedScanNumber.Contains(x.OneBasedPrecursorScanNumber.Value)) { mz2.AddRange(x.MassSpectrum.XArray.ToList()); intensities2.AddRange(x.MassSpectrum.YArray.ToList()); } } } var MassSpectrum2 = new MzSpectrum(mz2.ToArray(), intensities2.ToArray(), false); ListOfSortedMsScans.Add(new MsDataScan(MassSpectrum2, ms2scan.OneBasedScanNumber, ms2scan.MsnOrder, ms2scan.IsCentroid, Polarity.Positive, ms2scan.RetentionTime, ms2scan.ScanWindowRange, ms2scan.ScanFilter, ms2scan.MzAnalyzer, ms2scan.TotalIonCurrent, ms2scan.InjectionTime, null, "", ms2scan.SelectedIonMZ, ms2scan.SelectedIonChargeStateGuess, ms2scan.SelectedIonIntensity, ms2scan.IsolationMz, null, ms2scan.DissociationType, ms2scan.OneBasedPrecursorScanNumber, ms2scan.SelectedIonMonoisotopicGuessMz)); } } } foreach (var ms2scan in ListOfSortedMsScans.Where(x => x.MsnOrder != 1)) { test.Add(new Ms2ScanWithSpecificMass(ms2scan, ms2scan.SelectedIonMonoisotopicGuessMz.Value, ms2scan.SelectedIonChargeStateGuess.Value, "", new CommonParameters())); } var testToArray = test.OrderBy(b => b.PrecursorMass).ToArray(); }
public static void TestPsmHeader() { DigestionParams digestionParams = new DigestionParams(); PeptideWithSetModifications pepWithSetMods = new Protein( "MQQQQQQQ", "accession1", "org", new List <Tuple <string, string> > { new Tuple <string, string>("geneNameType", "geneName") }, new Dictionary <int, List <Modification> > { { 2, new List <Modification> { new Modification("mod", "mod") } } }, name: "name", full_name: "fullName", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(2, "P", "Q", "changed this sequence") }) .Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First(); MsDataFile myMsDataFile = new TestDataFile(pepWithSetMods, "quadratic"); MsDataScan scann = myMsDataFile.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(scann, 4, 1, null); PeptideSpectralMatch psm = new PeptideSpectralMatch(pepWithSetMods.CompactPeptide(TerminusType.None), 1, 2, 3, scan, digestionParams); var t = psm.ToString(); var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader(); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { pepWithSetMods.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> { pepWithSetMods } } }; psm.MatchToProteinLinkedPeptides(matching); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Tolerance fragmentTolerance = new PpmTolerance(10); List <ProductType> lp = new List <ProductType> { ProductType.B }; new LocalizationEngine(new List <PeptideSpectralMatch> { psm }, lp, myMsDataFile, new CommonParameters(productMassTolerance: fragmentTolerance), new List <string>()).Run(); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); psm.SetFdrValues(6, 6, 6, 6, 6, 6, 0, 0, 0, true); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); }
public static void TestCompIons_MatchIons() { TestDataFile t = new TestDataFile(0.0001); Tolerance productMassTolerance = new AbsoluteTolerance(0.01); double precursorMass = 402.18629720155; //The below theoretical does not accurately represent B-Y ions double[] sorted_theoretical_product_masses_for_this_peptide = new double[] { 50, 60, 70, 147.0764 - Constants.ProtonMass, 200, 215, 230, 245, precursorMass + Constants.ProtonMass - 147.0764, 258.127, 275.1350, precursorMass + (2 * Constants.ProtonMass) - 70, precursorMass + (2 * Constants.ProtonMass) - 60, precursorMass + (2 * Constants.ProtonMass) - 50 }; //{ 50, 60, 70, 147.0764, 257.1244, 258.127, 275.1350 } List <double> matchedIonMassesT = new List <double>(); List <double> matchedDaErrorT = new List <double>(); List <double> matchedPpmErrorT = new List <double>(); List <double> matchedIonIntensityT = new List <double>(); List <double> matchedIonMassesF = new List <double>(); List <double> matchedDaErrorF = new List <double>(); List <double> matchedPpmErrorF = new List <double>(); List <double> matchedIonIntensityF = new List <double>(); List <int> matchedIonSeriesT = new List <int>(); List <int> matchedIonSeriesF = new List <int>(); MetaMorpheusEngine.MatchIonsOld(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, matchedIonSeriesT, matchedIonMassesT, matchedDaErrorT, matchedPpmErrorT, matchedIonIntensityT, precursorMass, ProductType.BnoB1ions, true); MetaMorpheusEngine.MatchIonsOld(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, matchedIonSeriesF, matchedIonMassesF, matchedDaErrorF, matchedPpmErrorF, matchedIonIntensityF, precursorMass, ProductType.BnoB1ions, false); //Test the number of series is doubled Assert.IsTrue(matchedIonSeriesT.Count == matchedIonSeriesF.Count * 2); //Test the number of ions is doubled Assert.IsTrue(matchedIonMassesT.Count == matchedIonMassesF.Count * 2); //Test the number of da errors is doubled Assert.IsTrue(matchedDaErrorT.Count == matchedDaErrorF.Count * 2); //test the number of ppm errors is doubled Assert.IsTrue(matchedPpmErrorT.Count == matchedPpmErrorF.Count * 2); //test the number of the intensity values is doubled Assert.IsTrue(matchedIonIntensityT.Count == matchedIonIntensityF.Count * 2); foreach (double d in matchedDaErrorF) { Assert.IsTrue(d <= 0.01); } foreach (double d in matchedDaErrorT) { Assert.IsTrue(d <= 0.01); } }
public static void TestCompIons_MatchIonsScore() { TestDataFile t = new TestDataFile(); Tolerance productMassTolerance = new AbsoluteTolerance(0.01); double precursorMass = 300; //The below theoretical does not accurately represent B-Y ions double[] sorted_theoretical_product_masses_for_this_peptide = new double[] { precursorMass + (2 * Constants.protonMass) - 275.1350, precursorMass + (2 * Constants.protonMass) - 258.127, precursorMass + (2 * Constants.protonMass) - 257.1244, 50, 60, 70, 147.0764, precursorMass + (2 * Constants.protonMass) - 147.0764, precursorMass + (2 * Constants.protonMass) - 70, precursorMass + (2 * Constants.protonMass) - 60, precursorMass + (2 * Constants.protonMass) - 50, 257.1244, 258.127, 275.1350 }; //{ 50, 60, 70, 147.0764, 257.1244, 258.127, 275.1350 } List <ProductType> lp = new List <ProductType> { ProductType.B, ProductType.Y }; double scoreT = MetaMorpheusEngine.CalculatePeptideScore(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, precursorMass, new List <DissociationType> { DissociationType.HCD }, true, 0); double scoreF = MetaMorpheusEngine.CalculatePeptideScore(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, precursorMass, new List <DissociationType> { DissociationType.HCD }, false, 0); Assert.IsTrue(scoreT == scoreF * 2 && scoreT > scoreF + 1); }
public static void TestPsmHeader() { CommonParameters commonParameters = new CommonParameters(); PeptideWithSetModifications pepWithSetMods = new Protein( "MQQQQQQQ", "accession1", "org", new List <Tuple <string, string> > { new Tuple <string, string>("geneNameType", "geneName") }, new Dictionary <int, List <Modification> > { { 2, new List <Modification> { new Modification("mod", "mod") } } }, name: "name", fullName: "fullName", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(2, "P", "Q", "changed this sequence") }) .Digest(commonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).First(); MsDataFile myMsDataFile = new TestDataFile(pepWithSetMods, "quadratic"); MsDataScan scann = myMsDataFile.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(scann, 4, 1, null, new CommonParameters()); var theoreticalIons = new List <Product>(); pepWithSetMods.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalIons); var matchedIons = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalIons, new CommonParameters()); PeptideSpectralMatch psm = new PeptideSpectralMatch(pepWithSetMods, 1, 2, 3, scan, commonParameters, matchedIons); psm.ResolveAllAmbiguities(); var t = psm.ToString(); var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader(); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Tolerance fragmentTolerance = new PpmTolerance(10); new LocalizationEngine(new List <PeptideSpectralMatch> { psm }, myMsDataFile, new CommonParameters(productMassTolerance: fragmentTolerance), null, new List <string>()).Run(); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); psm.SetFdrValues(6, 6, 6, 6, 6, 0, 0, 0); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); }
public static void TestPsmHeader() { DigestionParams digestionParams = new DigestionParams(); PeptideWithSetModifications pepWithSetMods = new Protein("MQQQQQQQ", "accession1").Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First(); IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(pepWithSetMods, "quadratic"); IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > scann = myMsDataFile.GetOneBasedScan(2) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(scann, 4, 1, null); PeptideSpectralMatch psm = new PeptideSpectralMatch(pepWithSetMods.CompactPeptide(TerminusType.None), 1, 2, 3, scan); var t = psm.ToString(); var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader(); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { pepWithSetMods.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> { pepWithSetMods } } }; psm.MatchToProteinLinkedPeptides(matching); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); Tolerance fragmentTolerance = new PpmTolerance(10); List <ProductType> lp = new List <ProductType> { ProductType.B }; new LocalizationEngine(new List <PeptideSpectralMatch> { psm }, lp, myMsDataFile, fragmentTolerance, new List <string>(), false).Run(); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); psm.SetFdrValues(6, 6, 6, 6, 6, 6, 0, 0, 0, false); Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t')); }
private static Tuple <List <PeptideSpectralMatch>, Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >, MassDiffAcceptor, bool, CompactPeptideBase, CompactPeptideBase> GetInfo(bool localizeable) { CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: 2, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain, maxModsForPeptides: 1), scoreCutoff: 1); // Alanine = Glycine + CH2 Protein protein1 = new Protein("MA", "protein1"); Protein protein2 = new Protein("MG", "protein2"); Protein protein3; double monoisotopicMass = Chemistry.ChemicalFormula.ParseFormula("CH2").MonoisotopicMass; ModificationMotif.TryGetMotif("G", out ModificationMotif motif1); ModificationMotif.TryGetMotif("A", out ModificationMotif motif2); TerminusLocalization modificationSites = TerminusLocalization.Any; List <ModificationWithMass> allKnownFixedModifications = new List <ModificationWithMass> { new ModificationWithMass("CH2 on Glycine", null, motif1, modificationSites, monoisotopicMass) }; List <ModificationWithMass> variableModifications; ModificationWithMass alanineMod = new ModificationWithMass("CH2 on Alanine", null, motif2, modificationSites, monoisotopicMass); if (localizeable) { variableModifications = new List <ModificationWithMass>(); IDictionary <int, List <Modification> > oneBasedModifications = new Dictionary <int, List <Modification> > { { 2, new List <Modification> { alanineMod } } }; protein3 = new Protein("MA", "protein3", oneBasedModifications: oneBasedModifications); } else { variableModifications = new List <ModificationWithMass>(); variableModifications = new List <ModificationWithMass> { alanineMod }; protein3 = new Protein("MA", "protein3"); } var pepWithSetModifications1 = protein1.Digest(CommonParameters.DigestionParams, allKnownFixedModifications, variableModifications).First(); var pepWithSetModifications2 = protein2.Digest(CommonParameters.DigestionParams, allKnownFixedModifications, variableModifications).First(); var pepWithSetModifications3 = protein3.Digest(CommonParameters.DigestionParams, allKnownFixedModifications, variableModifications).Last(); CompactPeptide compactPeptide1 = new CompactPeptide(pepWithSetModifications1, TerminusType.None); CompactPeptide compactPeptideDuplicate = new CompactPeptide(pepWithSetModifications2, TerminusType.None); Assert.AreEqual(compactPeptide1, compactPeptideDuplicate); CompactPeptide compactPeptide2 = new CompactPeptide(pepWithSetModifications3, TerminusType.None); string fullFilePath = null; int precursorCharge = 0; TestDataFile testDataFile = new TestDataFile(); MsDataScan mzLibScan = testDataFile.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(mzLibScan, 0, precursorCharge, fullFilePath); int scanIndex = 0; double score = 0; int notch = 0; PeptideSpectralMatch psm1 = new PeptideSpectralMatch(compactPeptide1, notch, score, scanIndex, scan, CommonParameters.DigestionParams); psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false); PeptideSpectralMatch psm2 = new PeptideSpectralMatch(compactPeptide1, notch, score, scanIndex, scan, CommonParameters.DigestionParams); psm2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false); PeptideSpectralMatch psm3 = new PeptideSpectralMatch(compactPeptide2, notch, score, scanIndex, scan, CommonParameters.DigestionParams); psm3.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false); var newPsms = new List <PeptideSpectralMatch> { psm1, psm2, psm3 }; MassDiffAcceptor massDiffAcceptors = new SinglePpmAroundZeroSearchMode(5); SequencesToActualProteinPeptidesEngine stappe = new SequencesToActualProteinPeptidesEngine(newPsms, new List <Protein> { protein1, protein2, protein3 }, allKnownFixedModifications, variableModifications, new List <ProductType> { ProductType.B, ProductType.Y }, new List <DigestionParams> { CommonParameters.DigestionParams }, CommonParameters.ReportAllAmbiguity, CommonParameters, new List <string>()); var haha = (SequencesToActualProteinPeptidesEngineResults)stappe.Run(); var compactPeptideToProteinPeptideMatching = haha.CompactPeptideToProteinPeptideMatching; Assert.AreEqual(2, compactPeptideToProteinPeptideMatching.Count); psm1.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching); bool noOneHitWonders = false; return(new Tuple <List <PeptideSpectralMatch>, Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >, MassDiffAcceptor, bool, CompactPeptideBase, CompactPeptideBase> ( newPsms, compactPeptideToProteinPeptideMatching, massDiffAcceptors, noOneHitWonders, compactPeptide1, compactPeptide2 )); }
public static void FdrTestMethod() { MassDiffAcceptor searchModes = new DotMassDiffAcceptor(null, new List <double> { 0, 1.0029 }, new PpmTolerance(5)); List <string> nestedIds = new List <string>(); Protein p = new Protein("MNKNNKNNNKNNNNK", null); DigestionParams digestionParams = new DigestionParams(); var digested = p.Digest(digestionParams, new List <Modification>(), new List <Modification>()).ToList(); PeptideWithSetModifications pep1 = digested[0]; PeptideWithSetModifications pep2 = digested[1]; PeptideWithSetModifications pep3 = digested[2]; PeptideWithSetModifications pep4 = digested[3]; TestDataFile t = new TestDataFile(new List <PeptideWithSetModifications> { pep1, pep2, pep3 }); MsDataScan mzLibScan1 = t.GetOneBasedScan(2); Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, pep1.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); PeptideSpectralMatch psm1 = new PeptideSpectralMatch(pep1, 0, 3, 0, scan1, digestionParams, new List <MatchedFragmentIon>()); MsDataScan mzLibScan2 = t.GetOneBasedScan(4); Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, pep2.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); PeptideSpectralMatch psm2 = new PeptideSpectralMatch(pep2, 1, 2, 1, scan2, digestionParams, new List <MatchedFragmentIon>()); MsDataScan mzLibScan3 = t.GetOneBasedScan(6); Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, pep3.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); PeptideSpectralMatch psm3 = new PeptideSpectralMatch(pep3, 0, 1, 2, scan3, digestionParams, new List <MatchedFragmentIon>()); psm3.AddOrReplace(pep4, 1, 1, true, new List <MatchedFragmentIon>(), 0); var newPsms = new List <PeptideSpectralMatch> { psm1, psm2, psm3 }; foreach (PeptideSpectralMatch psm in newPsms) { psm.ResolveAllAmbiguities(); } FdrAnalysisEngine fdr = new FdrAnalysisEngine(newPsms, searchModes.NumNotches, new CommonParameters(), nestedIds); fdr.Run(); Assert.AreEqual(2, searchModes.NumNotches); Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoyNotch); Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTargetNotch); Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoyNotch); Assert.AreEqual(1, newPsms[1].FdrInfo.CumulativeTargetNotch); Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoyNotch); Assert.AreEqual(1, newPsms[2].FdrInfo.CumulativeTargetNotch); Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoy); Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTarget); Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoy); Assert.AreEqual(2, newPsms[1].FdrInfo.CumulativeTarget); Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoy); Assert.AreEqual(3, newPsms[2].FdrInfo.CumulativeTarget); }
public static void FdrTestMethod() { MassDiffAcceptor searchModes = new DotMassDiffAcceptor(null, new List <double> { 0, 1.0029 }, new PpmTolerance(5)); List <string> nestedIds = new List <string>(); Protein p = new Protein("MNKNNKNNNKNNNNK", null); DigestionParams digestionParams = new DigestionParams(); var digested = p.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).ToList(); PeptideWithSetModifications pep1 = digested[0]; PeptideWithSetModifications pep2 = digested[1]; PeptideWithSetModifications pep3 = digested[2]; PeptideWithSetModifications pep4 = digested[3]; TestDataFile t = new TestDataFile(new List <PeptideWithSetModifications> { pep1, pep2, pep3 }); CompactPeptide peptide1 = new CompactPeptide(pep1, TerminusType.None); IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > mzLibScan1 = t.GetOneBasedScan(2) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, peptide1.MonoisotopicMassIncludingFixedMods.ToMz(1), 1, null); PeptideSpectralMatch psm1 = new PeptideSpectralMatch(peptide1, 0, 3, 0, scan1); CompactPeptide peptide2 = new CompactPeptide(pep2, TerminusType.None); IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > mzLibScan2 = t.GetOneBasedScan(4) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, peptide2.MonoisotopicMassIncludingFixedMods.ToMz(1), 1, null); PeptideSpectralMatch psm2 = new PeptideSpectralMatch(peptide2, 1, 2, 1, scan2); CompactPeptide peptide3 = new CompactPeptide(pep3, TerminusType.None); IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > mzLibScan3 = t.GetOneBasedScan(6) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, peptide3.MonoisotopicMassIncludingFixedMods.ToMz(1), 1, null); PeptideSpectralMatch psm3 = new PeptideSpectralMatch(peptide3, 0, 1, 2, scan3); CompactPeptide peptide4 = new CompactPeptide(pep4, TerminusType.None); psm3.AddOrReplace(peptide4, 1, 1, true); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { peptide1, new HashSet <PeptideWithSetModifications> { pep1 } }, { peptide2, new HashSet <PeptideWithSetModifications> { pep2 } }, { peptide3, new HashSet <PeptideWithSetModifications> { pep3 } }, { peptide4, new HashSet <PeptideWithSetModifications> { pep4 } }, }; psm1.MatchToProteinLinkedPeptides(matching); psm2.MatchToProteinLinkedPeptides(matching); psm3.MatchToProteinLinkedPeptides(matching); var newPsms = new List <PeptideSpectralMatch> { psm1, psm2, psm3 }; FdrAnalysisEngine fdr = new FdrAnalysisEngine(newPsms, searchModes.NumNotches, true, nestedIds); fdr.Run(); Assert.AreEqual(2, searchModes.NumNotches); Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoyNotch); Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTargetNotch); Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoyNotch); Assert.AreEqual(1, newPsms[1].FdrInfo.CumulativeTargetNotch); Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoyNotch); Assert.AreEqual(1, newPsms[2].FdrInfo.CumulativeTargetNotch); Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoy); Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTarget); Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoy); Assert.AreEqual(2, newPsms[1].FdrInfo.CumulativeTarget); Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoy); Assert.AreEqual(3, newPsms[2].FdrInfo.CumulativeTarget); }
//[Test] public static void TestGetCombinedMs2Scans() { var myMsDataFile = new TestDataFile(5); bool DoPrecursorDeconvolution = true; bool UseProvidedPrecursorInfo = true; double DeconvolutionIntensityRatio = 4; int DeconvolutionMaxAssumedChargeState = 10; Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, DoPrecursorDeconvolution, UseProvidedPrecursorInfo, DeconvolutionIntensityRatio, DeconvolutionMaxAssumedChargeState, DeconvolutionMassTolerance).OrderBy(b => b.PrecursorMass).ToArray(); //Write prime code to combine MS2MS3 Dictionary <int, double> listOfScanPrecusor = new Dictionary <int, double>(); List <IMzmlScan> ListOfSortedMsScans = new List <IMzmlScan>(); List <Ms2ScanWithSpecificMass> test = new List <Ms2ScanWithSpecificMass>(); foreach (var ms2scan in myMsDataFile.OfType <IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > >()) { if (ms2scan.MsnOrder == 2 && !listOfScanPrecusor.Contains(new KeyValuePair <int, double>(ms2scan.OneBasedPrecursorScanNumber.Value, ms2scan.SelectedIonMZ))) { if (ms2scan.OneBasedPrecursorScanNumber.HasValue) { listOfScanPrecusor.Add(ms2scan.OneBasedPrecursorScanNumber.Value, ms2scan.SelectedIonMZ); List <int> currentScanMS2OneBasedScanNumber = new List <int>(); currentScanMS2OneBasedScanNumber.Add(ms2scan.OneBasedScanNumber); var mz2 = ms2scan.MassSpectrum.XArray.ToList(); var intensities2 = ms2scan.MassSpectrum.YArray.ToList(); for (int i = 1; i < 7; i++) { if (ms2scan.OneBasedScanNumber + i <= myMsDataFile.NumSpectra) { var x = myMsDataFile.GetOneBasedScan(ms2scan.OneBasedScanNumber + i) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; //var x = myMsDataFile.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().ElementAt(i); if (x.MsnOrder == 2 && x.SelectedIonMZ == ms2scan.SelectedIonMZ) { currentScanMS2OneBasedScanNumber.Add(x.OneBasedScanNumber); mz2.AddRange(x.MassSpectrum.XArray.ToList()); intensities2.AddRange(x.MassSpectrum.YArray.ToList()); } if (x.MsnOrder == 3 && currentScanMS2OneBasedScanNumber.Contains(x.OneBasedPrecursorScanNumber.Value)) { mz2.AddRange(x.MassSpectrum.XArray.ToList()); intensities2.AddRange(x.MassSpectrum.YArray.ToList()); } } } var MassSpectrum2 = new MzmlMzSpectrum(mz2.ToArray(), intensities2.ToArray(), false); ListOfSortedMsScans.Add(new MzmlScanWithPrecursor(ms2scan.OneBasedScanNumber, MassSpectrum2, ms2scan.MsnOrder, ms2scan.IsCentroid, Polarity.Positive, ms2scan.RetentionTime, ms2scan.ScanWindowRange, ms2scan.ScanFilter, ms2scan.MzAnalyzer, ms2scan.TotalIonCurrent, ms2scan.SelectedIonMZ, ms2scan.SelectedIonChargeStateGuess, ms2scan.SelectedIonIntensity, ms2scan.IsolationMz, null, ms2scan.DissociationType, ms2scan.OneBasedPrecursorScanNumber, ms2scan.SelectedIonMonoisotopicGuessMz, ms2scan.InjectionTime, "")); } } } foreach (var ms2scan in ListOfSortedMsScans.OfType <IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > >()) { test.Add(new Ms2ScanWithSpecificMass(ms2scan, ms2scan.SelectedIonMonoisotopicGuessMz.Value, ms2scan.SelectedIonChargeStateGuess.Value, "")); } var testToArray = test.OrderBy(b => b.PrecursorMass).ToArray(); //Using function to combine MS2MS3 //var listOfSortedms2Scans2 = MetaMorpheusTask.GetCombinedMs2Scans(myMsDataFile, null, DoPrecursorDeconvolution, UseProvidedPrecursorInfo, DeconvolutionIntensityRatio, DeconvolutionMaxAssumedChargeState, DeconvolutionMassTolerance).OrderBy(b => b.PrecursorMass).ToArray(); //Assert.AreEqual(5, myMsDataFile.NumSpectra); //Assert.AreEqual(1, listOfSortedms2Scans2.Count()); }