private void ProcessSrmSpectrum(double time, string modifiedSequence, Color peptideColor, double precursorMz, int filterIndex, double[] mzs, double[] intensities, double ionMobilityValue, double ionMobilityExtractionWidth, ChromDataCollectorSet chromMap) { float[] intensityFloats = new float[intensities.Length]; for (int i = 0; i < intensities.Length; i++) intensityFloats[i] = (float) intensities[i]; var productFilters = mzs.Select(mz => new SpectrumProductFilter(mz, 0)).ToArray(); var spectrum = new ExtractedSpectrum(modifiedSequence, peptideColor, precursorMz, ionMobilityValue, ionMobilityExtractionWidth, ChromExtractor.summed, filterIndex, productFilters, intensityFloats, null); chromMap.ProcessExtractedSpectrum((float)time, _collectors, -1, spectrum, null); }
/// <summary> /// Process a list of spectra - typically of length one, /// but possibly a set of drift bins all with same retention time, /// or a set of Agilent ramped-CE Mse scans to be averaged /// </summary> private void ProcessSpectrumList(MsDataSpectrum[] spectra, ChromDataCollectorSet chromMap, double rt, SpectrumFilter filter, string scanId) { lock (_blockWriter) { foreach (var spectrum in filter.Extract(rt, spectra)) { if (_loader.IsCanceled) throw new LoadCanceledException(Status); chromMap.ProcessExtractedSpectrum((float) rt, _collectors, GetScanIdIndex(scanId), spectrum, AddChromCollector); } } }
private void ExtractChromatogramsLocked() { // First read all of the spectra, building chromatogram time, intensity lists var fragmentTimeSharing = _spectra.HasSrmSpectra ? TimeSharing.single : TimeSharing.grouped; var chromMap = new ChromDataCollectorSet(ChromSource.fragment, fragmentTimeSharing, _allChromData, _blockWriter); var ms1TimeSharing = _filter.IsSharedTime ? TimeSharing.shared : TimeSharing.grouped; var chromMapMs1 = new ChromDataCollectorSet(ChromSource.ms1, ms1TimeSharing, _allChromData, _blockWriter); var chromMapSim = new ChromDataCollectorSet(ChromSource.sim, TimeSharing.grouped, _allChromData, _blockWriter); var chromMaps = new[] {chromMap, chromMapSim, chromMapMs1}; var dictPrecursorMzToIndex = new Dictionary<double, int>(); // For SRM processing var peptideFinder = _spectra.HasSrmSpectra ? new PeptideFinder(_document) : null; while (_spectra.NextSpectrum()) { if (_isDisposing) { CompleteChromatograms(chromMaps); return; } UpdatePercentComplete(); if (_spectra.HasSrmSpectra) { var dataSpectrum = _spectra.CurrentSpectrum; double precursorMz = dataSpectrum.Precursors[0].PrecursorMz ?? 0; int filterIndex; if (!dictPrecursorMzToIndex.TryGetValue(precursorMz, out filterIndex)) { filterIndex = dictPrecursorMzToIndex.Count; dictPrecursorMzToIndex.Add(precursorMz, filterIndex); } // Process the one SRM spectrum var peptideNode = peptideFinder != null ? peptideFinder.FindPeptide(precursorMz) : null; ProcessSrmSpectrum( dataSpectrum.RetentionTime.Value, peptideNode != null ? peptideNode.ModifiedSequence : string.Empty, peptideNode != null ? peptideNode.Color : PeptideDocNode.UNKNOWN_COLOR, precursorMz, filterIndex, dataSpectrum.Mzs, dataSpectrum.Intensities, 0, 0, // ion mobility unknown chromMap); } else if (_filter.EnabledMsMs || _filter.EnabledMs) { var dataSpectrum = _spectra.CurrentSpectrum; var spectra = _spectra.CurrentSpectra; float rt = _spectra.CurrentTime; if (_allChromData != null) _allChromData.CurrentTime = rt; if (_filter.IsMsSpectrum(dataSpectrum)) { var chromMapMs = _filter.IsSimSpectrum(dataSpectrum) ? chromMapSim : chromMapMs1; string scanId = dataSpectrum.Id; // Process all SRM spectra that can be generated by filtering this full-scan MS1 if (chromMapMs.IsSharedTime) { chromMapMs.AddSharedTime(rt, (short) GetScanIdIndex(scanId)); } lock (_blockWriter) { foreach (var spectrum in _filter.SrmSpectraFromMs1Scan(rt, dataSpectrum.Precursors, spectra)) { chromMapMs.ProcessExtractedSpectrum(rt, _collectors, GetScanIdIndex(scanId), spectrum, AddChromCollector); } } } if (_filter.IsMsMsSpectrum(dataSpectrum)) { // Process all SRM spectra that can be generated by filtering this full-scan MS/MS if (_demultiplexer == null) { ProcessSpectrumList(spectra, chromMap, rt, _filter, dataSpectrum.Id); } else { int i = _spectra.CurrentIndex; foreach (var deconvSpectrum in _demultiplexer.GetDeconvolvedSpectra(i, dataSpectrum)) { ProcessSpectrumList(new[] {deconvSpectrum}, chromMap, rt, _filter, dataSpectrum.Id); } } } // Complete any chromatograms with filter pairs with a maximum time earlier // than the current retention time. CompleteChromatograms(chromMaps, rt); } } string log = _spectra.GetLog(); if (log != null) // in case perf logging is enabled DebugLog.Info(log); if (_spectra.HasSrmSpectra) { foreach (var map in chromMaps) AddChromatograms(map); } else { CompleteChromatograms(chromMaps); } if (chromMap.Count == 0 && chromMapMs1.Count == 0 && chromMapSim.Count == 0) throw new NoFullScanDataException(_filePath); }
private void CompleteChromatograms(ChromDataCollectorSet[] chromMaps, double retentionTime = -1) { var finishedFilterPairs = _filter.RemoveFinishedFilterPairs(retentionTime); foreach (var filterPair in finishedFilterPairs) AddChromatogramsForFilterPair(chromMaps, filterPair); // Update time for which chromatograms are available. _collectors.AddComplete(retentionTime >= 0 ? (float)retentionTime : float.MaxValue); }
private void AddChromatogramsForFilterPair(ChromDataCollectorSet[] chromMaps, SpectrumFilterPair filterPair) { // Fill the chromatograms that were actually extracted foreach (var chromMap in chromMaps) { if (filterPair.Id >= chromMap.PrecursorCollectorMap.Count || chromMap.PrecursorCollectorMap[filterPair.Id] == null) continue; var pairPrecursor = chromMap.PrecursorCollectorMap[filterPair.Id]; chromMap.PrecursorCollectorMap[filterPair.Id] = null; var collector = pairPrecursor.Item2; var scanIdCollector = chromMap.ScanIdsCollector; var timesCollector = chromMap.SharedTimesCollector; if (chromMap.IsGroupedTime) { scanIdCollector = collector.ScansCollector; timesCollector = collector.GroupedTimesCollector; } foreach (var pairProduct in collector.ProductIntensityMap) { var chromCollector = pairProduct.Value; if (timesCollector != null) { chromCollector.SetScans(scanIdCollector); chromCollector.SetTimes(timesCollector); } _collectors.AddCollector(pairProduct.Key.FilterId, chromCollector); } } }
private void AddChromatograms(ChromDataCollectorSet chromMap) { var scanIdCollector = chromMap.ScanIdsCollector; var timesCollector = chromMap.SharedTimesCollector; foreach (var pairPrecursor in chromMap.PrecursorCollectorMap) { if (pairPrecursor == null) continue; var modSeq = pairPrecursor.Item1; var collector = pairPrecursor.Item2; if (chromMap.IsGroupedTime) { scanIdCollector = collector.ScansCollector; timesCollector = collector.GroupedTimesCollector; } foreach (var pairProduct in collector.ProductIntensityMap) { var chromCollector = pairProduct.Value; if (timesCollector != null) { chromCollector.SetScans(scanIdCollector); chromCollector.SetTimes(timesCollector); } var key = new ChromKey( collector.ModifiedSequence, collector.PrecursorMz, collector.IonMobilityValue, collector.IonMobilityExtractionWidth, pairProduct.Key.TargetMz, 0, pairProduct.Key.FilterWidth, chromMap.ChromSource, modSeq.Extractor, true, true, null, null); _collectors.AddSrmCollector(key, chromCollector); } } }