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 MsDataFile LoadFile(string origDataFile, int?topNpeaks, double?minRatio, bool trimMs1Peaks, bool trimMsMsPeaks, CommonParameters commonParameters) { FilteringParams filter = new FilteringParams(topNpeaks, minRatio, 1, trimMs1Peaks, trimMsMsPeaks); if (MyMsDataFiles.TryGetValue(origDataFile, out MsDataFile value) && value != null) { return(value); } // By now know that need to load this file!!! lock (FileLoadingLock) // Lock because reading is sequential { if (Path.GetExtension(origDataFile).Equals(".mzML", StringComparison.OrdinalIgnoreCase)) { MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, commonParameters.MaxThreadsToUsePerFile); } else if (Path.GetExtension(origDataFile).Equals(".mgf", StringComparison.OrdinalIgnoreCase)) { MyMsDataFiles[origDataFile] = Mgf.LoadAllStaticData(origDataFile, filter); } else { #if NETFRAMEWORK MyMsDataFiles[origDataFile] = ThermoStaticData.LoadAllStaticData(origDataFile, filter); #else Warn("No capability for reading " + origDataFile); #endif } return(MyMsDataFiles[origDataFile]); } }
public static void TestClassicSearchEngineTopDown() { CommonParameters CommonParameters = new CommonParameters( digestionParams: new DigestionParams(protease: "top-down"), scoreCutoff: 1, assumeOrphanPeaksAreZ1Fragments: false); MetaMorpheusTask.DetermineAnalyteType(CommonParameters); // test output file name (should be proteoform and not peptide) Assert.That(GlobalVariables.AnalyteType == "Proteoform"); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("MPKVYSYQEVAEHNGPENFWIIIDDKVYDVSQFKDEHPGGDEIIMDLGGQDATESFVDIGHSDEALRLLKGLYIGDVDKTSERVSVEKVSTSENQSKGSGTLVVILAILMLGVAYYLLNE", "P40312") }; var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TopDownTestData\slicedTDYeast.mzML")); var searchMode = new SinglePpmAroundZeroSearchMode(5); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null, proteinList, searchMode, CommonParameters, null, null, new List <string>()).Run(); var psm = allPsmsArray.Where(p => p != null).FirstOrDefault(); Assert.That(psm.MatchedFragmentIons.Count == 47); }
public static void testingTMTonBigScan() { Dictionary <string, MsDataFile> MyMsDataFiles = new Dictionary <string, MsDataFile>(); var origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\tmt18test.mzML"); FilteringParams filter = new FilteringParams(); MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, 1); var scans2 = MyMsDataFiles[origDataFile].GetAllScansList(); var trimmedScans = scans2.Where(m => m.MsnOrder == 3).ToList(); Protein p = new Protein("LAALNPESNTAGLDIFAK", "accession"); List <Modification> fixedModifications = new List <Modification>(); fixedModifications.AddRange(GlobalVariables.AllModsKnown); List <Modification> tmt18Mods = fixedModifications.Where(m => m.ModificationType == "Multiplex Label" && m.IdWithMotif.Contains("TMT18")).ToList(); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 1); var aPeptideWithSetModifications = p.Digest(digestionParams, tmt18Mods, new List <Modification>()).First(); var theseTheoreticalFragments = new List <Product>(); aPeptideWithSetModifications.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theseTheoreticalFragments); theseTheoreticalFragments = theseTheoreticalFragments.Where(n => n.ProductType == ProductType.D).ToList(); double ppmTolerance = 20; int roundTo = 5; List <double> diagnosticIons = new List <double>(); for (int k = 0; k < theseTheoreticalFragments.Count(); k++) { diagnosticIons.Add(Math.Round(theseTheoreticalFragments[k].NeutralMass, roundTo)); } int i = 460; do { if (i == trimmedScans.Count()) { break; } var massList = trimmedScans[i].MassSpectrum.XArray.ToList(); for (int j = 0; j < massList.Count(); j++) { massList[j] = Math.Round(massList[j], roundTo); } for (int l = 0; l < massList.Count(); l++) { for (int m = 0; m < diagnosticIons.Count(); m++) { double toleranceValue = ppmTolerance / Math.Pow(10, 6) * massList[l]; if ((massList[l] < diagnosticIons[m] + toleranceValue) & (massList[l] > diagnosticIons[m] - toleranceValue)) { diagnosticIons.Remove(diagnosticIons[m]); } } } i++; } while (diagnosticIons.Count() > 0); Assert.AreEqual(0, diagnosticIons.Count()); }
public void LoadMzmlTest() { Assert.Throws <AggregateException>(() => { Mzml.LoadAllStaticData(@"tiny.pwiz.1.1.mzML"); }, "Reading profile mode mzmls not supported"); }
internal IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > LoadFile(string origDataFile, int?topNpeaks, double?minRatio, bool trimMs1Peaks, bool trimMsMsPeaks) { FilteringParams filter = new FilteringParams(topNpeaks, minRatio, null, trimMs1Peaks, trimMsMsPeaks); if (myMsDataFiles.TryGetValue(origDataFile, out IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > value) && value != null) { return(value); } // By now know that need to load this file!!! lock (fileLoadingLock) // Lock because reading is sequential if (Path.GetExtension(origDataFile).Equals(".mzML", StringComparison.OrdinalIgnoreCase)) { myMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter); } else { #if NETFRAMEWORK myMsDataFiles[origDataFile] = ThermoStaticData.LoadAllStaticData(origDataFile, filter); #else Warn("No capability for reading " + origDataFile); #endif } return(myMsDataFiles[origDataFile]); }
public static void ProcessXcorrInB6MzSpectrum() { Dictionary <string, MsDataFile> MyMsDataFiles = new Dictionary <string, MsDataFile>(); string origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"DatabaseTests\sliced_b6.mzML"); FilteringParams filter = new FilteringParams(200, 0.01, null, 1, false, false, false); string expectedResultFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"DatabaseTests\Working_86.tsv"); List <string> expectedResults = File.ReadAllLines(expectedResultFile, Encoding.UTF8).ToList(); MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, 1); var scans = MyMsDataFiles[origDataFile].GetAllScansList(); List <double> xArrayProcessed = new List <double>(); foreach (MsDataScan scan in scans.Where(s => s.MsnOrder > 1)) { if (scan.OneBasedScanNumber == 86) { scan.MassSpectrum.XCorrPrePreprocessing(0, 1969, scan.IsolationMz.Value); xArrayProcessed = scan.MassSpectrum.XArray.ToList(); } } for (int i = 0; i < expectedResults.Count; i++) { Assert.That(double.Parse(expectedResults[i]), Is.EqualTo(xArrayProcessed[i]).Within(0.001)); } }
public static void TestModernSearchEngineTopDown() { CommonParameters CommonParameters = new CommonParameters( digestionParams: new DigestionParams(protease: "top-down"), scoreCutoff: 1, assumeOrphanPeaksAreZ1Fragments: false); var variableModifications = new List <Modification>(); var fixedModifications = new List <Modification>(); var proteinList = new List <Protein> { new Protein("MPKVYSYQEVAEHNGPENFWIIIDDKVYDVSQFKDEHPGGDEIIMDLGGQDATESFVDIGHSDEALRLLKGLYIGDVDKTSERVSVEKVSTSENQSKGSGTLVVILAILMLGVAYYLLNE", "P40312") }; var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TopDownTestData\slicedTDYeast.mzML")); var searchMode = new SinglePpmAroundZeroSearchMode(5); Tolerance DeconvolutionMassTolerance = new PpmTolerance(5); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray(); PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length]; var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.Reverse, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>()); var indexResults = (IndexingResults)indexEngine.Run(); new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, searchMode, 0, new List <string>()).Run(); var psm = allPsmsArray.Where(p => p != null).FirstOrDefault(); Assert.That(psm.MatchedFragmentIons.Count > 50); }
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 MsDataFile LoadFile(string origDataFile, CommonParameters commonParameters) { FilteringParams filter = new FilteringParams(commonParameters.NumberOfPeaksToKeepPerWindow, commonParameters.MinimumAllowedIntensityRatioToBasePeak, commonParameters.WindowWidthThomsons, commonParameters.NumberOfWindows, commonParameters.NormalizePeaksAccrossAllWindows, commonParameters.TrimMs1Peaks, commonParameters.TrimMsMsPeaks); if (commonParameters.DissociationType == DissociationType.LowCID || commonParameters.MS2ChildScanDissociationType == DissociationType.LowCID || commonParameters.MS3ChildScanDissociationType == DissociationType.LowCID) { filter = null; } if (MyMsDataFiles.TryGetValue(origDataFile, out MsDataFile value) && value != null) { return(value); } // By now know that need to load this file!!! lock (FileLoadingLock) // Lock because reading is sequential { if (Path.GetExtension(origDataFile).Equals(".mzML", StringComparison.OrdinalIgnoreCase)) { MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, commonParameters.MaxThreadsToUsePerFile); } else if (Path.GetExtension(origDataFile).Equals(".mgf", StringComparison.OrdinalIgnoreCase)) { MyMsDataFiles[origDataFile] = Mgf.LoadAllStaticData(origDataFile, filter); } else { MyMsDataFiles[origDataFile] = ThermoRawFileReaderData.LoadAllStaticData(origDataFile, filter, commonParameters.MaxThreadsToUsePerFile); } return(MyMsDataFiles[origDataFile]); } }
public bool Run_TdMzCal(InputFile raw_file, List <TopDownHit> topdown_hits) { all_topdown_hits = topdown_hits.Where(h => h.score > 0).ToList(); //need to reset m/z in case same td hits used for multiple calibration raw files... Parallel.ForEach(all_topdown_hits, h => h.mz = h.reported_mass.ToMz(h.charge)); high_scoring_topdown_hits = all_topdown_hits.Where(h => h.score >= 40).ToList(); this.raw_file = raw_file; if (high_scoring_topdown_hits.Count < 5) { return(false); } myMsDataFile = Path.GetExtension(raw_file.complete_path) == ".raw" ? ThermoStaticData.LoadAllStaticData(raw_file.complete_path) : null; if (myMsDataFile == null) { myMsDataFile = Mzml.LoadAllStaticData(raw_file.complete_path); } if (myMsDataFile == null) { return(false); } DataPointAquisitionResults dataPointAcquisitionResult = GetDataPoints(); if (dataPointAcquisitionResult.Ms1List.Count < 10) { return(false); } var myMs1DataPoints = new List <(double[] xValues, double yValue)>(); for (int i = 0; i < dataPointAcquisitionResult.Ms1List.Count; i++) { //x values var explanatoryVariables = new double[4]; explanatoryVariables[0] = dataPointAcquisitionResult.Ms1List[i].mz; explanatoryVariables[1] = dataPointAcquisitionResult.Ms1List[i].retentionTime; explanatoryVariables[2] = dataPointAcquisitionResult.Ms1List[i].logTotalIonCurrent; explanatoryVariables[3] = dataPointAcquisitionResult.Ms1List[i].logInjectionTime; //yvalue double mzError = dataPointAcquisitionResult.Ms1List[i].massError; myMs1DataPoints.Add((explanatoryVariables, mzError)); } var ms1Model = GetRandomForestModel(myMs1DataPoints); CalibrateHitsAndComponents(ms1Model); if (Sweet.lollipop.calibrate_raw_files) { MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, raw_file.directory + "\\" + raw_file.filename + "_calibrated.mzML", false); } return(true); }
public void LoadMzmlTest() { Mzml a = new Mzml(@"tiny.pwiz.1.1.mzML"); a.Open(); Assert.AreEqual(true, a.IsIndexedMzML); var ya = a.GetScan(1).MassSpectrum; }
public static void TestLookingForAcceptableIsotopicEnvelopes() { 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(); var ms2ScanTest = listOfSortedms2Scans[0]; //test when all the masses are not in the given range //test1 when all the masses are too small var test1 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(50, 95); Assert.AreEqual(test1, null); //test2 when all the masses are too big var test2 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(582, 682); Assert.AreEqual(test2, null); //test3 when the mass which is bigger than given min mass is bigger than the mass which is smaller than the given max mass //for example: the mass array is [1,2,3,4,5], the given min mass is 2.2, the given max mass is 2.8 var test3 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(110, 111); Assert.AreEqual(test3, null); //test normal conditions:look for IsotopicEnvelopes which are in the range of acceptable mass var test4 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(120, 130); IsotopicEnvelope[] expected4 = ms2ScanTest.ExperimentalFragments.Skip(15).Take(9).ToArray(); Assert.That(ms2ScanTest.ExperimentalFragments[15].MonoisotopicMass > 120 && ms2ScanTest.ExperimentalFragments[14].MonoisotopicMass < 120); Assert.That(ms2ScanTest.ExperimentalFragments[23].MonoisotopicMass < 130 && ms2ScanTest.ExperimentalFragments[24].MonoisotopicMass > 130); Assert.AreEqual(test4, expected4); var test5 = ms2ScanTest.GetClosestExperimentalIsotopicEnvelopeList(400, 500); IsotopicEnvelope[] expected5 = ms2ScanTest.ExperimentalFragments.Skip(150).Take(7).ToArray(); Assert.That(ms2ScanTest.ExperimentalFragments[150].MonoisotopicMass > 400 && ms2ScanTest.ExperimentalFragments[149].MonoisotopicMass < 400); Assert.That(ms2ScanTest.ExperimentalFragments[156].MonoisotopicMass < 500 && ms2ScanTest.ExperimentalFragments[157].MonoisotopicMass > 500); Assert.AreEqual(test5, expected5); }
public static void Test_ChargeDeconv() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/2076.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter(); Stopwatch stopwatch0 = new Stopwatch(); stopwatch0.Start(); var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); stopwatch0.Stop(); Stopwatch stopwatch_iso = new Stopwatch(); stopwatch_iso.Start(); var iso = IsoDecon.MsDeconv_Deconvolute(spectrum, spectrum.Range, deconvolutionParameter); stopwatch_iso.Stop(); Stopwatch stopwatch1 = new Stopwatch(); stopwatch1.Start(); var x = ChargeDecon.FindChargesForScan(spectrum, deconvolutionParameter); stopwatch1.Stop(); //Stopwatch stopwatch2 = new Stopwatch(); //stopwatch2.Start(); var stopwatch2 = Stopwatch.StartNew(); var x2 = ChargeDecon.QuickFindChargesForScan(spectrum, deconvolutionParameter); stopwatch2.Stop(); // Stopwatch stopwatch3 = new Stopwatch(); // stopwatch3.Start(); // int indUp = spectrum.ExtractIndicesByY().First(); // double mass_up = spectrum.XArray[indUp]; // var highest = ChargeDecon.FindChargesForPeak(spectrum, indUp, new DeconvolutionParameter()); // stopwatch3.Stop(); // var Parameters = Program.AddParametersFromFile(""); // List<double> masses = highest.Select(p => p.Value.Mz).ToList(); // string dynamicTargets; // string dynamicMaxITs; // Stopwatch stopwatch4 = new Stopwatch(); // stopwatch4.Start(); // var test = BoxCarScan.BuildDynamicBoxString(Parameters, masses, out dynamicTargets, out dynamicMaxITs); // stopwatch4.Stop(); // Assert.That(test == "[(400.0,522.8),(524.8,542.2),(544.2,563.1),(565.1,585.6),(587.6,610.0),(612.0,636.5),(638.5,665.4),(667.4,697.1),(699.1,732.0),(734.0,770.5),(772.5,813.3),(815.3,861.1),(863.1,915.0),(917.0,976.0),(978.0,1045.7),(1047.7,1126.1),(1128.1,1200.0)]"); }
public static void TestSummedMsDataFile() { ThermoStaticData rawFile = ThermoStaticData.LoadAllStaticData(@"05-13-16_cali_MS_60K-res_MS.raw"); // 3 scans SummedMsDataFile summed3 = new SummedMsDataFile(rawFile, 3, 10); Assert.AreEqual(rawFile.NumSpectra - 2, summed3.NumSpectra); var resultingTic = summed3.GetOneBasedScan(1).TotalIonCurrent; var mySummedTic = rawFile.GetOneBasedScan(1).MassSpectrum.SumOfAllY + rawFile.GetOneBasedScan(2).MassSpectrum.SumOfAllY + rawFile.GetOneBasedScan(3).MassSpectrum.SumOfAllY; var instrumentSummedTic = rawFile.GetOneBasedScan(1).TotalIonCurrent + rawFile.GetOneBasedScan(2).TotalIonCurrent + rawFile.GetOneBasedScan(3).TotalIonCurrent; // Tics are approximately what they should be Assert.IsTrue(Math.Abs(resultingTic - mySummedTic) / mySummedTic < 1e-4); Assert.IsTrue(Math.Abs(resultingTic - instrumentSummedTic) / instrumentSummedTic < 1e-1); // Equal to representative Assert.AreEqual(summed3.GetOneBasedScan(1).RetentionTime, rawFile.GetOneBasedScan(2).RetentionTime); Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size <= rawFile.GetOneBasedScan(1).MassSpectrum.Size + rawFile.GetOneBasedScan(2).MassSpectrum.Size + rawFile.GetOneBasedScan(3).MassSpectrum.Size); Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size >= rawFile.GetOneBasedScan(1).MassSpectrum.Size); Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size >= rawFile.GetOneBasedScan(2).MassSpectrum.Size); Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.Size >= rawFile.GetOneBasedScan(3).MassSpectrum.Size); Assert.IsTrue(summed3.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY == rawFile.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY + rawFile.GetOneBasedScan(2).MassSpectrum.YofPeakWithHighestY + rawFile.GetOneBasedScan(3).MassSpectrum.YofPeakWithHighestY); // Interval of 893-899 mz Assert.AreEqual(2, rawFile.GetOneBasedScan(1).MassSpectrum.NumPeaksWithinRange(893, 899)); Assert.AreEqual(2, rawFile.GetOneBasedScan(2).MassSpectrum.NumPeaksWithinRange(893, 899)); Assert.AreEqual(1, rawFile.GetOneBasedScan(3).MassSpectrum.NumPeaksWithinRange(893, 899)); // One peak persists across the three scans! So instead of 5 see three peaks in summed Assert.AreEqual(3, summed3.GetOneBasedScan(1).MassSpectrum.NumPeaksWithinRange(893, 899)); Assert.AreEqual(summed3.GetOneBasedScan(1).MassSpectrum.FirstX, Math.Min(Math.Min(rawFile.GetOneBasedScan(1).MassSpectrum.FirstX.Value, rawFile.GetOneBasedScan(2).MassSpectrum.FirstX.Value), rawFile.GetOneBasedScan(3).MassSpectrum.FirstX.Value)); Assert.AreEqual(summed3.GetOneBasedScan(1).MassSpectrum.LastX, Math.Max(Math.Max(rawFile.GetOneBasedScan(1).MassSpectrum.LastX.Value, rawFile.GetOneBasedScan(2).MassSpectrum.LastX.Value), rawFile.GetOneBasedScan(3).MassSpectrum.LastX.Value)); // 5 scans SummedMsDataFile summed5 = new SummedMsDataFile(rawFile, 5, 10); Assert.AreEqual(rawFile.NumSpectra - 4, summed5.NumSpectra); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(summed5, "testSummed.mzML", false); var ok = Mzml.LoadAllStaticData("testSummed.mzML"); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(ok, "testSummed2.mzML", false); Mzml.LoadAllStaticData("testSummed2.mzML"); }
public static void WriteIndexedMzmlFromThermoTest() { var smallThermo = ThermoStaticData.LoadAllStaticData(@"small.raw"); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(smallThermo, Path.Combine(TestContext.CurrentContext.TestDirectory, "Hi.mzML"), true); var smallMzml = Mzml.LoadAllStaticData(@"Hi.mzML"); Assert.AreEqual(smallMzml.NumSpectra, 48); Assert.AreEqual(smallMzml.GetOneBasedScan(8).OneBasedScanNumber, 8); Assert.AreEqual(smallThermo.GetOneBasedScan(5).RetentionTime, smallMzml.GetOneBasedScan(5).RetentionTime); }
public static void TestXicExtraction() { string dataFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", "SmallCalibratibleYeast.mzml"); var data = Mzml.LoadAllStaticData(dataFilePath); var peptide = new PeptideWithSetModifications("KAPAGGAADAAAK", new Dictionary <string, Modification>()); var xic = data.ExtractIonChromatogram(peptide.MonoisotopicMass, 2, new PpmTolerance(10), 24.806); Assert.That(xic.Data.Count(p => p.Y > 0) == 4); }
public static void Test_RealDataDeconv() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/20170802_QEp1_FlMe_SA_BOX0_SILAC_BoxCar_SLICED.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); var test = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); var ms1scans = scans.Where(p => p.MsnOrder == 1).ToList(); DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter(); }
public static void Test_FragmentMesh() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/2076.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); DeconvolutionParameter deconvolutionParameter = new DeconvolutionParameter(); var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); var CEs = ChargeDecon.FindChargesForScan(spectrum, deconvolutionParameter); var mesh = CEs.First().mzs_box; Assert.That(mesh.Count() == 3); }
public static void BU_dynamicBoxCarRange() { string FilepathMZML = Path.Combine(TestContext.CurrentContext.TestDirectory, @"Data/20170802_QEp1_FlMe_SA_BOX0_SILAC_BoxCar_SLICED.mzML"); MsDataFile file = Mzml.LoadAllStaticData(FilepathMZML, null); var scans = file.GetAllScansList(); var spectrum = new MzSpectrumXY(scans.First().MassSpectrum.XArray, scans.First().MassSpectrum.YArray, true); Parameters parameters = Program.AddParametersFromFile(""); var isos = IsoDecon.MsDeconv_Deconvolute(spectrum, spectrum.Range, parameters.DeconvolutionParameter); List <List <Tuple <double, double, double> > > Boxes = new List <List <Tuple <double, double, double> > >(); BoxCarScan.GenerateDynamicBoxes_BU(isos, parameters, Boxes); Assert.That(Boxes.Count == 2); }
/// <summary> /// Tests peak filtering for ThermoRawFileReader /// </summary> public static void TestPeakFilteringRawFileReader(string infile) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var filterParams = new FilteringParams(200, 0.01, 0, 1, false, true, true); var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", infile); var a = ThermoRawFileReader.LoadAllStaticData(path, filterParams, maxThreads: 1); var rawScans = a.GetAllScansList(); foreach (var scan in rawScans) { Assert.That(scan.MassSpectrum.XArray.Length <= 200); } string outfile1 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", Path.GetFileNameWithoutExtension(infile) + ".mzML"); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, outfile1, false); var mzml = Mzml.LoadAllStaticData(outfile1, filterParams, maxThreads: 1); var mzmlScans = mzml.GetAllScansList(); for (int i = 0; i < mzmlScans.Count; i++) { var mzmlScan = mzmlScans[i]; var rawScan = rawScans[i]; for (int j = 0; j < mzmlScan.MassSpectrum.XArray.Length; j++) { double roundedMzmlMz = Math.Round(mzmlScan.MassSpectrum.XArray[j], 2); double roundedRawMz = Math.Round(rawScan.MassSpectrum.XArray[j], 2); Assert.AreEqual(roundedMzmlMz, roundedRawMz); double roundedMzmlIntensity = Math.Round(mzmlScan.MassSpectrum.XArray[j], 0); double roundedRawIntensity = Math.Round(rawScan.MassSpectrum.XArray[j], 0); Assert.AreEqual(roundedMzmlIntensity, roundedRawIntensity); } } Console.WriteLine($"Analysis time for TestPeakFilteringRawFileReader: {stopwatch.Elapsed.Hours}h " + $"{stopwatch.Elapsed.Minutes}m {stopwatch.Elapsed.Seconds}s"); }
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 static void LoadCompressedMzml() { ThermoStaticData a = ThermoStaticData.LoadAllStaticData(@"small.RAW"); Mzml b = Mzml.LoadAllStaticData(@"smallCentroid.mzML"); Assert.AreEqual(a.NumSpectra, b.NumSpectra); Assert.AreEqual(a.GetOneBasedScan(1).MassSpectrum.XofPeakWithHighestY.Value, b.GetOneBasedScan(1).MassSpectrum.XofPeakWithHighestY.Value, 1e-8); Assert.IsTrue(Math.Abs((a.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value - b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) / b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) < 1e-8); Assert.AreEqual(a.GetOneBasedScan(2).MassSpectrum.XofPeakWithHighestY.Value, b.GetOneBasedScan(2).MassSpectrum.XofPeakWithHighestY, 1e-8); Assert.IsTrue(Math.Abs((a.GetOneBasedScan(2).MassSpectrum.YofPeakWithHighestY.Value - b.GetOneBasedScan(2).MassSpectrum.YofPeakWithHighestY.Value) / b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) < 1e-8); Assert.AreEqual(a.GetOneBasedScan(3).MassSpectrum.XofPeakWithHighestY.Value, b.GetOneBasedScan(3).MassSpectrum.XofPeakWithHighestY.Value, 1e-8); Assert.IsTrue(Math.Abs((a.GetOneBasedScan(3).MassSpectrum.YofPeakWithHighestY.Value - b.GetOneBasedScan(3).MassSpectrum.YofPeakWithHighestY.Value) / b.GetOneBasedScan(1).MassSpectrum.YofPeakWithHighestY.Value) < 1e-8); }
public void LoadMzmlAnotherTest() { Mzml a = Mzml.LoadAllStaticData(@"small.pwiz.1.1.mzML"); Assert.AreEqual(19914, a.First().MassSpectrum.Size); //a = new Mzml(@"small.pwiz.1.1.mzML", 400); //a.Open(); //Assert.AreEqual(400, a.First().MassSpectrum.Size); //var cool = a.GetOneBasedScan(6) as MzmlScanWithPrecursor; //Assert.AreEqual(1, cool.IsolationWidth); //a.Close(); }
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 static void ProcessXcorrInMzSpectrum() { Dictionary <string, MsDataFile> MyMsDataFiles = new Dictionary <string, MsDataFile>(); string origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", "BinGenerationTest.mzML"); FilteringParams filter = new FilteringParams(200, 0.01, null, 1, false, false, true); MyMsDataFiles[origDataFile] = Mzml.LoadAllStaticData(origDataFile, filter, 1); var scans = MyMsDataFiles[origDataFile].GetAllScansList(); foreach (MsDataScan scan in scans.Where(s => s.MsnOrder > 1)) { scan.MassSpectrum.XCorrPrePreprocessing(0, 1968 * 1.0005079, scan.IsolationMz.Value); } Assert.AreEqual(6, scans[0].MassSpectrum.XArray.Count()); Assert.AreEqual(20, scans[1].MassSpectrum.XArray.Count()); }
/// <summary> /// Tests LoadAllStaticData for ThermoRawFileReader /// </summary> public static void TestLoadAllStaticDataRawFileReader(string infile, string outfile1, string outfile2) { var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", infile); outfile1 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", outfile1); outfile2 = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataFiles", outfile2); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var a = ThermoRawFileReader.LoadAllStaticData(path, maxThreads: 1); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, outfile1, false); var aa = Mzml.LoadAllStaticData(outfile1); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(aa, outfile2, true); Mzml.LoadAllStaticData(outfile2); Console.WriteLine($"Analysis time for TestLoadAllStaticDataRawFileReader({infile}): {stopwatch.Elapsed.Hours}h {stopwatch.Elapsed.Minutes}m {stopwatch.Elapsed.Seconds}s"); }
public void LoadMzmlTest() { Mzml a = Mzml.LoadAllStaticData(@"tiny.pwiz.1.1.mzML"); var ya = a.GetOneBasedScan(1).MassSpectrum; Assert.AreEqual(15, ya.Size); var ya2 = a.GetOneBasedScan(2).MassSpectrum; Assert.AreEqual(10, ya2.Size); var ya3 = a.GetOneBasedScan(3).MassSpectrum; Assert.AreEqual(0, ya3.Size); var ya4 = a.GetOneBasedScan(4).MassSpectrum; Assert.AreEqual(15, ya4.Size); IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > ok = a; Assert.AreEqual(1, ok.GetClosestOneBasedSpectrumNumber(5)); }
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 LoadMzmlFromConvertedMGFTest() { Mzml a = Mzml.LoadAllStaticData(@"tester.mzML"); var ya = a.GetOneBasedScan(1).MassSpectrum; Assert.AreEqual(192, ya.Size); var ya2 = a.GetOneBasedScan(3).MassSpectrum; Assert.AreEqual(165, ya2.Size); var ya3 = a.GetOneBasedScan(5).MassSpectrum; Assert.AreEqual(551, ya3.Size); var ya4 = a.GetOneBasedScan(975).MassSpectrum; Assert.AreEqual(190, ya4.Size); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(a, "CreateFileFromConvertedMGF.mzML", false); Mzml b = Mzml.LoadAllStaticData(@"CreateFileFromConvertedMGF.mzML"); MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(b, "CreateFileFromConvertedMGF2.mzML", false); }