//[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 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 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); }
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 }