public double[] GetTotalIonCurrent() { if (ChromatogramList == null) { return null; } using (var chromatogram = ChromatogramList.chromatogram(0, true)) { if (chromatogram == null) { return null; } TimeIntensityPairList timeIntensityPairList = new TimeIntensityPairList(); chromatogram.getTimeIntensityPairs(ref timeIntensityPairList); double[] intensities = new double[timeIntensityPairList.Count]; for (int i = 0; i < intensities.Length; i++) { intensities[i] = timeIntensityPairList[i].intensity; } return intensities; } }
private void TestPWiz(string strFilePath) { const bool RUN_BENCHMARKS = false; try { var objPWiz2 = new MSDataFile(strFilePath); Console.WriteLine("Spectrum count: " + objPWiz2.run.spectrumList.size()); Console.WriteLine(); if (objPWiz2.run.spectrumList.size() > 0) { var intSpectrumIndex = 0; do { var oSpectrum = objPWiz2.run.spectrumList.spectrum(intSpectrumIndex, getBinaryData: true); pwiz.CLI.data.CVParam param; if (oSpectrum.scanList.scans.Count > 0) { if (clsProteowizardDataParser.TryGetCVParam(oSpectrum.scanList.scans[0].cvParams, pwiz.CLI.cv.CVID.MS_scan_start_time, out param)) { var intScanNum = intSpectrumIndex + 1; var dblStartTimeMinutes = param.timeInSeconds() / 60.0; Console.WriteLine("ScanIndex " + intSpectrumIndex + ", Scan " + intScanNum + ", Elution Time " + dblStartTimeMinutes + " minutes"); } } // Use the following to determine info on this spectrum if (clsProteowizardDataParser.TryGetCVParam(oSpectrum.cvParams, pwiz.CLI.cv.CVID.MS_ms_level, out param)) { int.TryParse(param.value, out _); } // Use the following to get the MZs and Intensities var oMZs = oSpectrum.getMZArray(); oSpectrum.getIntensityArray(); if (oMZs.data.Count > 0) { Console.WriteLine(" Data count: " + oMZs.data.Count); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (RUN_BENCHMARKS) { double dblTIC1 = 0; double dblTIC2 = 0; var dtStartTime = default(DateTime); var dtEndTime = default(DateTime); double dtRunTimeSeconds1 = 0; double dtRunTimeSeconds2 = 0; const int LOOP_ITERATIONS = 2000; // Note from Matt Chambers (matt.chambers42 at gmail) // Repeatedly accessing items directly via oMZs.data() can be very slow // With 700 points and 2000 iterations, it takes anywhere from 0.6 to 1.1 seconds to run from dtStartTime to dtEndTime dtStartTime = DateTime.Now; for (var j = 1; j <= LOOP_ITERATIONS; j++) { for (var intIndex = 0; intIndex <= oMZs.data.Count - 1; intIndex++) { dblTIC1 += oMZs.data[intIndex]; } } dtEndTime = DateTime.Now; dtRunTimeSeconds1 = dtEndTime.Subtract(dtStartTime).TotalSeconds; // The preferred method is to copy the data from .data to a locally-stored mzArray var // With 700 points and 2000 iterations, it takes 0.016 seconds to run from dtStartTime to dtEndTime dtStartTime = DateTime.Now; for (var j = 1; j <= LOOP_ITERATIONS; j++) { var oMzArray = oMZs.data; for (var intIndex = 0; intIndex <= oMzArray.Count - 1; intIndex++) { dblTIC2 += oMzArray[intIndex]; } } dtEndTime = DateTime.Now; dtRunTimeSeconds2 = dtEndTime.Subtract(dtStartTime).TotalSeconds; Console.WriteLine(" " + oMZs.data.Count + " points with " + LOOP_ITERATIONS + " iterations gives Runtime1=" + dtRunTimeSeconds1.ToString("0.0##") + " sec. vs. Runtime2=" + dtRunTimeSeconds2.ToString("0.0##") + " sec."); if (Math.Abs(dblTIC1 - dblTIC2) > float.Epsilon) { Console.WriteLine(" TIC values don't agree; this is unexpected"); } } } if (intSpectrumIndex < 25) { intSpectrumIndex += 1; } else { intSpectrumIndex += 50; } } while (intSpectrumIndex < objPWiz2.run.spectrumList.size()); } if (objPWiz2.run.chromatogramList.size() > 0) { var intChromIndex = 0; do { var oTimeIntensityPairList = new TimeIntensityPairList(); // Note that even for a small .Wiff file (1.5 MB), obtaining the Chromatogram list will take some time (20 to 60 seconds) // The chromatogram at index 0 should be the TIC // The chromatogram at index >=1 will be each SRM var oChromatogram = objPWiz2.run.chromatogramList.chromatogram(intChromIndex, getBinaryData: true); // Determine the chromatogram type if (clsProteowizardDataParser.TryGetCVParam(oChromatogram.cvParams, pwiz.CLI.cv.CVID.MS_TIC_chromatogram, out var param)) { // Obtain the data oChromatogram.getTimeIntensityPairs(ref oTimeIntensityPairList); } if (clsProteowizardDataParser.TryGetCVParam(oChromatogram.cvParams, pwiz.CLI.cv.CVID.MS_selected_reaction_monitoring_chromatogram, out param)) { // Obtain the SRM scan oChromatogram.getTimeIntensityPairs(ref oTimeIntensityPairList); } intChromIndex += 1; } while (intChromIndex < 50 && intChromIndex < objPWiz2.run.chromatogramList.size()); } } catch (Exception ex) { OnErrorEvent("Error using ProteoWizard reader: " + ex.Message, ex); } }
/// <summary> /// Gets the retention times from the first chromatogram in the data file. /// Returns null if there are no chromatograms in the file. /// </summary> public double[] GetScanTimes() { using (_perf.CreateTimer("GetScanTimes")) // Not L10N { if (ChromatogramList == null || ChromatogramList.empty()) { return null; } using (var chromatogram = ChromatogramList.chromatogram(0, true)) { if (chromatogram == null) { return null; } TimeIntensityPairList timeIntensityPairList = new TimeIntensityPairList(); chromatogram.getTimeIntensityPairs(ref timeIntensityPairList); double[] times = new double[timeIntensityPairList.Count]; for (int i = 0; i < times.Length; i++) { times[i] = timeIntensityPairList[i].time; } return times; } } }