public SpectrumData(MsDataFileImpl msDataFileImpl, int scanIndex) { ScanIndex = scanIndex; var spectrum = msDataFileImpl.GetSpectrum(scanIndex); if (spectrum.Centroided) { CentroidMzs = spectrum.Mzs; CentroidIntensities = spectrum.Intensities; } else { ProfileMzs = spectrum.Mzs; ProfileIntensities = spectrum.Intensities; var centroider = new Centroider(ProfileMzs, ProfileIntensities); double[] centroidMzs, centroidIntensities; centroider.GetCentroidedData(out centroidMzs, out centroidIntensities); CentroidMzs = centroidMzs; CentroidIntensities = centroidIntensities; } Time = spectrum.RetentionTime; MsLevel = spectrum.Level; }
private void GenerateChromatograms(ChromatogramTask chromatogramTask) { int totalAnalyses = chromatogramTask.AnalysisChromatograms.Count; if (totalAnalyses == 0) { return; } if (!UpdateProgress(chromatogramTask, 0)) { return; } var msDataFile = chromatogramTask.MsDataFile; MsDataFileUtil.InitMsDataFile(chromatogramTask.Workspace, msDataFile); var analyses = new List<AnalysisChromatograms>(chromatogramTask.AnalysisChromatograms); MsDataFileImpl pwizMsDataFileImpl; var path = _workspace.GetDataFilePath(msDataFile.Name); try { pwizMsDataFileImpl = new MsDataFileImpl(path); } catch (Exception exception) { ErrorHandler.LogException("Chromatogram Generator", "Error opening " + path, exception); _workspace.RejectMsDataFile(msDataFile); return; } using (pwizMsDataFileImpl) { var completeAnalyses = new List<AnalysisChromatograms>(); int totalScanCount = pwizMsDataFileImpl.SpectrumCount; var lastTimeInDataFile = chromatogramTask.MsDataFile.GetTime(chromatogramTask.MsDataFile.GetSpectrumCount() - 1); double minTime = lastTimeInDataFile; double maxTime = msDataFile.GetTime(0); foreach (var analysis in analyses) { minTime = Math.Min(minTime, analysis.FirstTime); maxTime = Math.Max(maxTime, analysis.LastTime); } int firstScan = msDataFile.FindScanIndex(minTime); for (int iScan = firstScan; analyses.Count > 0 && iScan < totalScanCount; iScan++) { double time = msDataFile.GetTime(iScan); int progress = (int)(100 * (time - minTime) / (maxTime - minTime)); progress = Math.Min(progress, 100); progress = Math.Max(progress, 0); if (!UpdateProgress(chromatogramTask, progress)) { return; } List<AnalysisChromatograms> activeAnalyses = new List<AnalysisChromatograms>(); double nextTime = Double.MaxValue; if (msDataFile.GetMsLevel(iScan, pwizMsDataFileImpl) != 1) { continue; } foreach (var analysis in analyses) { nextTime = Math.Min(nextTime, analysis.FirstTime); if (analysis.FirstTime <= time) { activeAnalyses.Add(analysis); } } if (activeAnalyses.Count == 0) { int nextScan = msDataFile.FindScanIndex(nextTime); iScan = Math.Max(iScan, nextScan - 1); continue; } bool lowMemory = IsLowOnMemory(); // If we have exceeded the number of analyses we should be working on at once, // throw out any that we haven't started. for (int iAnalysis = activeAnalyses.Count - 1; iAnalysis >= 0 && (activeAnalyses.Count > _maxConcurrentAnalyses || lowMemory); iAnalysis--) { var analysis = activeAnalyses[iAnalysis]; if (analysis.Times.Count > 0) { continue; } activeAnalyses.RemoveAt(iAnalysis); analyses.Remove(analysis); } double[] mzArray, intensityArray; pwizMsDataFileImpl.GetSpectrum(iScan, out mzArray, out intensityArray); if (!pwizMsDataFileImpl.IsCentroided(iScan)) { var centroider = new Centroider(mzArray, intensityArray); centroider.GetCentroidedData(out mzArray, out intensityArray); } foreach (var analysis in activeAnalyses) { var points = new List<ChromatogramPoint>(); foreach (var chromatogram in analysis.Chromatograms) { points.Add(MsDataFileUtil.GetPoint(chromatogram.MzRange, mzArray, intensityArray)); } analysis.AddPoints(iScan, time, points); } var incompleteAnalyses = new List<AnalysisChromatograms>(); foreach (var analysis in analyses) { if (analysis.LastTime <= time) { completeAnalyses.Add(analysis); } else { incompleteAnalyses.Add(analysis); } } SaveChromatograms(chromatogramTask, completeAnalyses, false); completeAnalyses.Clear(); analyses = incompleteAnalyses; } completeAnalyses.AddRange(analyses); SaveChromatograms(chromatogramTask, completeAnalyses, true); } }