public static void TestAddCompIonsClassic() { var myMsDataFile = new TestDataFile(); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("QXQ", null) }; var productMassTolerance = new AbsoluteTolerance(0.01); var searchModes = new OpenSearchMode(); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("Custom Protease3", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters = new CommonParameters( digestionParams: new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1), scoreCutoff: 1, addCompIons: false); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, fsp, null, new List <string>()).Run(); CommonParameters CommonParameters2 = new CommonParameters( digestionParams: new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1), scoreCutoff: 1, addCompIons: true); var fsp2 = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp2.Add(("", CommonParameters2)); PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters2, fsp2, null, new List <string>()).Run(); double scoreT = allPsmsArray2[0].Score; double scoreF = allPsmsArray[0].Score; // Single search mode Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length); // Single ms2 scan Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length); Assert.IsTrue(scoreT > 1); Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber); Assert.IsTrue(scoreT == scoreF * 3 && scoreT > scoreF + 2); }
public static void TestAddCompIonsClassic() { var myMsDataFile = new TestDataFile(); var variableModifications = new List <ModificationWithMass>(); var fixedModifications = new List <ModificationWithMass>(); var proteinList = new List <Protein> { new Protein("QXQ", null) }; var productMassTolerance = new AbsoluteTolerance(0.01); var searchModes = new OpenSearchMode(); 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(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; CommonParameters CommonParameters = new CommonParameters { DigestionParams = new DigestionParams { Protease = new Protease("Custom Protease", new List <string> { "K" }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null), MinPeptideLength = null, MaxMissedCleavages = 0 }, ConserveMemory = false, ScoreCutoff = 1, }; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, new List <ProductType> { ProductType.B, ProductType.Y }, searchModes, false, CommonParameters, CommonParameters.ProductMassTolerance, new List <string>()).Run(); PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, new List <ProductType> { ProductType.B, ProductType.Y }, searchModes, true, CommonParameters, CommonParameters.ProductMassTolerance, new List <string>()).Run(); double scoreT = allPsmsArray2[0].Score; double scoreF = allPsmsArray[0].Score; // Single search mode Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length); // Single ms2 scan Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length); Assert.IsTrue(scoreT > 1); Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber); Assert.IsTrue(scoreT == scoreF * 3 && scoreT > scoreF + 2); }
private static MassDiffAcceptor ParseSearchMode(string text) { MassDiffAcceptor massDiffAcceptor = null; try { var split = text.Split(' '); switch (split[1]) { case "dot": double[] massShifts = split[4].Split(',').Select(p => double.Parse(p, CultureInfo.InvariantCulture)).ToArray(); string newString = split[2].Replace("�", ""); double toleranceValue = double.Parse(newString, CultureInfo.InvariantCulture); if (split[3].ToUpperInvariant().Equals("PPM")) { massDiffAcceptor = new DotMassDiffAcceptor(split[0], massShifts, new PpmTolerance(toleranceValue)); } else if (split[3].ToUpperInvariant().Equals("DA")) { massDiffAcceptor = new DotMassDiffAcceptor(split[0], massShifts, new AbsoluteTolerance(toleranceValue)); } break; case "interval": IEnumerable <DoubleRange> doubleRanges = Array.ConvertAll(split[2].Split(';'), b => new DoubleRange(double.Parse(b.Trim(new char[] { '[', ']' }).Split(',')[0], CultureInfo.InvariantCulture), double.Parse(b.Trim(new char[] { '[', ']' }).Split(',')[1], CultureInfo.InvariantCulture))); massDiffAcceptor = new IntervalMassDiffAcceptor(split[0], doubleRanges); break; case "OpenSearch": massDiffAcceptor = new OpenSearchMode(); break; case "daltonsAroundZero": massDiffAcceptor = new SingleAbsoluteAroundZeroSearchMode(double.Parse(split[2], CultureInfo.InvariantCulture)); break; case "ppmAroundZero": massDiffAcceptor = new SinglePpmAroundZeroSearchMode(double.Parse(split[2], CultureInfo.InvariantCulture)); break; default: throw new MetaMorpheusException("Unrecognized search mode type: " + split[1]); } } catch (Exception e) { throw new MetaMorpheusException("Could not parse search mode string: " + e.Message); } return(massDiffAcceptor); }
private static MassDiffAcceptor ParseSearchMode(string text) { MassDiffAcceptor ye = null; var split = text.Split(' '); switch (split[1]) { case "dot": var massShifts = Array.ConvertAll(split[4].Split(','), Double.Parse); var newString = split[2].Replace("�", ""); var toleranceValue = double.Parse(newString, CultureInfo.InvariantCulture); if (split[3].ToUpperInvariant().Equals("PPM")) { ye = new DotMassDiffAcceptor(split[0], massShifts, new PpmTolerance(toleranceValue)); } else if (split[3].ToUpperInvariant().Equals("DA")) { ye = new DotMassDiffAcceptor(split[0], massShifts, new AbsoluteTolerance(toleranceValue)); } break; case "interval": IEnumerable <DoubleRange> doubleRanges = Array.ConvertAll(split[2].Split(','), b => new DoubleRange(double.Parse(b.Trim(new char[] { '[', ']' }).Split(';')[0], CultureInfo.InvariantCulture), double.Parse(b.Trim(new char[] { '[', ']' }).Split(';')[1], CultureInfo.InvariantCulture))); ye = new IntervalMassDiffAcceptor(split[0], doubleRanges); break; case "OpenSearch": ye = new OpenSearchMode(); break; case "daltonsAroundZero": ye = new SingleAbsoluteAroundZeroSearchMode(double.Parse(split[2], CultureInfo.InvariantCulture)); break; case "ppmAroundZero": ye = new SinglePpmAroundZeroSearchMode(double.Parse(split[2], CultureInfo.InvariantCulture)); break; default: throw new MetaMorpheusException("Could not parse search mode string"); } return(ye); }
public static void TestMatchIonsOfAllChargesBottomUp() { CommonParameters CommonParameters = new CommonParameters(); MetaMorpheusTask.DetermineAnalyteType(CommonParameters); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("AAAHSSLK", ""), new Protein("RQPAQPR", ""), new Protein("EKAEAEAEK", "") }; var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML")); var searchMode = new SinglePpmAroundZeroSearchMode(5); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); //search by new method of looking for all charges PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List <string>(), true).Run(); var psm = allPsmsArray.Where(p => p != null).ToList(); Assert.That(psm[1].MatchedFragmentIons.Count == 14); //there are ions with same product type and same fragment number but different charges Assert.That(psm[1].MatchedFragmentIons[8].NeutralTheoreticalProduct.ProductType == psm[1].MatchedFragmentIons[9].NeutralTheoreticalProduct.ProductType && psm[1].MatchedFragmentIons[8].NeutralTheoreticalProduct.FragmentNumber == psm[1].MatchedFragmentIons[9].NeutralTheoreticalProduct.FragmentNumber && psm[1].MatchedFragmentIons[8].Charge != psm[1].MatchedFragmentIons[9].Charge); Assert.That(psm[2].MatchedFragmentIons.Count == 14); Assert.That(psm[4].MatchedFragmentIons.Count == 16); //search by old method of looking for only one charge PeptideSpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray_oneCharge, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List <string>(), false).Run(); var psm_oneCharge = allPsmsArray_oneCharge.Where(p => p != null).ToList(); //compare 2 scores , they should have same integer part but new search has a little higher score than old search Assert.That(psm[1].Score > psm_oneCharge[1].Score); Assert.AreEqual(Math.Truncate(psm[1].Score), 12); Assert.AreEqual(Math.Truncate(psm_oneCharge[1].Score), 12); //compare 2 results and evaluate the different matched ions var peptideTheorProducts = new List <Product>(); Assert.That(psm_oneCharge[1].MatchedFragmentIons.Count == 12); var differences = psm[1].MatchedFragmentIons.Except(psm_oneCharge[1].MatchedFragmentIons); psm[1].BestMatchingPeptides.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts); foreach (var ion in differences) { foreach (var product in peptideTheorProducts) { if (product.Annotation.ToString().Equals(ion.NeutralTheoreticalProduct.Annotation.ToString())) { //to see if the different matched ions are qualified Assert.That(CommonParameters.ProductMassTolerance.Within(ion.Mz.ToMass(ion.Charge), product.NeutralMass)); } } } //test specific condition: unknown fragment mass; this only happens rarely for sequences with unknown amino acids var myMsDataFile1 = new TestDataFile(); var variableModifications1 = new List <Modification>(); var fixedModifications1 = new List <Modification>(); var proteinList1 = new List <Protein> { new Protein("QXQ", null) }; var productMassTolerance = new AbsoluteTolerance(0.01); var searchModes = new OpenSearchMode(); Tolerance DeconvolutionMassTolerance1 = new PpmTolerance(5); var listOfSortedms2Scans1 = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("Custom Protease3", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters1 = new CommonParameters( digestionParams: new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1), scoreCutoff: 1, addCompIons: false); var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>(); fsp.Add(("", CommonParameters)); PeptideSpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; bool writeSpectralLibrary = true; new ClassicSearchEngine(allPsmsArray1, listOfSortedms2Scans1, variableModifications1, fixedModifications1, null, null, null, proteinList1, searchModes, CommonParameters1, fsp, null, new List <string>(), writeSpectralLibrary).Run(); var psm1 = allPsmsArray1.Where(p => p != null).ToList(); Assert.AreEqual(psm1.Count, 222); }
protected override MetaMorpheusEngineResults RunSpecific() { MassDiffAcceptor XLsearchMode = new OpenSearchMode(); CrosslinkAnalysisResults myAnalysisResults = new CrosslinkAnalysisResults(this); Status("Running analysis engine!"); //At this point have Spectrum-Sequence matching, without knowing which protein, and without know if target/decoy #region Match Seqeunces to PeptideWithSetModifications //myAnalysisResults.AddText("Starting compactPeptideToProteinPeptideMatching count: " + compactPeptideToProteinPeptideMatching.Count); Status("Adding observed peptides to dictionary..."); foreach (var psmpair in newPsms) { if (psmpair != null) { var cp = psmpair.compactPeptide; if (!compactPeptideToProteinPeptideMatching.ContainsKey(cp)) { compactPeptideToProteinPeptideMatching.Add(cp, new HashSet <PeptideWithSetModifications>()); } if (psmpair.BetaPsmCross != null) { var cp1 = psmpair.BetaPsmCross.compactPeptide; if (!compactPeptideToProteinPeptideMatching.ContainsKey(cp1)) { compactPeptideToProteinPeptideMatching.Add(cp1, new HashSet <PeptideWithSetModifications>()); } } } } //myAnalysisResults.AddText("Ending compactPeptideToProteinPeptideMatching count: " + compactPeptideToProteinPeptideMatching.Count); int totalProteins = proteinList.Count; int proteinsSeen = 0; int old_progress = 0; var obj = new object(); Status("Adding possible sources to peptide dictionary..."); Parallel.ForEach(Partitioner.Create(0, totalProteins), fff => { Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > local = compactPeptideToProteinPeptideMatching.ToDictionary(b => b.Key, b => new HashSet <PeptideWithSetModifications>()); for (int i = fff.Item1; i < fff.Item2; i++) { foreach (var peptideWithSetModifications in proteinList[i].Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications)) { if (local.TryGetValue(new CompactPeptide(peptideWithSetModifications, terminusType), out HashSet <PeptideWithSetModifications> v)) { v.Add(peptideWithSetModifications); } } } lock (obj) { foreach (var ye in local) { if (compactPeptideToProteinPeptideMatching.TryGetValue(ye.Key, out HashSet <PeptideWithSetModifications> v)) { foreach (var huh in ye.Value) { v.Add(huh); } } } proteinsSeen += fff.Item2 - fff.Item1; var new_progress = (int)((double)proteinsSeen / (totalProteins) * 100); if (new_progress > old_progress) { ReportProgress(new ProgressEventArgs(new_progress, "In adding possible" + " sources to peptide dictionary loop", nestedIds)); old_progress = new_progress; } } }); #endregion Match Seqeunces to PeptideWithSetModifications Status("Computing info about actual peptides with modifications..."); for (int myScanWithMassIndex = 0; myScanWithMassIndex < newPsms.Count; myScanWithMassIndex++) { var huh = newPsms[myScanWithMassIndex]; if (huh != null) { huh.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching); } if (huh != null) { var huh1 = newPsms[myScanWithMassIndex].BetaPsmCross; if (huh1 != null) { huh1.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching); } } } return(myAnalysisResults); }