private void AddChromKeys(ChromSource source, SpectrumProductFilter[] productFilters, bool highEnergy, List <ChromKey> listChromKeys) { if (null != productFilters) { double?imCenterOpt = null; double imCenter, imWidth; if (GetDriftTimeWindow(out imCenter, out imWidth, highEnergy)) { imCenterOpt = imCenter; } foreach (var spectrumProductFilter in productFilters) { spectrumProductFilter.FilterId = listChromKeys.Count; var key = new ChromKey(ModifiedSequence, Q1, imCenterOpt, imWidth, spectrumProductFilter.TargetMz, 0, // CE value (Shimadzu SRM only) spectrumProductFilter.FilterWidth, source, Extractor, true, true, MinTime, MaxTime); listChromKeys.Add(key); } } }
private static IEnumerable <double> ReadChromPrecursorsFromMsd(MsDataFileImpl msd, IProgressMonitor monitor) { for (var i = 0; i < msd.ChromatogramCount; i++) { if (monitor.IsCanceled) { yield break; } double?precursor = null; try { int tmp; var chromKey = ChromKey.FromId(msd.GetChromatogramId(i, out tmp), false); precursor = chromKey.Precursor; } catch { // ignored } if (precursor.HasValue) { yield return(precursor.Value); } } }
public bool GetChromatogram(ChromKey chromKey, out float[] times, out int[] scanIds, out float[] intensities, out float[] massErrors) { ChromatogramGeneratorTask task; if (!_chromKeys.TryGetValue(chromKey, out task)) { times = null; intensities = null; massErrors = null; scanIds = null; return(false); } lock (LockObj) { StartTask(task); while (!task.IsFinished()) { Monitor.Wait(LockObj, CANCEL_CHECK_MILLIS); CheckCancelled(); } if (null != _exception) { throw new ChorusServerException(_exception.Message, _exception); } } return(task.GetChromatogram(chromKey, out times, out scanIds, out intensities, out massErrors)); }
public ChromatogramGeneratorTask GetGeneratorTask(ChromKey chromKey) { ChromatogramGeneratorTask task; _chromKeys.TryGetValue(chromKey, out task); return(task); }
public bool GetChromatogram(ChromKey chromKey, out TimeIntensities timeIntensities) { int keyIndex = -1; if (_chromKeyIndiceses != null) { var tolerance = (float)ChromTaskList.SrmDocument.Settings.TransitionSettings.Instrument.MzMatchTolerance; keyIndex = _chromKeyIndiceses.IndexOf(entry => EqualsTolerant(chromKey, entry.Key, tolerance)); } if (keyIndex == -1 || _chromKeyIndiceses == null) // Keep ReSharper from complaining { timeIntensities = null; return(false); } ChromKeyIndices chromKeyIndices = _chromKeyIndiceses[keyIndex]; var chromGroupInfo = _chromatogramCache.LoadChromatogramInfo(chromKeyIndices.GroupIndex); chromGroupInfo.ReadChromatogram(_chromatogramCache); var tranInfo = chromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex); if (tranInfo.TimeIntensities == null || tranInfo.TimeIntensities.NumPoints == 0) { // Chorus returns zero length chromatogram to indicate that no spectra matched // the precursor filter. timeIntensities = null; return(false); } timeIntensities = CoalesceIntensities(tranInfo.TimeIntensities); return(true); }
private void AddChromKeys(ChromSource source, SpectrumProductFilter[] productFilters, bool highEnergy, List <ChromKey> listChromKeys) { if (null != productFilters) { var ionMobility = GetIonMobilityWindow(highEnergy); foreach (var spectrumProductFilter in productFilters) { spectrumProductFilter.FilterId = listChromKeys.Count; var key = new ChromKey(ModifiedSequence, Q1, ionMobility, spectrumProductFilter.TargetMz, 0, // CE value (Shimadzu SRM only) spectrumProductFilter.FilterWidth, source, Extractor, true, true, MinTime, MaxTime); listChromKeys.Add(key); } } }
/// <summary> /// Returns true if the two ChromKeys are close enough to match. /// Chorus sometimes rounds off the numbers of the precursor and product mz's /// of the chromatograms we ask for. /// </summary> private bool EqualsTolerant(ChromKey key1, ChromKey key2, float tolerance) { return(Equals(key1.Source, key2.Source) && Equals(key1.Target, key2.Target) && Equals(key1.Extractor, key2.Extractor) && 0 == key1.Precursor.CompareTolerant(key2.Precursor, tolerance) && 0 == key2.Product.CompareTolerant(key2.Product, tolerance)); }
public ChromData(ChromKey key, int providerId) { Key = PrimaryKey = key; ProviderId = providerId; Peaks = new List <ChromPeak>(); MaxPeakIndex = -1; }
private void AddChromKeys(ChromSource source, SpectrumProductFilter[] productFilters, bool highEnergy, List <ChromKey> listChromKeys) { if (null != productFilters) { var ionMobilityFilter = GetIonMobilityWindow(); foreach (var spectrumProductFilter in productFilters) { spectrumProductFilter.FilterId = listChromKeys.Count; var key = new ChromKey(ModifiedSequence, Q1, ionMobilityFilter.ApplyOffset(highEnergy ? spectrumProductFilter.HighEnergyIonMobilityValueOffset : 0), spectrumProductFilter.TargetMz, 0, // CE value (Shimadzu SRM only) spectrumProductFilter.FilterWidth, source, Extractor, true, true); if (_filterByTime) { key = key.ChangeOptionalTimes(_minTime, _maxTime); } listChromKeys.Add(key); } } }
public override bool GetChromatogram( int id, Target modifiedSequence, Color peptideColor, out ChromExtra extra, out TimeIntensities timeIntensities) { bool loaded = false; extra = null; timeIntensities = null; int idRemain = id; for (int iTaskList = 0; iTaskList < _chromatogramRequestProviders.Length; iTaskList++) { ChromatogramRequestProvider requestProvider = _chromatogramRequestProviders[iTaskList]; if (requestProvider.ChromKeys.Count <= idRemain) { idRemain -= requestProvider.ChromKeys.Count; continue; } ChromTaskList chromTaskList = _chromTaskLists[iTaskList]; if (null == chromTaskList) { chromTaskList = _chromTaskLists[iTaskList] = new ChromTaskList(CheckCancelled, _document, _chorusAccount, requestProvider.ChorusUrl, ChromTaskList.ChunkChromatogramRequest(requestProvider.GetChromatogramRequest(), 1000)); chromTaskList.SetMinimumSimultaneousTasks(3); } ChromKey chromKey = requestProvider.ChromKeys[idRemain]; loaded = chromTaskList.GetChromatogram(chromKey, out timeIntensities); if (loaded) { extra = new ChromExtra(id, chromKey.Precursor == 0 ? 0 : -1); if (chromKey.Precursor.IsNegative) { _sourceHasNegativePolarityData = true; } else { _sourceHasPositivePolarityData = true; } if (timeIntensities.NumPoints > 0 && Status is ChromatogramLoadingStatus) { ((ChromatogramLoadingStatus)Status).Transitions.AddTransition( modifiedSequence, peptideColor, extra.StatusId, extra.StatusRank, timeIntensities.Times, timeIntensities.Intensities); } } break; } int percentComplete = _chromTaskLists.Sum(taskList => taskList == null ? 0 : taskList.PercentComplete) / _chromTaskLists.Length; percentComplete = Math.Min(percentComplete, 99); SetPercentComplete(percentComplete); return(loaded); }
public ChromatogramDataProvider(MsDataFileImpl dataFile, ChromFileInfo fileInfo, ProgressStatus status, int startPercent, int endPercent, IProgressMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _dataFile = dataFile; if (_dataFile.IsThermoFile) { _readMaxMinutes = 4; } int len = dataFile.ChromatogramCount; _chromIndices = new int[len]; bool fixCEOptForShimadzu = dataFile.IsShimadzuFile; int indexPrecursor = -1; double lastPrecursor = 0; for (int i = 0; i < len; i++) { int index; string id = dataFile.GetChromatogramId(i, out index); if (!ChromKey.IsKeyId(id)) { continue; } var chromKey = ChromKey.FromId(id, fixCEOptForShimadzu); if (chromKey.Precursor != lastPrecursor) { lastPrecursor = chromKey.Precursor; indexPrecursor++; } var ki = new KeyValuePair <ChromKey, int>(chromKey, index); _chromIndices[index] = indexPrecursor; _chromIds.Add(ki); } // Shimadzu can't do the necessary product m/z stepping for itself. // So, they provide the CE values in their IDs and we need to adjust // product m/z values for them to support CE optimization. if (fixCEOptForShimadzu) { FixCEOptForShimadzu(); } if (_chromIds.Count == 0) { throw new NoSrmDataException(dataFile.FilePath); } SetPercentComplete(50); }
public override bool GetChromatogram( int id, string modifiedSequence, Color peptideColor, out ChromExtra extra, out float[] times, out int[] scanIndexes, out float[] intensities, out float[] massErrors) { bool loaded = false; extra = null; times = null; scanIndexes = null; intensities = null; massErrors = null; int idRemain = id; for (int iTaskList = 0; iTaskList < _chromatogramRequestProviders.Length; iTaskList++) { ChromatogramRequestProvider requestProvider = _chromatogramRequestProviders[iTaskList]; if (requestProvider.ChromKeys.Count <= idRemain) { idRemain -= requestProvider.ChromKeys.Count; continue; } ChromTaskList chromTaskList = _chromTaskLists[iTaskList]; if (null == chromTaskList) { chromTaskList = _chromTaskLists[iTaskList] = new ChromTaskList(CheckCancelled, _document, _chorusAccount, requestProvider.ChorusUrl, ChromTaskList.ChunkChromatogramRequest(requestProvider.GetChromatogramRequest(), 1000)); chromTaskList.SetMinimumSimultaneousTasks(3); } ChromKey chromKey = requestProvider.ChromKeys[idRemain]; loaded = chromTaskList.GetChromatogram(chromKey, out times, out scanIndexes, out intensities, out massErrors); if (loaded) { extra = new ChromExtra(id, chromKey.Precursor == 0 ? 0 : -1); if (times.Length > 0) { LoadingStatus.Transitions.AddTransition( modifiedSequence, peptideColor, extra.StatusId, extra.StatusRank, times, intensities); } } break; } int percentComplete = _chromTaskLists.Sum(taskList => taskList == null ? 0 : taskList.PercentComplete) / _chromTaskLists.Length; percentComplete = Math.Min(percentComplete, 99); SetPercentComplete(percentComplete); return(loaded); }
public bool GetChromatogram(ChromKey chromKey, out float[] times, out int[] scanIds, out float[] intensities, out float[] massErrors) { int keyIndex = -1; if (_chromKeyIndiceses != null) { var tolerance = (float)ChromTaskList.SrmDocument.Settings.TransitionSettings.Instrument.MzMatchTolerance; Assume.IsNull(chromKey.OptionalMinTime); Assume.IsNull(chromKey.OptionalMaxTime); Assume.IsTrue(0 == chromKey.IonMobilityValue); Assume.IsTrue(0 == chromKey.IonMobilityExtractionWidth); keyIndex = _chromKeyIndiceses.IndexOf(entry => entry.Key.CompareTolerant(chromKey, tolerance) == 0); } if (keyIndex == -1 || _chromKeyIndiceses == null) // Keep ReSharper from complaining { times = null; scanIds = null; intensities = null; massErrors = null; return(false); } ChromKeyIndices chromKeyIndices = _chromKeyIndiceses[keyIndex]; var chromGroupInfo = _chromatogramCache.LoadChromatogramInfo(chromKeyIndices.GroupIndex); chromGroupInfo.ReadChromatogram(_chromatogramCache); var tranInfo = chromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex); times = tranInfo.Times; if (times.Length == 0) { // Chorus returns zero length chromatogram to indicate that no spectra matched // the precursor filter. times = null; scanIds = null; intensities = null; massErrors = null; return(false); } if (null != tranInfo.ScanIndexes) { scanIds = tranInfo.ScanIndexes[(short)chromKeyIndices.Key.Source]; } else { scanIds = null; } intensities = tranInfo.Intensities; massErrors = null; if (tranInfo.MassError10Xs != null) { massErrors = tranInfo.MassError10Xs.Select(m => m / 10.0f).ToArray(); } CoalesceIntensities(ref times, ref scanIds, ref intensities, ref massErrors); return(true); }
public bool GetChromatogram(ChromKey chromKey, out TimeIntensities timeIntensities) { ChromatogramGeneratorTask task; if (!_chromKeys.TryGetValue(chromKey, out task)) { timeIntensities = null; return(false); } lock (LockObj) { StartTask(task); while (!task.IsFinished()) { Monitor.Wait(LockObj, CANCEL_CHECK_MILLIS); CheckCancelled(); } if (null != _exception) { throw new RemoteServerException(_exception.Message, _exception); } } return(task.GetChromatogram(chromKey, out timeIntensities)); }
public ChromatogramGeneratorTask GetGeneratorTask(ChromKey chromKey) { ChromatogramGeneratorTask task; _chromKeys.TryGetValue(chromKey, out task); return task; }
public bool GetChromatogram(ChromKey chromKey, out float[] times, out int[] scanIds, out float[] intensities, out float[] massErrors) { int keyIndex = -1; if (_chromKeyIndiceses != null) { var tolerance = (float)ChromTaskList.SrmDocument.Settings.TransitionSettings.Instrument.MzMatchTolerance; Assume.IsNull(chromKey.OptionalMinTime); Assume.IsNull(chromKey.OptionalMaxTime); Assume.IsTrue(0 == chromKey.IonMobilityValue); Assume.IsTrue(0 == chromKey.IonMobilityExtractionWidth); keyIndex = _chromKeyIndiceses.IndexOf(entry => entry.Key.CompareTolerant(chromKey, tolerance) == 0); } if (keyIndex == -1 || _chromKeyIndiceses == null) // Keep ReSharper from complaining { times = null; scanIds = null; intensities = null; massErrors = null; return false; } ChromKeyIndices chromKeyIndices = _chromKeyIndiceses[keyIndex]; var chromGroupInfo = _chromatogramCache.LoadChromatogramInfo(chromKeyIndices.GroupIndex); chromGroupInfo.ReadChromatogram(_chromatogramCache); var tranInfo = chromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex); times = tranInfo.Times; if (times.Length == 0) throw new IOException(Resources.ChromatogramGeneratorTask_GetChromatogram_Unexpected_zero_length_chromatogram_returned_from_Chorus_); if (null != tranInfo.ScanIndexes) { scanIds = tranInfo.ScanIndexes[(short) chromKeyIndices.Key.Source]; } else { scanIds = null; } intensities = tranInfo.Intensities; massErrors = null; if (tranInfo.MassError10Xs != null) massErrors = tranInfo.MassError10Xs.Select(m => m / 10.0f).ToArray(); CoalesceIntensities(ref times, ref scanIds, ref intensities, ref massErrors); return true; }
public ChromatogramDataProvider(MsDataFileImpl dataFile, ChromFileInfo fileInfo, IProgressStatus status, int startPercent, int endPercent, IProgressMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _dataFile = dataFile; if (_dataFile.IsThermoFile) { _readMaxMinutes = 4; } int len = dataFile.ChromatogramCount; _chromIndices = new int[len]; bool fixCEOptForShimadzu = dataFile.IsShimadzuFile; int indexPrecursor = -1; var lastPrecursor = SignedMz.ZERO; for (int i = 0; i < len; i++) { int index; string id = dataFile.GetChromatogramId(i, out index); if (!ChromKey.IsKeyId(id)) { continue; } var chromKey = ChromKey.FromId(id, fixCEOptForShimadzu); if (chromKey.Precursor != lastPrecursor) { lastPrecursor = chromKey.Precursor; indexPrecursor++; } var ki = new ChromKeyProviderIdPair(chromKey, index); _chromIndices[index] = indexPrecursor; _chromIds.Add(ki); } // Shimadzu can't do the necessary product m/z stepping for itself. // So, they provide the CE values in their IDs and we need to adjust // product m/z values for them to support CE optimization. if (fixCEOptForShimadzu) { FixCEOptForShimadzu(); } if (_chromIds.Count == 0) { throw new NoSrmDataException(FileInfo.FilePath); } // CONSIDER(kaipot): Some way to support mzML files converted from MIDAS wiff files _hasMidasSpectra = (dataFile.IsABFile) && SpectraChromDataProvider.HasSpectrumData(dataFile); SetPercentComplete(50); }
/// <summary> /// Add key and collector for an SRM chromatogram. /// </summary> public void AddSrmCollector(ChromKey chromKey, ChromCollector collector) { // Not allowed to use this method in the async case Assume.IsFalse(IsRunningAsync); ChromKeys.Add(chromKey); // ReSharper disable once InconsistentlySynchronizedField _collectors.Add(collector); }
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); } } }
public ChromatogramDataProvider(MsDataFileImpl dataFile, ChromFileInfo fileInfo, IProgressStatus status, int startPercent, int endPercent, IProgressMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _dataFile = dataFile; _globalChromatogramExtractor = new GlobalChromatogramExtractor(dataFile); if (_dataFile.IsThermoFile) { _readMaxMinutes = 4; } int len = dataFile.ChromatogramCount; _chromIndices = new int[len]; bool fixCEOptForShimadzu = dataFile.IsShimadzuFile; int indexPrecursor = -1; var lastPrecursor = SignedMz.ZERO; for (int i = 0; i < len; i++) { int index; string id = dataFile.GetChromatogramId(i, out index); if (!ChromKey.IsKeyId(id)) { continue; } var chromKey = ChromKey.FromId(id, fixCEOptForShimadzu); if (chromKey.Precursor != lastPrecursor) { lastPrecursor = chromKey.Precursor; indexPrecursor++; } if (chromKey.Precursor.IsNegative) { _sourceHasNegativePolarityData = true; } else { _sourceHasPositivePolarityData = true; } var ki = new ChromKeyProviderIdPair(chromKey, index); _chromIndices[index] = indexPrecursor; _chromIds.Add(ki); } // Shimadzu can't do the necessary product m/z stepping for itself. // So, they provide the CE values in their IDs and we need to adjust // product m/z values for them to support CE optimization. if (fixCEOptForShimadzu) { FixCEOptForShimadzu(); } if (_chromIds.Count == 0) { throw new NoSrmDataException(FileInfo.FilePath); } // CONSIDER: TIC and BPC are not well defined for SRM and produced chromatograms with over 100,000 points in // Agilent CE optimization data. So, keep them off for now. // foreach (int globalIndex in _globalChromatogramExtractor.GlobalChromatogramIndexes) // { // _chromIndices[globalIndex] = globalIndex; // _chromIds.Add(new ChromKeyProviderIdPair(ChromKey.FromId(_globalChromatogramExtractor.GetChromatogramId(globalIndex, out int indexId), false), globalIndex)); // } foreach (var qcTracePair in _globalChromatogramExtractor.QcTraceByIndex) { _chromIndices[qcTracePair.Key] = qcTracePair.Key; _chromIds.Add(new ChromKeyProviderIdPair(ChromKey.FromQcTrace(qcTracePair.Value), qcTracePair.Key)); } // CONSIDER(kaipot): Some way to support mzML files converted from MIDAS wiff files _hasMidasSpectra = (dataFile.IsABFile) && SpectraChromDataProvider.HasSpectrumData(dataFile); _ionMobilityUnits = dataFile.IonMobilityUnits; _hasIonMobilityCombined = dataFile.HasCombinedIonMobilitySpectra; // When true, data source provides IMS data in 3-array format, which affects spectrum ID format SetPercentComplete(50); }
/// <summary> /// Decides what information from a ChromatogramGroupInfo should be thrown away. /// ChromatogramGroupInfo's can have the the retention time range shortened, and certain /// transitions discarded. /// </summary> private MinimizedChromGroup MinimizeChromGroup(Settings settings, ChromatogramGroupInfo chromatogramGroupInfo, IList <TransitionGroupDocNode> transitionGroups) { var fileIndexes = new List <int>(); for (int fileIndex = 0; fileIndex < Document.Settings.MeasuredResults.Chromatograms.Count; fileIndex++) { var chromatogramSet = Document.Settings.MeasuredResults.Chromatograms[fileIndex]; if (chromatogramSet.MSDataFilePaths.Any(path => Equals(path, chromatogramGroupInfo.FilePath))) { fileIndexes.Add(fileIndex); } } var chromatograms = chromatogramGroupInfo.TransitionPointSets.ToArray(); Assume.IsTrue(Equals(chromatogramGroupInfo.NumTransitions, chromatograms.Length)); var keptTransitionIndexes = new List <int>(); double minRetentionTime = Double.MaxValue; double maxRetentionTime = -Double.MaxValue; for (int i = 0; i < chromatograms.Length; i++) { var chromatogram = chromatograms[i]; var matchingTransitions = new List <TransitionDocNode>(); foreach (var transitionDocNode in transitionGroups.SelectMany(tg => tg.Transitions)) { if (0 != ChromKey.CompareTolerant((float)chromatogram.ProductMz, (float)transitionDocNode.Mz, _tolerance)) { continue; } matchingTransitions.Add(transitionDocNode); foreach (var fileIndex in fileIndexes) { var chromatogramSet = transitionDocNode.Results[fileIndex]; if (chromatogramSet == null) { continue; } foreach (var transitionChromInfo in chromatogramSet) { if (transitionChromInfo.IsEmpty) { continue; } minRetentionTime = Math.Min(minRetentionTime, transitionChromInfo.StartRetentionTime); maxRetentionTime = Math.Max(maxRetentionTime, transitionChromInfo.EndRetentionTime); } } } bool kept = !settings.DiscardUnmatchedChromatograms || matchingTransitions.Count > 0; if (kept) { keptTransitionIndexes.Add(i); } } var result = new MinimizedChromGroup(chromatogramGroupInfo.Header) { RetainedTransitionIndexes = keptTransitionIndexes, }; if (settings.NoiseTimeRange.HasValue && minRetentionTime < maxRetentionTime) { if (null == chromatogramGroupInfo.Times) { // Chromatogram was unreadable. result.RetainedTransitionIndexes.Clear(); } else { result.SetStartEndTime(chromatogramGroupInfo.Times, (float)(minRetentionTime - settings.NoiseTimeRange), (float)(maxRetentionTime + settings.NoiseTimeRange)); } } return(result); }
public bool GetChromatogram(ChromKey chromKey, out float[] times, out int[] scanIds, out float[] intensities, out float[] massErrors) { ChromatogramGeneratorTask task; if (!_chromKeys.TryGetValue(chromKey, out task)) { times = null; intensities = null; massErrors = null; scanIds = null; return false; } lock (LockObj) { StartTask(task); while (!task.IsFinished()) { Monitor.Wait(LockObj, CANCEL_CHECK_MILLIS); CheckCancelled(); } if (null != _exception) { throw new ChorusServerException(_exception.Message, _exception); } } return task.GetChromatogram(chromKey, out times, out scanIds, out intensities, out massErrors); }