private void SpeciesListView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { AnnotatedSpecies species = ((TreeView)sender).SelectedItem as AnnotatedSpecies; MsDataScan scan = null; var file = SpectraFiles.FirstOrDefault(p => System.IO.Path.GetFileNameWithoutExtension(p.Key) == species.DeconvolutionFeature.SpectraFileNameWithoutExtension); if (file.Value == null) { MessageBox.Show("The spectra file '" + species.DeconvolutionFeature.SpectraFileNameWithoutExtension + "' has not been loaded"); } CurrentlySelectedSpectraFile = file; for (int i = 1; i < 10000000; i++) { var theScan = file.Value.GetOneBasedScanFromDynamicConnection(i); if (theScan.RetentionTime >= species.DeconvolutionFeature.ApexRt && theScan.MsnOrder == 1) { scan = theScan; break; } } PlotSpecies(species, scan); }
private static List <LabeledDataPoint> SearchMS2Spectrum(MsDataScan ms2DataScan, PeptideSpectralMatch identification) { List <LabeledDataPoint> result = new List <LabeledDataPoint>(); if (ms2DataScan.MassSpectrum.Size == 0) { return(result); } foreach (var matchedIon in identification.MatchedFragmentIons) { double exptPeakMz = matchedIon.Mz; double exptPeakIntensity = matchedIon.Intensity; double injTime = ms2DataScan.InjectionTime ?? double.NaN; result.Add( new LabeledDataPoint( exptPeakMz, ms2DataScan.OneBasedScanNumber, Math.Log(ms2DataScan.TotalIonCurrent), Math.Log(injTime), Math.Log(exptPeakIntensity), matchedIon.NeutralTheoreticalProduct.NeutralMass.ToMz(matchedIon.Charge), identification)); } return(result); }
public Ms2ScanWithSpecificMass(MsDataScan mzLibScan, double precursorMonoisotopicPeakMz, int precursorCharge, string fullFilePath, CommonParameters commonParam, IsotopicEnvelope[] neutralExperimentalFragments = null) { PrecursorMonoisotopicPeakMz = precursorMonoisotopicPeakMz; PrecursorCharge = precursorCharge; PrecursorMass = PrecursorMonoisotopicPeakMz.ToMass(precursorCharge); FullFilePath = fullFilePath; ChildScans = new List <Ms2ScanWithSpecificMass>(); NativeId = mzLibScan.NativeId; TheScan = mzLibScan; if (commonParam.DissociationType != DissociationType.LowCID) { ExperimentalFragments = neutralExperimentalFragments ?? GetNeutralExperimentalFragments(mzLibScan, commonParam); } if (ExperimentalFragments != null && ExperimentalFragments.Any()) { DeconvolutedMonoisotopicMasses = ExperimentalFragments.Select(p => p.MonoisotopicMass).ToArray(); } else { DeconvolutedMonoisotopicMasses = new double[0]; } }
/// <summary> /// Constructor for the BestScan class /// </summary> /// <param name="firstIndex"></param> /// <param name="lastIndex"></param> /// <param name="totalIntensity"></param> /// <param name="scan"></param> public BestScan(int firstIndex, int lastIndex, double totalIntensity, MsDataScan scan) { FirstIndex = firstIndex; LastIndex = lastIndex; TotalIntensity = totalIntensity; Scan = scan; }
public static double CalculatePeptideScore(MsDataScan thisScan, List <MatchedFragmentIon> matchedFragmentIons, double maximumMassThatFragmentIonScoreIsDoubled) { // scoring if some fragments get doubled for scoring purposes if (maximumMassThatFragmentIonScoreIsDoubled > 0) { double score = 0; foreach (var fragment in matchedFragmentIons) { double fragmentScore = 1 + (fragment.Intensity / thisScan.TotalIonCurrent); if (fragment.TheoreticalFragmentIon.Mass <= maximumMassThatFragmentIonScoreIsDoubled) { score += fragmentScore * 2; } else { score += fragmentScore; } } return(score); } // normal scoring return(matchedFragmentIons.Count + (matchedFragmentIons.Sum(v => v.Intensity) / thisScan.TotalIonCurrent)); }
public TestDataFile(PeptideWithSetModifications pepWithSetMods) : base(2, new SourceFile(@"no nativeID format", "mzML format", null, "SHA-1", @"C:\fake.mzML", null)) { var mz1 = new double[] { pepWithSetMods.MonoisotopicMass.ToMz(2), (pepWithSetMods.MonoisotopicMass + 1.003).ToMz(2), (pepWithSetMods.MonoisotopicMass + 2.005).ToMz(2) }; var intensities1 = new double[] { 1, 1, 1 }; var MassSpectrum1 = new MzSpectrum(mz1, intensities1, false); var ScansHere = new List <MsDataScan> { new MsDataScan(MassSpectrum1, 1, 1, true, Polarity.Positive, 1, new MzLibUtil.MzRange(0, 10000), "ff", MZAnalyzerType.Unknown, 1000, 1, null, "scan=1") }; List <double> mz2 = new List <double>(); List <double> intensities2 = new List <double>(); foreach (var aok in pepWithSetMods.CompactPeptide(TerminusType.None).ProductMassesMightHaveDuplicatesAndNaNs(new List <ProductType> { ProductType.B, ProductType.Y })) { mz2.Add(aok.ToMz(1)); mz2.Add((aok + 1.003).ToMz(1)); intensities2.Add(1); intensities2.Add(1); } var MassSpectrum2 = new MzSpectrum(mz2.OrderBy(b => b).ToArray(), intensities2.ToArray(), false); var scan2 = new MsDataScan(MassSpectrum2, 2, 2, true, Polarity.Positive, 2, new MzLibUtil.MzRange(0, 10000), "df", MZAnalyzerType.Orbitrap, 234734, 1, null, "scan=2", pepWithSetMods.MonoisotopicMass.ToMz(2), 2, 1, pepWithSetMods.MonoisotopicMass.ToMz(2), 2, DissociationType.HCD, 1, pepWithSetMods.MonoisotopicMass.ToMz(2)); scan2.ComputeSelectedPeakIntensity(MassSpectrum1); scan2.ComputeMonoisotopicPeakIntensity(MassSpectrum1); ScansHere.Add(scan2); Scans = ScansHere.ToArray(); }
public static AnnotatedEnvelope GetAnnotatedEnvelope(double monoMass, MsDataScan scan, int charge, double ppmTolerance = 5) { List <double> mzPeaks = new List <double>(); Tolerance tol = new PpmTolerance(ppmTolerance); for (int i = 0; i < 20; i++) { double isotopeMass = monoMass + i * Constants.C13MinusC12; double isotopeMz = isotopeMass.ToMz(charge); int ind = scan.MassSpectrum.GetClosestPeakIndex(isotopeMz); double expMz = scan.MassSpectrum.XArray[ind]; if (tol.Within(expMz.ToMass(charge), isotopeMass) && !mzPeaks.Contains(expMz)) { mzPeaks.Add(expMz); } else if (mzPeaks.Count > 0) { break; } } return(new AnnotatedEnvelope(scan.OneBasedScanNumber, scan.RetentionTime, charge, mzPeaks)); }
public static IsotopicEnvelope[] GetNeutralExperimentalFragments(MsDataScan scan, CommonParameters commonParam) { int minZ = 1; int maxZ = 10; var neutralExperimentalFragmentMasses = scan.MassSpectrum.Deconvolute(scan.MassSpectrum.Range, minZ, maxZ, commonParam.DeconvolutionMassTolerance.Value, commonParam.DeconvolutionIntensityRatio).ToList(); if (commonParam.AssumeOrphanPeaksAreZ1Fragments) { HashSet <double> alreadyClaimedMzs = new HashSet <double>(neutralExperimentalFragmentMasses .SelectMany(p => p.peaks.Select(v => ClassExtensions.RoundedDouble(v.mz).Value))); for (int i = 0; i < scan.MassSpectrum.XArray.Length; i++) { double mz = scan.MassSpectrum.XArray[i]; double intensity = scan.MassSpectrum.YArray[i]; if (!alreadyClaimedMzs.Contains(ClassExtensions.RoundedDouble(mz).Value)) { neutralExperimentalFragmentMasses.Add(new IsotopicEnvelope( new List <(double mz, double intensity)> { (mz, intensity) }, mz.ToMass(1), 1, intensity, 0, 0)); } } } return(neutralExperimentalFragmentMasses.OrderBy(p => p.monoisotopicMass).ToArray()); }
public void WriteMzmlTest() { var peptide = new Peptide("GPEAPPPALPAGAPPPCTAVTSDHLNSLLGNILR"); ChemicalFormulaModification carbamidomethylationOfCMod = new ChemicalFormulaModification("H3C2NO", "carbamidomethylation of C", ModificationSites.C); peptide.AddModification(carbamidomethylationOfCMod); DefaultMzSpectrum MS1 = createSpectrum(peptide.GetChemicalFormula(), 300, 2000, 1); DefaultMzSpectrum MS2 = createMS2spectrum(peptide.Fragment(FragmentTypes.b | FragmentTypes.y, true), 100, 1500); MsDataScan <IMzSpectrum <MzPeak> >[] Scans = new MsDataScan <IMzSpectrum <MzPeak> > [2]; Scans[0] = new MsDataScan <IMzSpectrum <MzPeak> >(1, MS1.newSpectrumApplyFunctionToX(b => b + 0.000001 * b + 0.000001), "spectrum 1", 1, false, Polarity.Positive, 1.0, new MzRange(300, 2000), "FTMS first spectrum", MZAnalyzerType.Unknown, 1, MS1.SumOfAllY); Scans[1] = new MsDataScan <IMzSpectrum <MzPeak> >(2, MS2.newSpectrumApplyFunctionToX(b => b + 0.00001 * b + 0.00001), "spectrum 2", 2, false, Polarity.Positive, 2.0, new MzRange(100, 1500), "FTMS second spectrum", MZAnalyzerType.Unknown, 1, MS2.SumOfAllY, "spectrum 1", 1134.26091302033, 3, 0.141146966879759, 1134.3, 1, DissociationType.Unknown, 1, 0.141146966879759, 1134.26091302033); var myMsDataFile = new FakeMsDataFile(@"myFakeFile.mzML", Scans); MzmlMethods.CreateAndWriteMyIndexedMZmlwithCalibratedSpectra(myMsDataFile, Path.Combine(Path.GetDirectoryName(myMsDataFile.FilePath), Path.GetFileNameWithoutExtension(myMsDataFile.FilePath)) + ".mzML"); Mzml okay = new Mzml(@"myFakeFile.mzML"); okay.Open(); okay.GetScan(2); Assert.AreEqual(1, okay.GetSpectrumNumber(1)); Assert.AreEqual(2, okay.GetSpectrumNumber(2)); }
public static void XcorrTestBorrowedFromMM() { double[] mzs = new double[] { 130.0499, 148.0604, 199.1077, 209.0921, 227.1026, 245.0768, 263.0874, 296.1605, 306.1448, 324.1554, 358.1609, 376.1714, 397.2082, 407.1925, 425.2031, 459.2086, 477.2191, 510.2922, 520.2766, 538.2871, 556.2613, 574.2719, 625.3192, 635.3035, 653.3141, 685.3039, 703.3145, 782.3567, 800.3672 }; double[] intensities = new double[] { 20, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }; double precursorMass = 799.359968; var ms2 = new MzSpectrum(mzs, intensities, false); double rt = 1; int precursorZ = 1; var myScan = new MsDataScan(ms2, 1, 2, true, Polarity.Positive, rt + 0.01, new MzLibUtil.MzRange(0, 10000), "ff", MZAnalyzerType.Unknown, 1000, 1, null, "scan=2", precursorMass.ToMz(precursorZ), precursorZ, 1, precursorMass.ToMz(precursorZ), 1.0, DissociationType.HCD, 1, precursorMass.ToMz(precursorZ)); ms2.XCorrPrePreprocessing(0, 1969, precursorMass.ToMz(1)); List <double> X = new List <double>() { 130.07, 148.08, 199.1, 209.11, 227.12, 245.12, 263.13, 296.15, 306.16, 324.16, 358.18, 376.19, 397.2, 407.21, 425.22, 459.23, 477.24, 510.26, 520.26, 538.27, 556.28, 574.29, 625.32, 635.32, 653.33, 685.35, 703.36, 782.4 }; List <double> Y = new List <double>() { 49.10, 34.13, 47.78, 48.11, 48.01, 47.68, 47.35, 47.68, 47.68, 47.68, 47.35, 47.68, 47.68, 47.68, 47.68, 47.68, 47.68, 47.68, 47.68, 48.01, 48.01, 47.68, 48.01, 48.01, 48.34, 48.34, 48.68, 49.67, 49.67 }; for (int i = 0; i < X.Count; i++) { Assert.AreEqual(X[i], Math.Round(ms2.XArray[i], 2)); Assert.AreEqual(Y[i], Math.Round(ms2.YArray[i], 2)); } }
public TestDataFile(PeptideWithSetModifications pepWithSetMods) : base(2, new SourceFile(@"no nativeID format", "mzML format", null, "SHA-1", @"C:\fake.mzML", null)) { var mz1 = new double[] { pepWithSetMods.MonoisotopicMass.ToMz(2), (pepWithSetMods.MonoisotopicMass + Constants.C13MinusC12).ToMz(2), (pepWithSetMods.MonoisotopicMass + 2 * Constants.C13MinusC12).ToMz(2) }; var intensities1 = new double[] { 1, 1, 1 }; var MassSpectrum1 = new MzSpectrum(mz1, intensities1, false); var ScansHere = new List <MsDataScan> { new MsDataScan(MassSpectrum1, 1, 1, true, Polarity.Positive, 1, new MzLibUtil.MzRange(0, 10000), "ff", MZAnalyzerType.Unknown, 1000, 1, null, "scan=1") }; List <double> mz2 = new List <double>(); List <double> intensities2 = new List <double>(); foreach (var aok in pepWithSetMods.Fragment(DissociationType.HCD, FragmentationTerminus.Both)) { mz2.Add(aok.NeutralMass.ToMz(1)); mz2.Add((aok.NeutralMass + Constants.C13MinusC12).ToMz(1)); intensities2.Add(1); intensities2.Add(1); } var MassSpectrum2 = new MzSpectrum(mz2.OrderBy(b => b).ToArray(), intensities2.ToArray(), false); var scan2 = new MsDataScan(MassSpectrum2, 2, 2, true, Polarity.Positive, 2, new MzLibUtil.MzRange(0, 10000), "df", MZAnalyzerType.Orbitrap, 234734, 1, null, "scan=2", pepWithSetMods.MonoisotopicMass.ToMz(2), 2, 1, pepWithSetMods.MonoisotopicMass.ToMz(2), 2, DissociationType.HCD, 1, pepWithSetMods.MonoisotopicMass.ToMz(2)); scan2.ComputeSelectedPeakIntensity(MassSpectrum1); scan2.ComputeMonoisotopicPeakIntensity(MassSpectrum1); ScansHere.Add(scan2); Scans = ScansHere.ToArray(); }
public TestDataFile(PeptideWithSetModifications pepWithSetMods, string v) : base(2, new SourceFile(null, null, null, null, null)) { if (v.Equals("quadratic")) { // Add three ms1 peaks with charge 2, exact var MassSpectrum1 = new MzSpectrum(new double[] { pepWithSetMods.MonoisotopicMass.ToMz(2), (pepWithSetMods.MonoisotopicMass + Constants.C13MinusC12).ToMz(2), (pepWithSetMods.MonoisotopicMass + 2 * Constants.C13MinusC12).ToMz(2) }, new double[] { 1, 1, 1 }, false); List <double> mz2 = new List <double>(); List <double> intensities2 = new List <double>(); foreach (var aok in pepWithSetMods.Fragment(DissociationType.HCD, FragmentationTerminus.Both)) { var t1 = aok.NeutralMass.ToMz(1); var c = 0.0000001; mz2.Add(t1 + c * Math.Pow(t1, 2)); var t2 = (aok.NeutralMass + Constants.C13MinusC12).ToMz(1); mz2.Add(t2 + c * Math.Pow(t2, 2)); intensities2.Add(1); intensities2.Add(1); } var MassSpectrum2 = new MzSpectrum(mz2.OrderBy(b => b).ToArray(), intensities2.ToArray(), false); var scan2 = new MsDataScan(MassSpectrum2, 2, 2, true, Polarity.Positive, 2, new MzLibUtil.MzRange(0, 10000), "df", MZAnalyzerType.Orbitrap, 234734, 1, null, "scan=2", pepWithSetMods.MonoisotopicMass.ToMz(2), 2, 1, pepWithSetMods.MonoisotopicMass.ToMz(2), 2, DissociationType.HCD, 1, pepWithSetMods.MonoisotopicMass.ToMz(2)); scan2.ComputeSelectedPeakIntensity(MassSpectrum1); scan2.ComputeMonoisotopicPeakIntensity(MassSpectrum1); var ScansHere = new List <MsDataScan> { new MsDataScan(MassSpectrum1, 1, 1, true, Polarity.Positive, 1, new MzLibUtil.MzRange(0, 10000), "ff", MZAnalyzerType.Unknown, 1000, 1, null, "scan=1"), scan2 }; Scans = ScansHere.ToArray(); } }
public TestDataFile(PeptideWithSetModifications pepWithSetMods, int charge, double intensity, double rt) : base(2, new SourceFile(null, null, null, null, null)) { var mz1 = new double[] { pepWithSetMods.MonoisotopicMass.ToMz(charge), (pepWithSetMods.MonoisotopicMass + 1.003).ToMz(charge), (pepWithSetMods.MonoisotopicMass + 2.005).ToMz(charge) }; var intensities1 = new double[] { intensity, intensity * 10, intensity / 10 }; var MassSpectrum1 = new MzSpectrum(mz1, intensities1, false); var ScansHere = new List <MsDataScan> { new MsDataScan(MassSpectrum1, 1, 1, true, Polarity.Positive, rt, new MzLibUtil.MzRange(0, 10000), "ff", MZAnalyzerType.Unknown, 1000, 1, null, "scan=1") }; List <double> mz2 = new List <double>(); List <double> intensities2 = new List <double>(); foreach (var aok in pepWithSetMods.Fragment(DissociationType.HCD, FragmentationTerminus.Both)) { mz2.Add(aok.NeutralMass.ToMz(1)); mz2.Add((aok.NeutralMass + 1.003).ToMz(1)); intensities2.Add(intensity); intensities2.Add(intensity); } var MassSpectrum2 = new MzSpectrum(mz2.OrderBy(b => b).ToArray(), intensities2.ToArray(), false); var scan2 = new MsDataScan(MassSpectrum2, 2, 2, true, Polarity.Positive, rt + 0.01, new MzLibUtil.MzRange(0, 10000), "df", MZAnalyzerType.Orbitrap, 234734, 1, null, "scan=2", pepWithSetMods.MonoisotopicMass.ToMz(2), 2, 1, pepWithSetMods.MonoisotopicMass.ToMz(2), 2, DissociationType.HCD, 1, pepWithSetMods.MonoisotopicMass.ToMz(2)); scan2.ComputeSelectedPeakIntensity(MassSpectrum1); scan2.ComputeMonoisotopicPeakIntensity(MassSpectrum1); ScansHere.Add(scan2); Scans = ScansHere.ToArray(); }
public static void TestAllNaN() { IDictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> >(); var prot = new Protein("XMMM", null, null, null, mods); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 1); var thePep = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First(); var frags = new List <Product>(); thePep.Fragment(DissociationType.HCD, FragmentationTerminus.Both, frags); var massArray = frags.Select(p => p.NeutralMass).ToArray(); Array.Sort(massArray); double[] intensities = new double[] { 1, 1, 1, 1 }; double[] mz = new double[] { 1, 2, 3, 4 }; MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 0, 0, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters(productMassTolerance: new PpmTolerance(5), scoreCutoff: 1, digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: int.MaxValue, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)); ClassicSearchEngine cse = new ClassicSearchEngine(globalPsms, arrayOfSortedMS2Scans, new List <Modification>(), new List <Modification>(), null, null, null, new List <Protein> { prot }, new OpenSearchMode(), CommonParameters, null, new List <string>()); cse.Run(); Assert.IsNull(globalPsms[0]); }
public PeptideSpectrumMatchPlot(OxyPlot.Wpf.PlotView plotView, Canvas sequenceDrawingCanvas, PsmFromTsv psm, MsDataScan scan, List <MatchedFragmentIon> matchedFragmentIons, bool annotateProperties = true, LibrarySpectrum librarySpectrum = null) : base(plotView) { Model.Title = string.Empty; Model.Subtitle = string.Empty; SpectrumMatch = psm; Scan = scan; SequenceDrawingCanvas = sequenceDrawingCanvas; SequenceDrawingCanvas.Height = 60; sequenceDrawingCanvas.Width = 600; ClearCanvas(SequenceDrawingCanvas); DrawSpectrum(); AnnotateBaseSequence(psm.BaseSeq, psm.FullSequence, 10, matchedFragmentIons); AnnotateMatchedIons(isBetaPeptide: false, matchedFragmentIons); if (annotateProperties) { AnnotateProperties(); } ZoomAxes(matchedFragmentIons); if (librarySpectrum != null) { AnnotateLibraryIons(isBetaPeptide: false, librarySpectrum.MatchedFragmentIons); } RefreshChart(); }
public static void TestVeryCloseExperimentalsModern() { IDictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> >(); ModificationMotif.TryGetMotif("M", out ModificationMotif motif); var prot = new Protein("MMMM", null, null, null, mods); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 1); var thePep = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First(); var frags = new List <Product>(); thePep.Fragment(DissociationType.HCD, FragmentationTerminus.Both, frags); var massArray = frags.Select(p => p.NeutralMass).ToArray(); Array.Sort(massArray); double[] intensities = new double[] { 1, 1, 1, 1 }; double[] mz = new double[] { 1, 2, massArray[4].ToMz(1), massArray[4].ToMz(1) + 1e-9 }; MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false); MsDataScan scan = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null); PeptideSpectralMatch[] globalPsms = new PeptideSpectralMatch[1]; Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 600, 1, null, new CommonParameters()) }; CommonParameters CommonParameters = new CommonParameters(productMassTolerance: new PpmTolerance(5), scoreCutoff: 1, digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: int.MaxValue, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)); var indexEngine = new IndexingEngine(new List <Protein> { prot }, new List <Modification>(), new List <Modification>(), null, null, null, 1, DecoyType.Reverse, CommonParameters, null, 30000, false, new List <FileInfo>(), TargetContaminantAmbiguity.RemoveContaminant, new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); var cse = new ModernSearchEngine(globalPsms, arrayOfSortedMS2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, null, new OpenSearchMode(), 0, new List <string>()); cse.Run(); Assert.Less(globalPsms[0].Score, 2); Assert.Greater(globalPsms[0].Score, 1); }
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); }
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()); }
private PlotModel DrawPdf(MsDataScan msDataScan, PropertyInfo[] properties, PsmFromTsv psm, bool redraw) { if (redraw) { this.Model = Draw(msDataScan, psm); } var y = Model.DefaultYAxis.ActualMaximum - Model.DefaultYAxis.ActualMaximum * 0.03; var x = Model.DefaultXAxis.ActualMaximum - Model.DefaultXAxis.ActualMaximum * 0.01; var diff = (y - (Model.DefaultYAxis.ActualMaximum * 0.1)) / properties.Length; // properties to include string[] propertiesToWrite = { "Filename", "PrecursorCharge", "PrecursorMass", "PeptideMonoMass", "MassDiffDa", "MassDiffPpm", "Score", "DeltaScore", "ProteinAccession", "ProteinName", "GeneName", "DecoyContamTarget", "QValue", "QValueNotch" }; var propertiesList = properties.Where(p => propertiesToWrite.Contains(p.Name)).OrderBy(p => Array.IndexOf(propertiesToWrite, p.Name)).ToList(); var displayedProperties = propertiesList.Where(p => p.GetValue(psm) != null); // only display non-null properties foreach (PropertyInfo property in displayedProperties) { // trim property values > 50 characters var val = "" + property.GetValue(psm); if (val.Length > 50) { val = val.Substring(0, 50) + "..."; } var propertyAnnotation = new TextAnnotation { Text = property.Name + ": " + val, TextPosition = new DataPoint(x, y), FontSize = 9, StrokeThickness = 0, TextHorizontalAlignment = HorizontalAlignment.Right }; y -= diff; Model.Annotations.Add(propertyAnnotation); } return(Model); }
public static void TestCoIsolation() { List <DigestionMotif> motifs = new List <DigestionMotif> { new DigestionMotif("K", null, 1, null) }; Protease protease = new Protease("CustProtease", CleavageSpecificity.Full, null, null, motifs); ProteaseDictionary.Dictionary.Add(protease.Name, protease); CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, deconvolutionIntensityRatio: 50, digestionParams: new DigestionParams(protease.Name, minPeptideLength: 1)); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("MNNNKNDNK", null) }; var searchModes = new SinglePpmAroundZeroSearchMode(5); Proteomics.AminoAcidPolymer.Peptide pep1 = new Proteomics.AminoAcidPolymer.Peptide("NNNK"); Proteomics.AminoAcidPolymer.Peptide pep2 = new Proteomics.AminoAcidPolymer.Peptide("NDNK"); var dist1 = IsotopicDistribution.GetDistribution(pep1.GetChemicalFormula(), 0.1, 0.01); var dist2 = IsotopicDistribution.GetDistribution(pep2.GetChemicalFormula(), 0.1, 0.01); MsDataScan[] Scans = new MsDataScan[2]; double[] ms1intensities = new double[] { 0.8, 0.8, 0.2, 0.02, 0.2, 0.02 }; double[] ms1mzs = dist1.Masses.Concat(dist2.Masses).OrderBy(b => b).Select(b => b.ToMz(1)).ToArray(); double selectedIonMz = ms1mzs[1]; MzSpectrum MS1 = new MzSpectrum(ms1mzs, ms1intensities, false); Scans[0] = new MsDataScan(MS1, 1, 1, false, Polarity.Positive, 1.0, new MzRange(300, 2000), "first spectrum", MZAnalyzerType.Unknown, MS1.SumOfAllY, null, null, "scan=1"); double[] ms2intensities = new double[] { 1, 1, 1, 1, 1 }; double[] ms2mzs = new double[] { 146.106.ToMz(1), 228.086.ToMz(1), 229.07.ToMz(1), 260.148.ToMz(1), 342.129.ToMz(1) }; MzSpectrum MS2 = new MzSpectrum(ms2mzs, ms2intensities, false); double isolationMZ = selectedIonMz; Scans[1] = new MsDataScan(MS2, 2, 2, false, Polarity.Positive, 2.0, new MzRange(100, 1500), "second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, null, null, "scan=2", selectedIonMz, null, null, isolationMZ, 2.5, DissociationType.HCD, 1, null); var myMsDataFile = new MsDataFile(Scans, null); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters(deconvolutionIntensityRatio: 50)).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchModes, CommonParameters, new List <string>()).Run(); // Two matches for this single scan! Corresponding to two co-isolated masses Assert.AreEqual(2, allPsmsArray.Length); Assert.IsTrue(allPsmsArray[0].Score > 1); Assert.AreEqual(2, allPsmsArray[0].ScanNumber); Assert.AreEqual("NNNK", allPsmsArray[0].BaseSequence); Assert.AreEqual("NDNK", allPsmsArray[1].BaseSequence); }
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 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 Ms2ScanWithSpecificMass(MsDataScan mzLibScan, double precursorMonoisotopicPeakMz, int precursorCharge, string fullFilePath) { PrecursorMonoisotopicPeakMz = precursorMonoisotopicPeakMz; PrecursorCharge = precursorCharge; PrecursorMass = PrecursorMonoisotopicPeakMz.ToMass(precursorCharge); FullFilePath = fullFilePath; TheScan = mzLibScan; }
public static void TestPeakSplittingRight() { string fileToWrite = "myMzml.mzML"; string peptide = "PEPTIDE"; double intensity = 1e6; Loaders.LoadElements(Path.Combine(TestContext.CurrentContext.TestDirectory, @"elements.dat")); // generate mzml file // 1 MS1 scan per peptide MsDataScan[] scans = new MsDataScan[10]; double[] intensityMultipliers = { 1, 3, 5, 10, 5, 3, 1, 1, 3, 1 }; for (int s = 0; s < scans.Length; s++) { ChemicalFormula cf = new Proteomics.AminoAcidPolymer.Peptide(peptide).GetChemicalFormula(); IsotopicDistribution dist = IsotopicDistribution.GetDistribution(cf, 0.125, 1e-8); double[] mz = dist.Masses.Select(v => v.ToMz(1)).ToArray(); double[] intensities = dist.Intensities.Select(v => v * intensity * intensityMultipliers[s]).ToArray(); // add the scan scans[s] = new MsDataScan(massSpectrum: new MzSpectrum(mz, intensities, false), oneBasedScanNumber: s + 1, msnOrder: 1, isCentroid: true, polarity: Polarity.Positive, retentionTime: 1.0 + s / 10.0, scanWindowRange: new MzRange(400, 1600), scanFilter: "f", mzAnalyzer: MZAnalyzerType.Orbitrap, totalIonCurrent: intensities.Sum(), injectionTime: 1.0, noiseData: null, nativeId: "scan=" + (s + 1)); } // write the .mzML IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(new FakeMsDataFile(scans), Path.Combine(TestContext.CurrentContext.TestDirectory, fileToWrite), false); // set up spectra file info SpectraFileInfo file1 = new SpectraFileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, fileToWrite), "", 0, 0, 0); // create some PSMs var pg = new ProteinGroup("MyProtein", "gene", "org"); Identification id1 = new Identification(file1, peptide, peptide, new Proteomics.AminoAcidPolymer.Peptide(peptide).MonoisotopicMass, 1.3 + 0.001, 1, new List <ProteinGroup> { pg }); // create the FlashLFQ engine FlashLFQEngine engine = new FlashLFQEngine(new List <Identification> { id1 }); // run the engine var results = engine.Run(); ChromatographicPeak peak = results.Peaks.First().Value.First(); Assert.That(peak.Apex.RetentionTime == 1.3); Assert.That(peak.SplitRT == 1.6); Assert.That(!peak.IsotopicEnvelopes.Any(p => p.RetentionTime > 1.6)); Assert.That(peak.IsotopicEnvelopes.Count == 6); }
public static void TestDynamicRaw(string fileName) { string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", fileName); ThermoRawFileReader staticRaw = ThermoRawFileReader.LoadAllStaticData(filePath); ThermoDynamicData dynamicRaw = new ThermoDynamicData(filePath); foreach (MsDataScan staticScan in staticRaw.GetAllScansList()) { MsDataScan dynamicScan = dynamicRaw.GetOneBasedScanFromDynamicConnection(staticScan.OneBasedScanNumber); Assert.That(dynamicScan.OneBasedScanNumber == staticScan.OneBasedScanNumber); Assert.That(dynamicScan.MsnOrder == staticScan.MsnOrder); Assert.That(dynamicScan.RetentionTime == staticScan.RetentionTime); Assert.That(dynamicScan.Polarity == staticScan.Polarity); Assert.That(dynamicScan.ScanWindowRange.Minimum == staticScan.ScanWindowRange.Minimum); Assert.That(dynamicScan.ScanWindowRange.Maximum == staticScan.ScanWindowRange.Maximum); Assert.That(dynamicScan.ScanFilter == staticScan.ScanFilter); Assert.That(dynamicScan.NativeId == staticScan.NativeId); Assert.That(dynamicScan.IsCentroid == staticScan.IsCentroid); Assert.That(dynamicScan.IsCentroid == staticScan.IsCentroid); Assert.That(dynamicScan.InjectionTime == staticScan.InjectionTime); Assert.That(dynamicScan.NoiseData == staticScan.NoiseData); Assert.That(dynamicScan.IsolationMz == staticScan.IsolationMz); Assert.That(dynamicScan.SelectedIonChargeStateGuess == staticScan.SelectedIonChargeStateGuess); Assert.That(dynamicScan.SelectedIonIntensity == staticScan.SelectedIonIntensity); Assert.That(dynamicScan.SelectedIonMZ == staticScan.SelectedIonMZ); Assert.That(dynamicScan.DissociationType == staticScan.DissociationType); Assert.That(dynamicScan.IsolationWidth == staticScan.IsolationWidth); Assert.That(dynamicScan.OneBasedPrecursorScanNumber == staticScan.OneBasedPrecursorScanNumber); Assert.That(dynamicScan.SelectedIonMonoisotopicGuessIntensity == staticScan.SelectedIonMonoisotopicGuessIntensity); Assert.That(dynamicScan.SelectedIonMonoisotopicGuessMz == staticScan.SelectedIonMonoisotopicGuessMz); if (dynamicScan.IsolationRange != null || staticScan.IsolationRange != null) { Assert.That(dynamicScan.IsolationRange.Minimum == staticScan.IsolationRange.Minimum); Assert.That(dynamicScan.IsolationRange.Maximum == staticScan.IsolationRange.Maximum); } Assert.That(dynamicScan.MassSpectrum.XArray.Length == staticScan.MassSpectrum.XArray.Length); Assert.That(dynamicScan.MassSpectrum.YArray.Length == staticScan.MassSpectrum.YArray.Length); for (int i = 0; i < staticScan.MassSpectrum.XArray.Length; i++) { double staticMz = staticScan.MassSpectrum.XArray[i]; double staticIntensity = staticScan.MassSpectrum.YArray[i]; double dynamicMz = dynamicScan.MassSpectrum.XArray[i]; double dynamicIntensity = dynamicScan.MassSpectrum.YArray[i]; Assert.That(dynamicMz == staticMz); Assert.That(dynamicIntensity == staticIntensity); } } }
public void DataFileTest() { MsDataScan theSpectrum = new MsDataScan(_mzSpectrumA, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 1000), "fake scan filter", MZAnalyzerType.Unknown, _mzSpectrumA.SumOfAllY, 1, null, "scan=1"); MsDataScan[] theList = new MsDataScan[1]; theList[0] = theSpectrum; FakeMsDataFile thefile = new FakeMsDataFile(theList); var theOneBasedScan = thefile.GetOneBasedScan(1); Assert.AreEqual("Scan #1", theOneBasedScan.ToString()); Assert.AreEqual(15, theOneBasedScan.MassSpectrum.Size); Assert.AreEqual(15, theOneBasedScan.MassSpectrum.Size); Assert.AreEqual(1, thefile.NumSpectra); Assert.AreEqual(1, thefile.NumSpectra); Assert.IsTrue(thefile.GetOneBasedScan(1).IsCentroid); foreach (var ok in thefile) { Assert.AreEqual(300, ok.ScanWindowRange.Minimum, 1e-9); Assert.AreEqual(1000, ok.ScanWindowRange.Maximum, 1e-9); } int ok1 = 0; foreach (var i in thefile.GetMsScansInTimeRange(0, 2)) { ok1 += 1; } Assert.AreEqual(1, ok1); int ok2 = 0; foreach (var i in thefile.GetMsScansInTimeRange(2, 4)) { ok2 += 1; } Assert.AreEqual(0, ok2); int ok3 = 0; foreach (var i in thefile.GetMsScansInTimeRange(-4, -2)) { ok3 += 1; } Assert.AreEqual(0, ok3); }
// Grouping the scans in the file /// <summary> /// Given a file, reads through the scans and groups them into SetOfScans objects, each containing one or more full ms1 scans and the corresponding boxcar scans. /// Discards all ms2 scans (although the SetOfScans object also has a list to hold these, if you wanted to include them). /// This method includes many comments which can be uncommented for debugging to write information to the console. /// </summary> /// <param name="file"></param> /// <returns></returns> list of SetOfScans objects, each SetOfScans contains one full ms1 scan and its corresponding boxcar scans. public static List <SetOfScans> SeparateScans(MsDataFile file) { List <SetOfScans> sorted = new List <SetOfScans>(); // Get only the ms1 and boxcar scans (discard ms2): var ms1scans = file.GetMS1Scans().ToList(); //Console.WriteLine("Number of ms1scans (full ms and boxcar method): " + ms1scans.Count); // Initialize variables: MsDataScan current = ms1scans.ElementAt(0); string currentFilter = current.ScanFilter; //Console.WriteLine("first scan filter: " + currentFilter); MsDataScan next = ms1scans.ElementAt(1); string nextFilter = next.ScanFilter; //Console.WriteLine("next scan filter: " + nextFilter); SetOfScans set = new SetOfScans(); // Loop through to group the scans. This should create as many SetOfScans objects as there are boxes (specified in the setup of the scan). for (int i = 0; i < ms1scans.Count; i++) { if (current.ScanFilter.Contains("Full ms ")) // the space is important! Otherwise this will be recorded as a boxcar scan instead of an ms1 { set.AddToMs1Scans(current); // Console.WriteLine("Found full ms, added to set"); } // if this boxcar scan has boxcar scans after it else if (current.ScanFilter.Contains("Full msx ms") && next.ScanFilter.Contains("Full msx ms")) { set.AddToBoxcarScans(current); //Console.WriteLine("Found msx ms, added to set"); } // if this boxcar scan is the last boxcar scan in the set, start a new set else if (current.ScanFilter.Contains("Full msx ms") && !next.ScanFilter.Contains("Full msx ms")) { set.AddToBoxcarScans(current); //Console.WriteLine("Found last msx ms in set, added to set"); sorted.Add(set); //Console.WriteLine("Added set to Sorted"); set = new SetOfScans(); } current = next; currentFilter = current.ScanFilter; if ((i + 1) < ms1scans.Count) // if there is a next MsDataScan in the file { next = ms1scans.ElementAt(i + 1); nextFilter = next.ScanFilter; } } return(sorted); }
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 IEnumerable <DeconvolutedEnvelope> Deconvolute(MsDataScan scan) { var deconvolutedEnvs = Deconvolute(scan.MassSpectrum, scan.MassSpectrum.Range).ToList(); foreach (var env in deconvolutedEnvs) { env.RetentionTime = scan.RetentionTime; env.OneBasedScan = scan.OneBasedScanNumber; env.TotalScanDeconvolutedIntensity = deconvolutedEnvs.Sum(p => p.Peaks.Sum(v => v.ExperimentalIntensity)); yield return(env); } }