public static void DifferentAnalyzersTest() { IMzmlScan[] scans = new IMzmlScan[2]; double[] intensities1 = new double[] { 1 }; double[] mz1 = new double[] { 50 }; MzmlMzSpectrum massSpec1 = new MzmlMzSpectrum(mz1, intensities1, false); scans[0] = new MzmlScan(1, massSpec1, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "1"); double[] intensities2 = new double[] { 1 }; double[] mz2 = new double[] { 30 }; MzmlMzSpectrum massSpec2 = new MzmlMzSpectrum(mz2, intensities2, false); scans[1] = new MzmlScanWithPrecursor(2, massSpec2, 2, true, Polarity.Positive, 2, new MzRange(1, 100), "f", MZAnalyzerType.IonTrap3D, massSpec2.SumOfAllY, 50, null, null, 50, 1, DissociationType.CID, 1, null, null, "2"); FakeMsDataFile f = new FakeMsDataFile(scans); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(f, Path.Combine(TestContext.CurrentContext.TestDirectory, "asdfefsf.mzML"), false); Mzml ok = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, "asdfefsf.mzML")); Assert.AreEqual(MZAnalyzerType.Orbitrap, ok.First().MzAnalyzer); Assert.AreEqual(MZAnalyzerType.IonTrap3D, ok.Last().MzAnalyzer); }
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 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); }
public static void WriteEmptyScan() { double[] intensities1 = new double[] { }; double[] mz1 = new double[] { }; MzmlMzSpectrum massSpec1 = new MzmlMzSpectrum(mz1, intensities1, false); IMzmlScan[] scans = new IMzmlScan[] { new MzmlScan(1, massSpec1, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "1") }; FakeMsDataFile f = new FakeMsDataFile(scans); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(f, Path.Combine(TestContext.CurrentContext.TestDirectory, "mzmlWithEmptyScan.mzML"), false); Mzml ok = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, "mzmlWithEmptyScan.mzML")); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(ok, Path.Combine(TestContext.CurrentContext.TestDirectory, "mzmlWithEmptyScan2.mzML"), false); }
public void WriteMzmlTest() { var peptide = new Peptide("GPEAPPPALPAGAPPPCTAVTSDHLNSLLGNILR"); OldSchoolChemicalFormulaModification carbamidomethylationOfCMod = new OldSchoolChemicalFormulaModification(ChemicalFormula.ParseFormula("H3C2NO"), "carbamidomethylation of C", ModificationSites.C); peptide.AddModification(carbamidomethylationOfCMod); MzmlMzSpectrum MS1 = CreateSpectrum(peptide.GetChemicalFormula(), 300, 2000, 1); MzmlMzSpectrum MS2 = CreateMS2spectrum(peptide.Fragment(FragmentTypes.b | FragmentTypes.y, true), 100, 1500); IMzmlScan[] Scans = new IMzmlScan[2]; Scans[0] = new MzmlScan(1, MS1, 1, true, Polarity.Positive, 1.0, new MzRange(300, 2000), " first spectrum", MZAnalyzerType.Unknown, MS1.SumOfAllY, 1, "scan=1"); Scans[1] = new MzmlScanWithPrecursor(2, MS2, 2, true, Polarity.Positive, 2.0, new MzRange(100, 1500), " second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, 1134.26091302033, 3, 0.141146966879759, 1134.3, 1, DissociationType.Unknown, 1, 1134.26091302033, 1, "scan=2"); var myMsDataFile = new FakeMsDataFile(Scans); var oldFirstValue = myMsDataFile.GetOneBasedScan(1).MassSpectrum.FirstX; var secondScan = myMsDataFile.GetOneBasedScan(2) as IMsDataScanWithPrecursor <MzmlMzSpectrum>; Assert.AreEqual(1, secondScan.IsolationRange.Maximum - secondScan.IsolationRange.Minimum); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, "argh.mzML", false); Mzml okay = Mzml.LoadAllStaticData(@"argh.mzML"); okay.GetOneBasedScan(2); Assert.AreEqual(1, okay.GetClosestOneBasedSpectrumNumber(1)); Assert.AreEqual(2, okay.GetClosestOneBasedSpectrumNumber(2)); var newFirstValue = okay.GetOneBasedScan(1).MassSpectrum.FirstX; Assert.AreEqual(oldFirstValue.Value, newFirstValue.Value, 1e-9); var secondScan2 = okay.GetOneBasedScan(2) as IMsDataScanWithPrecursor <MzmlMzSpectrum>; Assert.AreEqual(1, secondScan2.IsolationRange.Maximum - secondScan2.IsolationRange.Minimum); secondScan2.MassSpectrum.ReplaceXbyApplyingFunction((a) => 44); Assert.AreEqual(44, secondScan2.MassSpectrum.LastX); }
public void TestCoIsolation() { Peptide pep1 = new Peptide("AAAAAA"); Peptide pep2 = new Peptide("AAA[H]AAA"); 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, null); // Horrible fragmentation, but we don't care about this! double[] ms2intensities = new double[] { 1000 }; double[] ms2mzs = new double[] { 1000 }; 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, null, selectedIonMz, null, null, isolationMZ, 2.5, DissociationType.HCD, 1, null); var myMsDataFile = new FakeMsDataFile(Scans); var cool = myMsDataFile.GetAllScansList().Last(); int maxAssumedChargeState = 1; Tolerance massTolerance = Tolerance.ParseToleranceString("10 PPM"); var isolatedMasses = cool.GetIsolatedMassesAndCharges(myMsDataFile.GetOneBasedScan(cool.OneBasedPrecursorScanNumber.Value).MassSpectrum, 1, maxAssumedChargeState, 10, 5).ToList(); Assert.AreEqual(2, isolatedMasses.Count); Assert.AreEqual(2, isolatedMasses.Count(b => b.charge == 1)); Assert.AreEqual(pep1.MonoisotopicMass, isolatedMasses.Select(b => b.peaks.First().Item1.ToMass(b.charge)).Min(), 1e-9); Assert.AreEqual(pep2.MonoisotopicMass, isolatedMasses.Select(b => b.peaks.First().Item1.ToMass(b.charge)).Max(), 1e-9); Assert.AreEqual(pep1.MonoisotopicMass, isolatedMasses.Select(b => b.monoisotopicMass.ToMz(b.charge).ToMass(b.charge)).Min(), 1e-9); Assert.AreEqual(pep2.MonoisotopicMass, isolatedMasses.Select(b => b.monoisotopicMass.ToMz(b.charge).ToMass(b.charge)).Max(), 1e-9); }
public static void AnotherMzMLtest() { IMzmlScan[] scans = new IMzmlScan[4]; double[] intensities1 = new double[] { 1 }; double[] mz1 = new double[] { 50 }; MzmlMzSpectrum massSpec1 = new MzmlMzSpectrum(mz1, intensities1, false); scans[0] = new MzmlScan(1, massSpec1, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "1"); double[] intensities2 = new double[] { 1 }; double[] mz2 = new double[] { 30 }; MzmlMzSpectrum massSpec2 = new MzmlMzSpectrum(mz2, intensities2, false); scans[1] = new MzmlScanWithPrecursor(2, massSpec2, 2, true, Polarity.Positive, 2, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec2.SumOfAllY, 50, null, null, 50, 1, DissociationType.CID, 1, null, null, "2"); double[] intensities3 = new double[] { 1 }; double[] mz3 = new double[] { 50 }; MzmlMzSpectrum massSpec3 = new MzmlMzSpectrum(mz3, intensities3, false); scans[2] = new MzmlScan(3, massSpec3, 1, true, Polarity.Positive, 1, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec1.SumOfAllY, null, "3"); double[] intensities4 = new double[] { 1 }; double[] mz4 = new double[] { 30 }; MzmlMzSpectrum massSpec4 = new MzmlMzSpectrum(mz4, intensities4, false); scans[3] = new MzmlScanWithPrecursor(4, massSpec4, 2, true, Polarity.Positive, 2, new MzRange(1, 100), "f", MZAnalyzerType.Orbitrap, massSpec2.SumOfAllY, 50, null, null, 50, 1, DissociationType.CID, 3, null, null, "4"); FakeMsDataFile f = new FakeMsDataFile(scans); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(f, Path.Combine(TestContext.CurrentContext.TestDirectory, "what.mzML"), false); Mzml ok = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, "what.mzML")); var scanWithPrecursor = ok.Last(b => b is IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >; Assert.AreEqual(3, scanWithPrecursor.OneBasedPrecursorScanNumber); }
public void Setup() { Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory; UsefulProteomicsDatabases.Loaders.LoadElements(); double[] mz = { 328.73795, 329.23935, 447.73849, 448.23987, 482.23792, 482.57089, 482.90393, 500.95358, 501.28732, 501.62131, 611.99377, 612.32806, 612.66187, 722.85217, 723.35345 }; double[] intensities = { 81007096.0, 28604418.0, 78353512.0, 39291696.0, 122781408.0, 94147520.0, 44238040.0, 71198680.0, 54184096.0, 21975364.0, 44514172.0, 43061628.0, 23599424.0, 56022696.0, 41019144.0 }; _mzSpectrumA = new MzSpectrum(mz, intensities, false); var peptide = new Peptide("KQEEQMETEQQNKDEGK"); MzSpectrum MS1 = CreateSpectrum(peptide.GetChemicalFormula(), 300, 2000, 1); MzSpectrum MS2 = CreateMS2spectrum(peptide.Fragment(FragmentTypes.b | FragmentTypes.y, true), 100, 1500); MsDataScan[] Scans = new MsDataScan[2]; Scans[0] = new MsDataScan(MS1, 1, 1, false, Polarity.Positive, 1.0, new MzRange(300, 2000), "first spectrum", MZAnalyzerType.Unknown, MS1.SumOfAllY, 1, null, "scan=1"); Scans[1] = new MsDataScan(MS2, 2, 2, false, Polarity.Positive, 2.0, new MzRange(100, 1500), "second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, 1, null, "scan=2", 693.9892, 3, .3872, 693.99, 1, DissociationType.Unknown, 1, 693.6550); myMsDataFile = new FakeMsDataFile(Scans); }
[TestCase(1081.385183, 13, 35454636, 1081.385)] //This is a lesser abundant charge state envelope at the high mz end public void TestDeconvolutionProteoformMultiChargeState(double selectedIonMz, int selectedIonChargeStateGuess, double selectedIonIntensity, double isolationMz) { MsDataScan[] Scans = new MsDataScan[1]; //txt file, not mgf, because it's an MS1. Most intense proteoform has mass of ~14037.9 Da string Ms1SpectrumPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"DataFiles\14kDaProteoformMzIntensityMs1.txt"); string[] spectrumLines = File.ReadAllLines(Ms1SpectrumPath); int mzIntensityPairsCount = spectrumLines.Length; double[] ms1mzs = new double[mzIntensityPairsCount]; double[] ms1intensities = new double[mzIntensityPairsCount]; for (int i = 0; i < mzIntensityPairsCount; i++) { string[] pair = spectrumLines[i].Split('\t'); ms1mzs[i] = Convert.ToDouble(pair[0]); ms1intensities[i] = Convert.ToDouble(pair[1]); } MzSpectrum spectrum = new MzSpectrum(ms1mzs, ms1intensities, false); Scans[0] = new MsDataScan(spectrum, 1, 1, false, Polarity.Positive, 1.0, new MzRange(495, 1617), "first spectrum", MZAnalyzerType.Unknown, spectrum.SumOfAllY, null, null, null, selectedIonMz, selectedIonChargeStateGuess, selectedIonIntensity, isolationMz, 4); var myMsDataFile = new FakeMsDataFile(Scans); MsDataScan scan = myMsDataFile.GetAllScansList()[0]; List <IsotopicEnvelope> isolatedMasses = scan.GetIsolatedMassesAndCharges(spectrum, 1, 60, 4, 3).ToList(); List <double> monoIsotopicMasses = isolatedMasses.Select(m => m.MonoisotopicMass).ToList(); //The primary monoisotopic mass should be the same regardless of which peak in which charge state was selected for isolation. //this case is interesting because other monoisotopic mass may have a sodium adduct. The unit test could be expanded to consider this. Assert.That(monoIsotopicMasses[0], Is.EqualTo(14037.926829).Within(.0005)); }
public static void TestCoIsolation() { 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, }, ConserveMemory = false, ScoreCutoff = 1, DeconvolutionIntensityRatio = 50 }; var variableModifications = new List <ModificationWithMass>(); var fixedModifications = new List <ModificationWithMass>(); var proteinList = new List <Protein> { new Protein("MNNNKNDNK", null) }; var searchModes = new SinglePpmAroundZeroSearchMode(5); Proteomics.Peptide pep1 = new Proteomics.Peptide("NNNK"); Proteomics.Peptide pep2 = new Proteomics.Peptide("NDNK"); var dist1 = IsotopicDistribution.GetDistribution(pep1.GetChemicalFormula(), 0.1, 0.01); var dist2 = IsotopicDistribution.GetDistribution(pep2.GetChemicalFormula(), 0.1, 0.01); IMzmlScan[] Scans = new IMzmlScan[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]; MzmlMzSpectrum MS1 = new MzmlMzSpectrum(ms1mzs, ms1intensities, false); Scans[0] = new MzmlScan(1, MS1, 1, false, Polarity.Positive, 1.0, new MzRange(300, 2000), "first spectrum", MZAnalyzerType.Unknown, MS1.SumOfAllY, 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) }; MzmlMzSpectrum MS2 = new MzmlMzSpectrum(ms2mzs, ms2intensities, false); double isolationMZ = selectedIonMz; Scans[1] = new MzmlScanWithPrecursor(2, MS2, 2, false, Polarity.Positive, 2.0, new MzRange(100, 1500), "second spectrum", MZAnalyzerType.Unknown, MS2.SumOfAllY, selectedIonMz, null, null, isolationMZ, 2.5, DissociationType.HCD, 1, null, null, "scan=2"); var myMsDataFile = new FakeMsDataFile(Scans); bool DoPrecursorDeconvolution = true; bool UseProvidedPrecursorInfo = true; double DeconvolutionIntensityRatio = 50; 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]; List <ProductType> lp = new List <ProductType> { ProductType.B, ProductType.Y }; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, lp, searchModes, false, CommonParameters, CommonParameters.ProductMassTolerance, 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); var ojdfkj = (SequencesToActualProteinPeptidesEngineResults) new SequencesToActualProteinPeptidesEngine(new List <PeptideSpectralMatch> { allPsmsArray[0], allPsmsArray[1] }, proteinList, fixedModifications, variableModifications, lp, new List <IDigestionParams> { CommonParameters.DigestionParams }, CommonParameters.ReportAllAmbiguity, new List <string>()).Run(); foreach (var huh in allPsmsArray) { if (huh != null) { huh.MatchToProteinLinkedPeptides(ojdfkj.CompactPeptideToProteinPeptideMatching); } } Assert.AreEqual("NNNK", allPsmsArray[0].BaseSequence); Assert.AreEqual("NDNK", allPsmsArray[1].BaseSequence); }