//[TestCase(@"MzML\QC_Shew_16_01-15f_MPA_02redo_8Nov16_Tiger_16-02-14.mzML.gz", 9293)] // implemented, but decompresses first public void ReadMzMLChromatogramsTestRandom(string inputFileRelativePath, int expectedChromatograms) { if (!TestPath.FindInputFile(inputFileRelativePath, out var sourceFile)) { Console.WriteLine("File not found: " + inputFileRelativePath); return; } using (var reader = new SimpleMzMLReader(sourceFile.FullName, true, true)) { Assert.AreEqual(expectedChromatograms, reader.NumChromatograms); var chromCount = 0; foreach (var chrom in reader.ReadAllChromatograms(true)) { if (chrom == null) { Console.WriteLine("ReadAllChromatograms returned null for chromatogram index {0}", chromCount); } else { Console.WriteLine("Chromatogram {0}, NativeID {1,-45} has {2:N0} data points", chrom.Index, chrom.Id, chrom.Intensities.Length); } chromCount++; } Assert.AreEqual(expectedChromatograms, chromCount); } }
public void ReadMzMLChromatogramsTestNonRandom(string inputFileRelativePath, int expectedSpectra, int expectedChromatograms) { if (!TestPath.FindInputFile(inputFileRelativePath, out var sourceFile)) { Console.WriteLine("File not found: " + inputFileRelativePath); return; } using (var reader = new SimpleMzMLReader(sourceFile.FullName, false, true)) { Assert.AreEqual(expectedSpectra, reader.NumSpectra); if (expectedSpectra != 0) { Assert.AreEqual(0, reader.NumChromatograms); } var specCount = 0; foreach (var spec in reader.ReadAllSpectra(true)) { if (specCount < 100 || specCount >= expectedSpectra - 100) { Console.WriteLine("Spectrum {0,4}, NativeID {1,-45} has {2:N0} data points", spec.ScanNumber, spec.NativeId, spec.Peaks.Length); } else if (specCount == 100) { Console.WriteLine("..."); } specCount++; } Assert.AreEqual(expectedSpectra, specCount); Assert.AreEqual(expectedChromatograms, reader.NumChromatograms); var chromCount = 0; foreach (var chrom in reader.ReadAllChromatograms(false)) { if (chrom == null) { Console.WriteLine("ReadAllChromatograms returned null for chromatogram index {0}", chromCount); } else { Console.WriteLine("Chromatogram {0}, NativeID {1,-45} has {2:N0} data points", chrom.Index, chrom.Id, chrom.Intensities.Length); } chromCount++; } Assert.AreEqual(expectedChromatograms, reader.NumChromatograms); Assert.AreEqual(expectedChromatograms, chromCount); } }
public List <CompoundData> ReadSpectraData(List <CompoundData> combinedTransitions) { using (var reader = new SimpleMzMLReader(DatasetPath)) { foreach (var spectrum in reader.ReadAllSpectra(true)) { if (spectrum.Precursors.Count == 0) { continue; } var time = spectrum.ScanStartTime; var precursorMz = spectrum.Precursors[0].SelectedIons[0].SelectedIonMz; var matches = combinedTransitions.Where(x => x.StartTimeMinutes <= time && time <= x.StopTimeMinutes && Math.Abs(x.PrecursorMz - precursorMz) < 0.01); foreach (var match in matches) { foreach (var trans in match.Transitions) { foreach (var scanWindow in spectrum.ScanWindows.Where(x => x.LowerLimit <= trans.ProductMz && trans.ProductMz <= x.UpperLimit)) { //foreach (var peakMatch in srmSpec.Peaks.Where(x => Math.Abs(trans.ProductMz - x.Mz) < 0.01)) foreach (var peakMatch in spectrum.Peaks.Where(x => scanWindow.LowerLimit <= x.Mz && x.Mz <= scanWindow.UpperLimit)) { var intensity = peakMatch.Intensity; trans.IntensitySum += intensity; trans.Intensities.Add(new TransitionData.DataPoint(spectrum.ScanNumber, time, intensity)); if (intensity > trans.MaxIntensity) { trans.MaxIntensity = intensity; trans.MaxIntensityTime = time; } } } } } } var medianScanTimeDiff = 0.001; foreach (var chromatogram in reader.ReadAllChromatograms(true)) { if (chromatogram.CVParams.Any(x => x.TermInfo.Cvid == CV.CVID.MS_total_ion_current_chromatogram)) { // First chromatogram, use it to determine approximate scan times var diffs = new List <double>(chromatogram.Times.Length); var lastTime = 0.0; foreach (var time in chromatogram.Times) { diffs.Add(time - lastTime); lastTime = time; } diffs.Sort(); medianScanTimeDiff = diffs[diffs.Count / 2]; } if (!chromatogram.CVParams.Any(x => x.TermInfo.Cvid == CV.CVID.MS_selected_reaction_monitoring_chromatogram)) { continue; } var precursorMz = chromatogram.Precursor.IsolationWindow.TargetMz; var productMz = chromatogram.Product.TargetMz; var matches = combinedTransitions.Where(x => Math.Abs(x.PrecursorMz - precursorMz) < 0.01); foreach (var match in matches) { foreach (var trans in match.Transitions.Where(x => Math.Abs(x.ProductMz - productMz) < 0.01)) { for (var i = 0; i < chromatogram.Times.Length; i++) { var time = chromatogram.Times[i]; var intensity = chromatogram.Intensities[i]; trans.IntensitySum += intensity; var estimatedScanNum = (int)Math.Round(time / medianScanTimeDiff, MidpointRounding.AwayFromZero); trans.Intensities.Add(new TransitionData.DataPoint(estimatedScanNum, time, intensity)); if (intensity > trans.MaxIntensity) { trans.MaxIntensity = intensity; trans.MaxIntensityTime = time; } } } } } } return(combinedTransitions.ToList()); }