protected List <int> GetBinsToSearch(Ms2ScanWithSpecificMass scan) { int obsPreviousFragmentCeilingMz = 0; List <int> binsToSearch = new List <int>(); foreach (var peakMz in scan.TheScan.MassSpectrum.XArray) { // assume charge state 1 to calculate mass tolerance double experimentalFragmentMass = Chemistry.ClassExtensions.ToMass(peakMz, 1); // get theoretical fragment bins within mass tolerance int obsFragmentFloorMass = (int)Math.Floor((commonParameters.ProductMassTolerance.GetMinimumValue(experimentalFragmentMass)) * FragmentBinsPerDalton); if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz) { obsFragmentFloorMass = obsPreviousFragmentCeilingMz; } int obsFragmentCeilingMass = (int)Math.Ceiling((commonParameters.ProductMassTolerance.GetMaximumValue(experimentalFragmentMass)) * FragmentBinsPerDalton); obsPreviousFragmentCeilingMz = obsFragmentCeilingMass + 1; for (int fragmentBin = obsFragmentFloorMass; fragmentBin <= obsFragmentCeilingMass; fragmentBin++) { if (FragmentIndex[fragmentBin] != null) { binsToSearch.Add(fragmentBin); } } } return(binsToSearch); }
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); }
//If XlSites is of same types private PsmCross XlSitesSame(Ms2ScanWithSpecificMass theScan, PsmCross psmCrossAlpha, PsmCross psmCrossBeta, CrosslinkerTypeClass crosslinker, int ind, int inx) { PsmCross psmCross = null; var xlPosAlpha = PsmCross.XlPosCal(psmCrossAlpha.compactPeptide, crosslinker.CrosslinkerModSites); var xlPosBeta = PsmCross.XlPosCal(psmCrossBeta.compactPeptide, crosslinker.CrosslinkerModSites); if (xlPosAlpha.Count() >= 1 && xlPosBeta.Count() >= 1) { PsmCross.XlLocalization(theScan, psmCrossAlpha, psmCrossBeta.compactPeptide.MonoisotopicMassIncludingFixedMods + crosslinker.TotalMass, crosslinker, ProductTypes, commonParameters.ProductMassTolerance, Charge_2_3, Charge_2_3_PrimeFragment, xlPosAlpha); PsmCross.XlLocalization(theScan, psmCrossBeta, psmCrossAlpha.compactPeptide.MonoisotopicMassIncludingFixedMods + crosslinker.TotalMass, crosslinker, ProductTypes, commonParameters.ProductMassTolerance, Charge_2_3, Charge_2_3_PrimeFragment, xlPosBeta); if (psmCrossAlpha.XLBestScore < psmCrossBeta.XLBestScore) { var swap = psmCrossAlpha; psmCrossAlpha = psmCrossBeta; psmCrossBeta = swap; } psmCrossAlpha.XlRank = new int[] { ind, inx }; psmCrossAlpha.XLTotalScore = psmCrossAlpha.XLBestScore + psmCrossBeta.XLBestScore; psmCrossAlpha.XLQvalueTotalScore = Math.Sqrt(psmCrossAlpha.XLBestScore) * psmCrossBeta.XLBestScore; psmCrossAlpha.BetaPsmCross = psmCrossBeta; if (crosslinker.Cleavable) { psmCrossAlpha.ParentIonMaxIntensityRanks.AddRange(psmCrossBeta.ParentIonMaxIntensityRanks); psmCrossAlpha.ParentIonExistNum += psmCrossBeta.ParentIonExistNum; } psmCrossAlpha.CrossType = PsmCrossType.Cross; psmCross = psmCrossAlpha; } return(psmCross); }
private void UpdateModel(int x) { Ms2ScanWithSpecificMass msScanForDraw = arrayOfMs2ScansSortedByMass.Where(p => p.OneBasedScanNumber == x).First(); //mainViewModel.UpdateScanModel(msScanForDraw); PsmCross psmCross = PSMs.Where(p => p.ScanNumber == x).First(); var lp = new List <ProductType> { ProductType.BnoB1ions, ProductType.Y }; Tolerance productMassTolerance = new PpmTolerance(20); var pmm = PsmCross.XlCalculateTotalProductMassesForSingle(psmCross, lp, false); var matchedIonMassesListPositiveIsMatch = new MatchedIonInfo(pmm.ProductMz.Length); double pmmScore = PsmCross.XlMatchIons(msScanForDraw.TheScan, productMassTolerance, pmm.ProductMz, pmm.ProductName, matchedIonMassesListPositiveIsMatch); matchedIonMassesListPositiveIsMatch.PredictedIonName = psmCross.ProductMassesMightHaveDuplicatesAndNaNs(lp).ProductName; matchedIonMassesListPositiveIsMatch.PredictedIonMZ = psmCross.ProductMassesMightHaveDuplicatesAndNaNs(lp).ProductMz; matchedIonMassesListPositiveIsMatch.PredictedIonIntensity = predictedIntensities[psmCross.ScanNumber]; psmCross.MatchedIonInfo = matchedIonMassesListPositiveIsMatch; mainViewModel.UpdateCrosslinkModelForSingle(msScanForDraw, psmCross); pdeepModelView.UpdataModelForPdeep(psmCross); }
public static void TestCombos() { List <PeptideSpectralMatch> allIdentifications = null; ModificationMotif.TryGetMotif("N", out ModificationMotif motifN); ModificationMotif.TryGetMotif("P", out ModificationMotif motifP); var gptmdModifications = new List <ModificationWithMass> { new ModificationWithMass("21", "mt", motifN, TerminusLocalization.Any, 21.981943, null), new ModificationWithMass("16", "mt", motifP, TerminusLocalization.Any, 15.994915, null) }; IEnumerable <Tuple <double, double> > combos = new List <Tuple <double, double> > { new Tuple <double, double>(21.981943, 15.994915) }; Tolerance precursorMassTolerance = new PpmTolerance(10); MsDataScan dfd = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfd, (651.297638557 + 21.981943 + 15.994915).ToMz(1), 1, "filepath"); var parentProtein = new Protein("NNNPPP", "accession"); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 5); List <ModificationWithMass> variableModifications = new List <ModificationWithMass>(); var modPep = parentProtein.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).First(); var peptidesWithSetModifications = new List <PeptideWithSetModifications> { modPep }; PeptideSpectralMatch match = new PeptideSpectralMatch(peptidesWithSetModifications.First().CompactPeptide(TerminusType.None), 0, 0, 0, scan, digestionParams); PeptideSpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First().CompactPeptide(TerminusType.None), 0, 0, 0, scan, digestionParams); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { peptidesWithSetModifications.First().CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> { peptidesWithSetModifications.First() } } }; List <ProductType> lp = new List <ProductType> { ProductType.B, ProductType.Y }; Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); match.MatchToProteinLinkedPeptides(matching); match.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0, 0, false); allIdentifications = new List <PeptideSpectralMatch> { match }; var engine = new GptmdEngine(allIdentifications, gptmdModifications, combos, new Dictionary <string, Tolerance> { { "filepath", precursorMassTolerance } }, new CommonParameters(), new List <string>()); var res = (GptmdResults)engine.Run(); Assert.AreEqual(1, res.Mods.Count); Assert.AreEqual(6, res.Mods["accession"].Count); Assert.AreEqual(3, res.Mods["accession"].Where(b => b.Item2.id.Equals("21")).Count()); Assert.AreEqual(3, res.Mods["accession"].Where(b => b.Item2.id.Equals("16")).Count()); }
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 TestLocalization() { var protease = new Protease("Custom Protease", new List <string> { "K" }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null); Protein parentProteinForMatch = new Protein("MEK", null); DigestionParams digestionParams = new DigestionParams { MinPeptideLength = 1, }; ModificationMotif.TryGetMotif("E", out ModificationMotif motif); List <ModificationWithMass> variableModifications = new List <ModificationWithMass> { new ModificationWithMass("21", null, motif, TerminusLocalization.Any, 21.981943) }; List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList(); Assert.AreEqual(4, allPeptidesWithSetModifications.Count()); PeptideWithSetModifications ps = allPeptidesWithSetModifications.First(); List <ProductType> lp = new List <ProductType> { ProductType.BnoB1ions, ProductType.Y }; PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1]; IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { pepWithSetModsForSpectrum }); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(myMsDataFile.Last() as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >, pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null); PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps.CompactPeptide(TerminusType.None), 0, 0, 2, scan); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { ps.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> { ps } } }; newPsm.MatchToProteinLinkedPeptides(matching); LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> { newPsm }, lp, myMsDataFile, fragmentTolerance, new List <string>(), false); f.Run(); // Was single peak!!! Assert.AreEqual(0, newPsm.MatchedIonDictOnlyMatches[ProductType.BnoB1ions].Count(b => b > 0)); Assert.AreEqual(1, newPsm.MatchedIonDictOnlyMatches[ProductType.Y].Count(b => b > 0)); // If localizing, three match!!! Assert.IsTrue(newPsm.LocalizedScores[1] > 3 && newPsm.LocalizedScores[1] < 4); }
public static void ReplaceBadStdevTwo() { //here we are adding a really hydrophobic psm at the same time as a regular peptide so that there is a big difference in their computed hydrophobicities. The stdev of these hydrophobicities is out of whach the the collective and so it needs to get replaced by the global average var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_HeLa_04_subset_longestSeq.mzML"); MyFileManager myFileManager = new MyFileManager(true); CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams()); var myMsDataFile = myFileManager.LoadFile(origDataFile, CommonParameters); var searchModes = new SinglePpmAroundZeroSearchMode(5); List <Protein> proteinList = ProteinDbLoader.LoadProteinFasta(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\hela_snip_for_unitTest.fasta"), true, DecoyType.Reverse, false, ProteinDbLoader.UniprotAccessionRegex, ProteinDbLoader.UniprotFullNameRegex, ProteinDbLoader.UniprotFullNameRegex, ProteinDbLoader.UniprotGeneNameRegex, ProteinDbLoader.UniprotOrganismRegex, out var dbErrors, -1); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, @"TestData\TaGe_SA_HeLa_04_subset_longestSeq.mzML", CommonParameters).OrderBy(b => b.PrecursorMass).ToArray(); //adding a new scan that creates a psm at an isolated retention time. This will ultimately cause PEP to replace its retention time standard deviation "Z-score" with the global average. Ms2ScanWithSpecificMass topMs2Scan = listOfSortedms2Scans[395]; int newOneBasedScanNumber = 1000; MzRange range = new MzRange(topMs2Scan.TheScan.MassSpectrum.XArray.Min(), topMs2Scan.TheScan.MassSpectrum.XArray.Max()); MzSpectrum mzs = new MzSpectrum(topMs2Scan.TheScan.MassSpectrum.XArray, topMs2Scan.TheScan.MassSpectrum.YArray, true); double newRetentionTime = topMs2Scan.TheScan.RetentionTime - 25; MsDataScan msd = new MsDataScan(mzs, newOneBasedScanNumber, 2, topMs2Scan.TheScan.IsCentroid, Polarity.Positive, newRetentionTime, range, "", MZAnalyzerType.Orbitrap, topMs2Scan.TheScan.TotalIonCurrent, topMs2Scan.TheScan.InjectionTime, topMs2Scan.TheScan.NoiseData, "", topMs2Scan.TheScan.SelectedIonMZ, topMs2Scan.TheScan.SelectedIonChargeStateGuess, topMs2Scan.TheScan.SelectedIonIntensity, topMs2Scan.TheScan.IsolationMz, topMs2Scan.TheScan.IsolationWidth, DissociationType.HCD, topMs2Scan.TheScan.OneBasedPrecursorScanNumber, topMs2Scan.TheScan.SelectedIonMonoisotopicGuessMz); Ms2ScanWithSpecificMass mwsm = new Ms2ScanWithSpecificMass(msd, topMs2Scan.PrecursorMonoisotopicPeakMz, topMs2Scan.PrecursorCharge, topMs2Scan.FullFilePath, new CommonParameters(), topMs2Scan.ExperimentalFragments); Ms2ScanWithSpecificMass[] extendedArray = new Ms2ScanWithSpecificMass[listOfSortedms2Scans.Length + 1]; for (int i = 0; i < listOfSortedms2Scans.Length; i++) { extendedArray[i] = listOfSortedms2Scans[i]; } extendedArray[listOfSortedms2Scans.Length] = mwsm; extendedArray = extendedArray.OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[extendedArray.Length]; new ClassicSearchEngine(allPsmsArray, extendedArray, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, new List <string>()).Run(); List <PeptideSpectralMatch> nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); nonNullPsms = nonNullPsms.OrderByDescending(p => p.Score).ToList(); List <PeptideSpectralMatch> psmBloated = new List <PeptideSpectralMatch>(); psmBloated.AddRange(nonNullPsms); int arrayMax = nonNullPsms.Count; psmBloated.AddRange(nonNullPsms.GetRange(2, arrayMax - 2)); psmBloated.AddRange(nonNullPsms.GetRange(2, arrayMax - 2)); PeptideSpectralMatch pp = psmBloated.Where(p => p.ScanRetentionTime < (newRetentionTime + 1)).First(); PeptideWithSetModifications newPwsmTwo = new PeptideWithSetModifications(new Protein("WAGVLPWFPWAAVVWGFWF", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary <int, Modification>(), 0); PeptideSpectralMatch newPsmTwo = new PeptideSpectralMatch(newPwsmTwo, pp.BestMatchingPeptides.First().Notch, pp.Score, pp.ScanIndex, mwsm, new DigestionParams(), pp.MatchedFragmentIons); psmBloated.Add(newPsmTwo); FdrAnalysisResults fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(psmBloated.Where(p => p != null).ToList(), 1, CommonParameters, new List <string>()).Run()); }
public static void TestGptmdEngine() { List <PeptideSpectralMatch> allResultingIdentifications = null; ModificationMotif.TryGetMotif("N", out ModificationMotif motifN); var gptmdModifications = new List <ModificationWithMass> { new ModificationWithMass("21", "mt", motifN, TerminusLocalization.Any, 21.981943) }; IEnumerable <Tuple <double, double> > combos = new List <Tuple <double, double> >(); Tolerance precursorMassTolerance = new PpmTolerance(10); allResultingIdentifications = new List <PeptideSpectralMatch>(); var engine = new GptmdEngine(allResultingIdentifications, gptmdModifications, combos, precursorMassTolerance, new List <string>()); var res = (GptmdResults)engine.Run(); Assert.AreEqual(0, res.Mods.Count); //PsmParent newPsm = new TestParentSpectrumMatch(588.22520189093 + 21.981943); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(new MzmlScanWithPrecursor(0, new MzmlMzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null, null, "scan=1"), (588.22520189093 + 21.981943).ToMz(1), 1, null); var parentProtein = new Protein("NNNNN", "accession"); var protease = new Protease("Custom Protease", new List <string> { "K" }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null); DigestionParams digestionParams = new DigestionParams(); List <ModificationWithMass> variableModifications = new List <ModificationWithMass>(); var modPep = parentProtein.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).First(); var peptidesWithSetModifications = new List <PeptideWithSetModifications> { modPep }; PeptideSpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First().CompactPeptide(TerminusType.None), 0, 0, 0, scan); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { peptidesWithSetModifications.First().CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> { peptidesWithSetModifications.First() } } }; List <ProductType> lp = new List <ProductType> { ProductType.B, ProductType.Y }; Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); newPsm.MatchToProteinLinkedPeptides(matching); newPsm.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0, 0, false); allResultingIdentifications.Add(newPsm); engine = new GptmdEngine(allResultingIdentifications, gptmdModifications, combos, precursorMassTolerance, new List <string>()); res = (GptmdResults)engine.Run(); Assert.AreEqual(1, res.Mods.Count); Assert.AreEqual(5, res.Mods["accession"].Count); }
protected List <int> GetBinsToSearch(Ms2ScanWithSpecificMass scan) { int obsPreviousFragmentCeilingMz = 0; List <int> binsToSearch = new List <int>(); foreach (var peakMz in scan.TheScan.MassSpectrum.XArray) { // assume charge state 1 to calculate mass tolerance double experimentalFragmentMass = Chemistry.ClassExtensions.ToMass(peakMz, 1); // get theoretical fragment bins within mass tolerance int obsFragmentFloorMass = (int)Math.Floor((CommonParameters.ProductMassTolerance.GetMinimumValue(experimentalFragmentMass)) * fragmentBinsPerDalton); if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz) { obsFragmentFloorMass = obsPreviousFragmentCeilingMz; } int obsFragmentCeilingMass = (int)Math.Ceiling((CommonParameters.ProductMassTolerance.GetMaximumValue(experimentalFragmentMass)) * fragmentBinsPerDalton); obsPreviousFragmentCeilingMz = obsFragmentCeilingMass + 1; for (int fragmentBin = obsFragmentFloorMass; fragmentBin <= obsFragmentCeilingMass; fragmentBin++) { if (fragmentIndex[fragmentBin] != null) { binsToSearch.Add(fragmentBin); } } if (addCompIons) { //okay, we're not actually adding in complementary m/z peaks, we're doing a shortcut and just straight up adding the bins assuming that they're z=1 foreach (DissociationType dissociationType in dissociationTypes) { if (complementaryIonConversionDictionary.TryGetValue(dissociationType, out double protonMassShift)) { protonMassShift = Chemistry.ClassExtensions.ToMass(protonMassShift, 1); int compFragmentFloorMass = (int)Math.Round(((scan.PrecursorMass + protonMassShift) * fragmentBinsPerDalton)) - obsFragmentCeilingMass; int compFragmentCeilingMass = (int)Math.Round(((scan.PrecursorMass + protonMassShift) * fragmentBinsPerDalton)) - obsFragmentFloorMass; if (compFragmentFloorMass > 0) { for (int fragmentBin = compFragmentFloorMass; fragmentBin <= compFragmentCeilingMass; fragmentBin++) { if (fragmentIndex[fragmentBin] != null) { binsToSearch.Add(fragmentBin); } } } } else { throw new NotImplementedException(); } } } } return(binsToSearch); }
public static void TestMs2ScanWithSpecificMass() { Ms2ScanWithSpecificMass scanB = new Ms2ScanWithSpecificMass( new MsDataScan( new MzSpectrum(new double[] { }, new double[] { }, false), 2, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 100, 1, null, new CommonParameters(), null); var closestExperimentalMassB = scanB.GetClosestExperimentalIsotopicEnvelope(10); Assert.IsNull(closestExperimentalMassB); }
public static void TestGptmdEngine(string proteinSequence, string accession, string sequenceVariantDescription, int numModifiedResidues) { List <PeptideSpectralMatch> allResultingIdentifications = null; ModificationMotif.TryGetMotif("N", out ModificationMotif motifN); var gptmdModifications = new List <Modification> { new Modification(_originalId: "21", _modificationType: "mt", _target: motifN, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943) }; IEnumerable <Tuple <double, double> > combos = new List <Tuple <double, double> >(); Tolerance precursorMassTolerance = new PpmTolerance(10); allResultingIdentifications = new List <PeptideSpectralMatch>(); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", new CommonParameters())); var engine = new GptmdEngine(allResultingIdentifications, gptmdModifications, combos, new Dictionary <string, Tolerance> { { "filepath", precursorMassTolerance } }, new CommonParameters(), fsp, new List <string>()); var res = (GptmdResults)engine.Run(); Assert.AreEqual(0, res.Mods.Count); var parentProtein = new Protein(proteinSequence, accession, sequenceVariations: new List <SequenceVariation> { new SequenceVariation(1, "N", "A", sequenceVariantDescription) }); var variantProteins = parentProtein.GetVariantProteins(); CommonParameters commonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5)); List <Modification> variableModifications = new List <Modification>(); var modPep = variantProteins.SelectMany(p => p.Digest(commonParameters.DigestionParams, new List <Modification>(), variableModifications)).First(); //PsmParent newPsm = new TestParentSpectrumMatch(588.22520189093 + 21.981943); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null), (new Proteomics.AminoAcidPolymer.Peptide(modPep.BaseSequence).MonoisotopicMass + 21.981943).ToMz(1), 1, "filepath", new CommonParameters()); var peptidesWithSetModifications = new List <PeptideWithSetModifications> { modPep }; PeptideSpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, commonParameters, new List <MatchedFragmentIon>()); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); newPsm.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0); allResultingIdentifications.Add(newPsm); engine = new GptmdEngine(allResultingIdentifications, gptmdModifications, combos, new Dictionary <string, Tolerance> { { "filepath", precursorMassTolerance } }, new CommonParameters(), null, new List <string>()); res = (GptmdResults)engine.Run(); Assert.AreEqual(1, res.Mods.Count); Assert.AreEqual(numModifiedResidues, res.Mods["accession"].Count); }
public static void TestLocalization() { Protein parentProteinForMatch = new Protein("MEK", null); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 1); ModificationMotif.TryGetMotif("E", out ModificationMotif motif); List <ModificationWithMass> variableModifications = new List <ModificationWithMass> { new ModificationWithMass("21", null, motif, TerminusLocalization.Any, 21.981943) }; List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList(); Assert.AreEqual(4, allPeptidesWithSetModifications.Count()); PeptideWithSetModifications ps = allPeptidesWithSetModifications.First(); List <ProductType> lp = new List <ProductType> { ProductType.BnoB1ions, ProductType.Y }; PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1]; MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { pepWithSetModsForSpectrum }); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null); PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps.CompactPeptide(TerminusType.None), 0, 0, 2, scan, digestionParams); Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>(); Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > { { ps.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> { ps } } }; newPsm.MatchToProteinLinkedPeptides(matching); CommonParameters commonParameters = new CommonParameters(productMassTolerance: fragmentTolerance); LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> { newPsm }, lp, myMsDataFile, commonParameters, new List <string>()); f.Run(); // Was single peak!!! Assert.AreEqual(0, newPsm.MatchedIonMassToChargeRatioDict[ProductType.BnoB1ions].Count(b => b > 0)); Assert.AreEqual(1, newPsm.MatchedIonMassToChargeRatioDict[ProductType.Y].Count(b => b > 0)); Assert.AreEqual(0, newPsm.MatchedIonIntensitiesDict[ProductType.BnoB1ions].Count(b => b > 0)); Assert.AreEqual(1, newPsm.MatchedIonIntensitiesDict[ProductType.Y].Count(b => b > 0)); // If localizing, three match!!! Assert.IsTrue(newPsm.LocalizedScores[1] > 3 && newPsm.LocalizedScores[1] < 4); }
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 TestCombos(string proteinSequence, string accession, string variantAA, string sequenceVariantDescription, int numModHashes, int numModifiedResidues, int numModifiedResiduesN, int numModifiedResiduesP, int numModifiedResiduesNP) { List <PeptideSpectralMatch> allIdentifications = null; ModificationMotif.TryGetMotif("N", out ModificationMotif motifN); ModificationMotif.TryGetMotif("P", out ModificationMotif motifP); var gptmdModifications = new List <Modification> { new Modification(_originalId: "21", _modificationType: "mt", _target: motifN, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943), new Modification(_originalId: "16", _modificationType: "mt", _target: motifP, _locationRestriction: "Anywhere.", _monoisotopicMass: 15.994915) }; IEnumerable <Tuple <double, double> > combos = new List <Tuple <double, double> > { new Tuple <double, double>(21.981943, 15.994915) }; Tolerance precursorMassTolerance = new PpmTolerance(10); var parentProtein = new Protein(proteinSequence, accession, sequenceVariations: new List <SequenceVariation> { new SequenceVariation(1, "N", variantAA, sequenceVariantDescription) }); var variantProteins = parentProtein.GetVariantProteins(); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 5); List <Modification> variableModifications = new List <Modification>(); var modPep = variantProteins.SelectMany(p => p.Digest(digestionParams, new List <Modification>(), variableModifications)).First(); MsDataScan dfd = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfd, (new Proteomics.AminoAcidPolymer.Peptide(modPep.BaseSequence).MonoisotopicMass + 21.981943 + 15.994915).ToMz(1), 1, "filepath", new CommonParameters()); var peptidesWithSetModifications = new List <PeptideWithSetModifications> { modPep }; PeptideSpectralMatch match = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, digestionParams, new List <MatchedFragmentIon>()); PeptideSpectralMatch newPsm = new PeptideSpectralMatch(peptidesWithSetModifications.First(), 0, 0, 0, scan, digestionParams, new List <MatchedFragmentIon>()); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); match.SetFdrValues(1, 0, 0, 1, 0, 0, 0, 0); allIdentifications = new List <PeptideSpectralMatch> { match }; var engine = new GptmdEngine(allIdentifications, gptmdModifications, combos, new Dictionary <string, Tolerance> { { "filepath", precursorMassTolerance } }, new CommonParameters(), new List <string>()); var res = (GptmdResults)engine.Run(); Assert.AreEqual(numModHashes, res.Mods.Count); Assert.AreEqual(numModifiedResidues, res.Mods["accession"].Count); Assert.AreEqual(numModifiedResiduesN, res.Mods["accession"].Where(b => b.Item2.OriginalId.Equals("21")).Count()); Assert.AreEqual(numModifiedResiduesP, res.Mods["accession"].Where(b => b.Item2.OriginalId.Equals("16")).Count()); res.Mods.TryGetValue("accession_N1P", out var hash); Assert.AreEqual(numModifiedResiduesNP, (hash ?? new HashSet <Tuple <int, Modification> >()).Count); }
public static void TestMzIdentMlWriterWithUniprotPsiMod() { Protein protein = new Protein("PEPTIDE", "", databaseFilePath: "temp"); ModificationMotif.TryGetMotif("T", out var motif); Modification fakeMod = new Modification(_originalId: "FAKE", _accession: "FAKE_MOD_ACCESSION", _modificationType: "fake", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 0, _databaseReference: new Dictionary <string, IList <string> > { { "PSI-MOD", new List <string> { "FAKE_MOD_ACCESSION" } } }); string resIdAccession = fakeMod.DatabaseReference["PSI-MOD"].First(); var peptide = protein.Digest(new DigestionParams(), new List <Modification> { fakeMod }, new List <Modification>()).First(); MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); var psm = new PeptideSpectralMatch(peptide, 0, 1, 0, scan, new DigestionParams(), new List <MatchedFragmentIon>()); psm.ResolveAllAmbiguities(); psm.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "ResIdOutput.mzID"); MzIdentMLWriter.WriteMzIdentMl(new List <PeptideSpectralMatch> { psm }, new List <ProteinGroup>(), new List <Modification>(), new List <Modification>(), new List <SilacLabel>(), new List <Protease>(), 0, new PpmTolerance(20), new PpmTolerance(20), 0, path); var file = File.ReadAllLines(path); bool found = false; foreach (var line in file) { if (line.Contains("FAKE on T") && line.Contains("PSI-MOD:" + resIdAccession)) { found = true; } } Assert.That(found); File.Delete(path); }
public static void SingleEventArgsTest() { Protein parentProteinForMatch = new Protein("MEK", null); CommonParameters commonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 1)); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", commonParameters)); ModificationMotif.TryGetMotif("E", out ModificationMotif motif); List <Modification> variableModifications = new List <Modification> { new Modification(_originalId: "21", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943) }; List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(commonParameters.DigestionParams, new List <Modification>(), variableModifications).ToList(); Assert.AreEqual(4, allPeptidesWithSetModifications.Count()); PeptideWithSetModifications ps = allPeptidesWithSetModifications.First(); PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1]; MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { pepWithSetModsForSpectrum }); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); var theoreticalProducts = new List <Product>(); ps.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalProducts); var matchedIons = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalProducts, new CommonParameters()); PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons); LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> { newPsm }, myMsDataFile, new CommonParameters(), fsp, new List <string>()); var singleEngine = new SingleEngineEventArgs(f); Assert.That(singleEngine.MyEngine.Equals(f)); var singleFile = new SingleFileEventArgs("", new List <string>()); Assert.That(singleFile.WrittenFile.Equals("")); var stringList = new StringListEventArgs(new List <string>()); var rr = (stringList.StringList.DefaultIfEmpty().First()); Assert.That(stringList.StringList.DefaultIfEmpty().First() == null); }
private List <MatchedFragmentIon> ScoreChildScan(Ms2ScanWithSpecificMass parentScan, Ms2ScanWithSpecificMass childScan, int possibleSite, BestPeptideScoreNotch mainPeptide, BestPeptideScoreNotch otherPeptide) { bool shortMassAlphaMs3 = XLPrecusorSearchMode.Accepts(childScan.PrecursorMass, mainPeptide.BestPeptide.MonoisotopicMass + Crosslinker.CleaveMassShort) >= 0; bool longMassAlphaMs3 = XLPrecusorSearchMode.Accepts(childScan.PrecursorMass, mainPeptide.BestPeptide.MonoisotopicMass + Crosslinker.CleaveMassLong) >= 0; List <Product> childProducts; if (Crosslinker.Cleavable && (shortMassAlphaMs3 || longMassAlphaMs3)) { double massToLocalize = shortMassAlphaMs3 ? Crosslinker.CleaveMassShort : Crosslinker.CleaveMassLong; if (mainPeptide.BestPeptide.AllModsOneIsNterminus.TryGetValue(possibleSite + 1, out var existingMod)) { massToLocalize += existingMod.MonoisotopicMass.Value; } Dictionary <int, Modification> mod = new Dictionary <int, Modification> { { possibleSite + 1, new Modification(_monoisotopicMass: massToLocalize) } }; foreach (var otherExistingMod in mainPeptide.BestPeptide.AllModsOneIsNterminus.Where(p => p.Key != possibleSite + 1)) { mod.Add(otherExistingMod.Key, otherExistingMod.Value); } var peptideWithMod = new PeptideWithSetModifications(mainPeptide.BestPeptide.Protein, mainPeptide.BestPeptide.DigestionParams, mainPeptide.BestPeptide.OneBasedStartResidueInProtein, mainPeptide.BestPeptide.OneBasedEndResidueInProtein, mainPeptide.BestPeptide.CleavageSpecificityForFdrCategory, mainPeptide.BestPeptide.PeptideDescription, mainPeptide.BestPeptide.MissedCleavages, mod, mainPeptide.BestPeptide.NumFixedMods); childProducts = peptideWithMod.Fragment(CommonParameters.ChildScanDissociationType, FragmentationTerminus.Both).ToList(); } else if (Math.Abs(childScan.PrecursorMass - parentScan.PrecursorMass) < 0.01 && CommonParameters.DissociationType != CommonParameters.ChildScanDissociationType) { // same species got fragmented twice, the second time with a different dissociation type childProducts = CrosslinkedPeptide.XlGetTheoreticalFragments(CommonParameters.ChildScanDissociationType, Crosslinker, new List <int> { possibleSite }, otherPeptide.BestPeptide.MonoisotopicMass, mainPeptide.BestPeptide).First().Item2; } else { return(null); } var matchedChildIons = MatchFragmentIons(childScan, childProducts, CommonParameters); return(matchedChildIons); }
//Based on our implementation of Graph localization. We need to calculate cost between two nearby nodes (glycosites) public static double CalculateCost(Ms2ScanWithSpecificMass theScan, Tolerance productTolerance, List <double> fragments) { double score = 0; foreach (var f in fragments) { var closestExperimentalMass = theScan.GetClosestExperimentalIsotopicEnvelope(f); // is the mass error acceptable? if (productTolerance.Within(closestExperimentalMass.MonoisotopicMass, f) && closestExperimentalMass.Charge <= theScan.PrecursorCharge) { score += 1 + closestExperimentalMass.Peaks.Sum(p => p.intensity) / theScan.TotalIonCurrent; } } return(score); }
public static void TestMzIdentMlWriterWithUniprotResId() { Protein protein = new Protein("PEPTIDE", "", databaseFilePath: "temp"); Modification uniProtMod = GlobalVariables.AllModsKnown.First(p => p.IdWithMotif == "FMN phosphoryl threonine on T" && p.ModificationType == "UniProt" && p.Target.ToString() == "T" && p.DatabaseReference.ContainsKey("RESID") && p.LocationRestriction == "Anywhere."); string resIdAccession = uniProtMod.DatabaseReference["RESID"].First(); var peptide = protein.Digest(new DigestionParams(), new List <Modification> { uniProtMod }, new List <Modification>()).First(); MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); var psm = new PeptideSpectralMatch(peptide, 0, 1, 0, scan, new DigestionParams(), new List <MatchedFragmentIon>()); psm.ResolveAllAmbiguities(); psm.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0); string path = Path.Combine(TestContext.CurrentContext.TestDirectory, "ResIdOutput.mzID"); MzIdentMLWriter.WriteMzIdentMl(new List <PeptideSpectralMatch> { psm }, new List <ProteinGroup>(), new List <Modification>(), new List <Modification>(), new List <SilacLabel>(), new List <Protease>(), 0, new PpmTolerance(20), new PpmTolerance(20), 0, path); var file = File.ReadAllLines(path); bool found = false; foreach (var line in file) { if (line.Contains("FMN phosphoryl threonine on T") && line.Contains("RESID:" + resIdAccession)) { found = true; } } Assert.That(found); File.Delete(path); }
public static void TestLocalization() { Protein parentProteinForMatch = new Protein("MEK", null); CommonParameters commonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 1)); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", commonParameters)); ModificationMotif.TryGetMotif("E", out ModificationMotif motif); List <Modification> variableModifications = new List <Modification> { new Modification(_originalId: "21", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943) }; List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(commonParameters.DigestionParams, new List <Modification>(), variableModifications).ToList(); Assert.AreEqual(4, allPeptidesWithSetModifications.Count()); PeptideWithSetModifications ps = allPeptidesWithSetModifications.First(); PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1]; MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { pepWithSetModsForSpectrum }); Tolerance fragmentTolerance = new AbsoluteTolerance(0.01); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters()); var theoreticalProducts = new List <Product>(); ps.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalProducts); var matchedIons = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalProducts, new CommonParameters()); PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons); newPsm.ResolveAllAmbiguities(); LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> { newPsm }, myMsDataFile, commonParameters, fsp, new List <string>()); f.Run(); // single peak matches Assert.AreEqual(1, newPsm.MatchedFragmentIons.Where(p => p.NeutralTheoreticalProduct.ProductType == ProductType.b).Count());//including b1 now Assert.AreEqual(1, newPsm.MatchedFragmentIons.Where(p => p.NeutralTheoreticalProduct.ProductType == ProductType.y).Count()); // when localizing, three peaks match Assert.IsTrue(newPsm.LocalizedScores[1] > 4 && newPsm.LocalizedScores[1] < 5);//we have another matched ion }
public static void ParsimonyWeirdCatch() { Protein protein1 = new Protein("MATSIK", "protein1", isDecoy: true); Protein protein2 = new Protein("MATSIK", "protein2"); IEnumerable <Modification> allKnownFixedModifications = new List <Modification>(); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 5); List <Modification> variableModifications = new List <Modification>(); var pep1 = protein1.Digest(digestionParams, allKnownFixedModifications, variableModifications).First(); var pep2 = protein2.Digest(digestionParams, allKnownFixedModifications, variableModifications).First(); // build the dictionary for input to parsimony MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); List <PeptideSpectralMatch> psms = new List <PeptideSpectralMatch> { new PeptideSpectralMatch(pep1, 0, 1, 0, scan, new DigestionParams(), new List <MatchedFragmentIon>()), }; // this PSM has a target and a decoy psms[0].AddOrReplace(pep2, 1, 0, true, null, 0); psms.ForEach(p => p.ResolveAllAmbiguities()); psms.ForEach(p => p.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0)); // apply parsimony ProteinParsimonyEngine pae = new ProteinParsimonyEngine(psms, false, new CommonParameters(), new List <string>()); // because the two chosen peptides are the same, we should end up with both protein accessions still in the list var proteinParsimonyResult = (ProteinParsimonyResults)pae.Run(); // score protein groups and merge indistinguishable ones ProteinScoringAndFdrEngine proteinScoringEngine = new ProteinScoringAndFdrEngine(proteinParsimonyResult.ProteinGroups, psms, false, true, true, new CommonParameters(), new List <string>()); var results = (ProteinScoringAndFdrResults)proteinScoringEngine.Run(); int countOfProteinGroups = results.SortedAndScoredProteinGroups.Count; // only target protein gets generated Assert.That(countOfProteinGroups == 1); Assert.That(results.SortedAndScoredProteinGroups.First().Proteins.Count == 1); Assert.That(!results.SortedAndScoredProteinGroups.First().IsDecoy); }
public static void TestRemoveThisAmbiguousePeptide() { Ms2ScanWithSpecificMass scanB = new Ms2ScanWithSpecificMass( new MsDataScan( new MzSpectrum(new double[] { }, new double[] { }, false), 2, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 100, 1, null, new CommonParameters(), null); PeptideSpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary <int, Modification>(), 0), 0, 10, 1, scanB, new DigestionParams(), new List <MatchedFragmentIon>(), 0); PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary <int, Modification>(), 0); psm1.AddOrReplace(pwsm, 10, 1, true, new List <MatchedFragmentIon>(), 0); Assert.AreEqual(2, psm1.BestMatchingPeptides.Count()); psm1.RemoveThisAmbiguousPeptide(1, pwsm); Assert.AreEqual(1, psm1.BestMatchingPeptides.Count()); }
public static void AddCompIonsMzOutput() { PeptideWithSetModifications pwsm = new PeptideWithSetModifications("ASDFASDF", null); Ms2ScanWithSpecificMass testScan = MetaMorpheusTask.GetMs2Scans(new TestDataFile(pwsm), null, new CommonParameters()).OrderBy(b => b.PrecursorMass).First(); CommonParameters cp = new CommonParameters(addCompIons: true); List <Product> theoreticalIons = new List <Product>(); pwsm.Fragment(cp.DissociationType, FragmentationTerminus.Both, theoreticalIons); List <MatchedFragmentIon> matchedIons = MetaMorpheusEngine.MatchFragmentIons(testScan, theoreticalIons, cp); //check that the matchedIons have m/z values that are similar to their neutral mass. //There was an "issue" where the saved m/z was the original experimental peak (which is the complementary of the added ion). //A fix was introduced to save a "fake" m/z for the added ion foreach (MatchedFragmentIon ion in matchedIons) { Assert.IsTrue(ion.NeutralTheoreticalProduct.NeutralMass < ion.Mz); Assert.IsTrue(ion.NeutralTheoreticalProduct.NeutralMass + 2 > ion.Mz); } }
//Calculate score based on All possible Products Masses for inter- or intra- crosslinks and deadend. public static void XlLocalizationForLoopCrosslink(Ms2ScanWithSpecificMass theScan, PsmCross psmCross, double modMass, CrosslinkerTypeClass crosslinker, List <ProductType> lp, Tolerance fragmentTolerance, List <int> linkPos) { var pmmhList = PsmCross.XlCalculateTotalProductMassesForLoopCrosslink(psmCross, modMass, crosslinker, lp, linkPos); List <double> scoreList = new List <double>(); List <MatchedIonInfo> miil = new List <MatchedIonInfo>(); foreach (var pmm in pmmhList) { var matchedIonMassesListPositiveIsMatch = new MatchedIonInfo(pmm.ProductMz.Length); double pmmScore = PsmCross.XlMatchIons(theScan.TheScan, fragmentTolerance, pmm.ProductMz, pmm.ProductName, matchedIonMassesListPositiveIsMatch); miil.Add(matchedIonMassesListPositiveIsMatch); scoreList.Add(pmmScore); } psmCross.XLBestScore = scoreList.Max(); psmCross.MatchedIonInfo = miil[scoreList.IndexOf(scoreList.Max())]; psmCross.XlPos = pmmhList[scoreList.IndexOf(scoreList.Max())].XlPos + 1; psmCross.XlPos2 = pmmhList[scoreList.IndexOf(scoreList.Max())].XlPos2 + 1; }
public static double[] ScanOxoniumIonFilter(Ms2ScanWithSpecificMass theScan, MassDiffAcceptor massDiffAcceptor, DissociationType dissociationType) { double[] oxoniumIonsintensities = new double[Glycan.AllOxoniumIons.Length]; if (dissociationType != DissociationType.HCD && dissociationType != DissociationType.CID && dissociationType != DissociationType.EThcD) { return(oxoniumIonsintensities); } for (int i = 0; i < Glycan.AllOxoniumIons.Length; i++) { var oxoMass = ((double)Glycan.AllOxoniumIons[i] / 1E5).ToMass(1); var envelope = theScan.GetClosestExperimentalIsotopicEnvelope(oxoMass); if (massDiffAcceptor.Accepts(envelope.MonoisotopicMass, oxoMass) >= 0) { oxoniumIonsintensities[i] = envelope.TotalIntensity; } } return(oxoniumIonsintensities); }
public static Tuple <int, double, double>[] MatchBestGlycan(Ms2ScanWithSpecificMass theScan, Glycan[] glycans, CommonParameters commonParameters) { Tuple <int, double, double>[] tuples = new Tuple <int, double, double> [glycans.Length]; //Tuple<id, Yion matched score, glycan mass> //TO DO: Parallel this? for (int i = 0; i < glycans.Length; i++) { if (theScan.PrecursorMass - (double)glycans[i].Mass / 1E5 < 350) //Filter large glycans { continue; } List <Product> YIons = GetGlycanYIons(theScan.PrecursorMass, glycans[i]); List <MatchedFragmentIon> matchedFragmentIons = MetaMorpheusEngine.MatchFragmentIons(theScan, YIons, commonParameters); if (ScanTrimannosylCoreFilter(matchedFragmentIons, glycans[i])) { var score = MetaMorpheusEngine.CalculatePeptideScore(theScan.TheScan, matchedFragmentIons); tuples[i] = new Tuple <int, double, double>(i, score, (double)glycans[i].Mass / 1E5); } } return(tuples); }
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')); }
protected override MetaMorpheusEngineResults RunSpecific() { // don't try to localize mass differences for ambiguous peptides foreach (PeptideSpectralMatch psm in AllResultingIdentifications.Where(b => b.FullSequence != null)) { // Stop loop if canceled if (GlobalVariables.StopLoops) { break; } MsDataScan scan = MyMsDataFile.GetOneBasedScan(psm.ScanNumber); Ms2ScanWithSpecificMass scanWithSpecificMass = new Ms2ScanWithSpecificMass(scan, psm.ScanPrecursorMonoisotopicPeakMz, psm.ScanPrecursorCharge, psm.FullFilePath, CommonParameters); PeptideWithSetModifications peptide = psm.BestMatchingPeptides.First().Peptide; double massDifference = psm.ScanPrecursorMass - peptide.MonoisotopicMass; // this section will iterate through all residues of the peptide and try to localize the mass-diff at each residue and report a score for each residue var localizedScores = new List <double>(); for (int r = 0; r < peptide.Length; r++) { // create new PeptideWithSetMods with unidentified mass difference at the given residue PeptideWithSetModifications peptideWithLocalizedMassDiff = peptide.Localize(r, massDifference); // this is the list of theoretical products for this peptide with mass-difference on this residue List <Product> productsWithLocalizedMassDiff = peptideWithLocalizedMassDiff.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus).ToList(); var matchedIons = MatchFragmentIons(scanWithSpecificMass, productsWithLocalizedMassDiff, CommonParameters); // score when the mass-diff is on this residue double localizedScore = CalculatePeptideScore(scan, matchedIons); localizedScores.Add(localizedScore); } psm.LocalizedScores = localizedScores; } return(new LocalizationEngineResults(this)); }
public static void TopPickedFdrTest() { //Test that the decoy beats out the target for FDR, but that the target still gets written. Protein fillerProtein = new Protein("FILLR", "filler"); Protein targetProtein = new Protein("KFDSA", "protein"); Protein decoyProtein = new Protein("ASDFK", "DECOY_protein", isDecoy: true); IEnumerable <Modification> allKnownFixedModifications = new List <Modification>(); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 5); List <Modification> variableModifications = new List <Modification>(); PeptideWithSetModifications fillerPep = fillerProtein.Digest(digestionParams, allKnownFixedModifications, variableModifications).First(); PeptideWithSetModifications targetPep = targetProtein.Digest(digestionParams, allKnownFixedModifications, variableModifications).First(); PeptideWithSetModifications decoyPep = decoyProtein.Digest(digestionParams, allKnownFixedModifications, variableModifications).First(); // build the dictionary for input to parsimony MsDataScan dfb = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null); Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(dfb, 2, 0, "File", new CommonParameters()); List <PeptideSpectralMatch> psms = new List <PeptideSpectralMatch> { new PeptideSpectralMatch(fillerPep, 0, 30, 0, scan, new DigestionParams(), new List <MatchedFragmentIon>()), new PeptideSpectralMatch(decoyPep, 0, 15.11, 0, scan, new DigestionParams(), new List <MatchedFragmentIon>()), new PeptideSpectralMatch(targetPep, 0, 15.1, 0, scan, new DigestionParams(), new List <MatchedFragmentIon>()) }; psms.ForEach(p => p.ResolveAllAmbiguities()); psms.ForEach(p => p.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0)); // apply parsimony ProteinParsimonyEngine pae = new ProteinParsimonyEngine(psms, false, new CommonParameters(), new List <string>()); ProteinParsimonyResults proteinParsimonyResult = (ProteinParsimonyResults)pae.Run(); ProteinScoringAndFdrEngine proteinScoringEngine = new ProteinScoringAndFdrEngine(proteinParsimonyResult.ProteinGroups, psms, false, true, true, new CommonParameters(), new List <string>()); ProteinScoringAndFdrResults results = (ProteinScoringAndFdrResults)proteinScoringEngine.Run(); Assert.IsTrue(results.SortedAndScoredProteinGroups.Count == 3); Assert.IsTrue(results.SortedAndScoredProteinGroups[1].QValue == 0.5); }