public void Dispose() { if (_msDataFileScanHelper != null) { _msDataFileScanHelper.Dispose(); _msDataFileScanHelper = null; } }
/// <summary> /// Looks through the result and finds ion mobility values. /// Note that this method only returns new values that were found in results. /// The returned dictionary should be merged with the existing values in /// order to preserve those existing values. /// </summary> public Dictionary <LibKey, IonMobilityAndCCS> FindIonMobilityPeaks() { // Overwrite any existing measurements with newly derived ones var measured = new Dictionary <LibKey, IonMobilityAndCCS>(); if (_document.Settings.MeasuredResults == null) { return(measured); } var filepaths = _document.Settings.MeasuredResults.MSDataFilePaths.ToArray(); _totalSteps = filepaths.Length * _document.MoleculeTransitionGroupCount; if (_totalSteps == 0) { return(measured); } using (_msDataFileScanHelper = new MsDataFileScanHelper(SetScans, HandleLoadScanException)) { // // Avoid opening and re-opening raw files - make these the outer loop // _ms1IonMobilities = new Dictionary <LibKey, List <IonMobilityIntensityPair> >(); _ms2IonMobilities = new Dictionary <LibKey, List <IonMobilityIntensityPair> >(); var twopercent = (int)Math.Ceiling(_totalSteps * 0.02); _totalSteps += twopercent; _currentStep = twopercent; if (_progressMonitor != null) { _progressStatus = new ProgressStatus(filepaths.First().GetFileName()); _progressStatus = _progressStatus.UpdatePercentCompleteProgress(_progressMonitor, _currentStep, _totalSteps); // Make that inital lag seem less dismal to the user } foreach (var fp in filepaths) { if (!ProcessFile(fp)) { return(null); // User cancelled } } // Find ion mobilities based on MS1 data foreach (var dt in _ms1IonMobilities) { // Choose the ion mobility which gave the largest signal // CONSIDER: average IM and CCS values that fall "near" the IM of largest signal? var ms1IonMobility = dt.Value.OrderByDescending(p => p.Intensity).First().IonMobility; // Check for MS2 data to use for high energy offset List <IonMobilityIntensityPair> listDt; var ms2IonMobility = _ms2IonMobilities.TryGetValue(dt.Key, out listDt) ? listDt.OrderByDescending(p => p.Intensity).First().IonMobility : ms1IonMobility; var value = IonMobilityAndCCS.GetIonMobilityAndCCS(ms1IonMobility.IonMobility, ms1IonMobility.CollisionalCrossSectionSqA, ms2IonMobility.IonMobility.Mobility.Value - ms1IonMobility.IonMobility.Mobility.Value); if (!measured.ContainsKey(dt.Key)) { measured.Add(dt.Key, value); } else { measured[dt.Key] = value; } } // Check for data for which we have only MS2 to go on foreach (var im in _ms2IonMobilities) { if (!_ms1IonMobilities.ContainsKey(im.Key)) { // Only MS2 ion mobility values found, use that as a reasonable inference of MS1 ion mobility var driftTimeIntensityPair = im.Value.OrderByDescending(p => p.Intensity).First(); var value = driftTimeIntensityPair.IonMobility; // Note collisional cross section if (_msDataFileScanHelper.ProvidesCollisionalCrossSectionConverter) { var mz = im.Key.PrecursorMz ?? GetMzFromDocument(im.Key); var ccs = _msDataFileScanHelper.CCSFromIonMobility(value.IonMobility, mz, im.Key.Charge); if (ccs.HasValue) { value = IonMobilityAndCCS.GetIonMobilityAndCCS(value.IonMobility, ccs, value.HighEnergyIonMobilityValueOffset); } } if (!measured.ContainsKey(im.Key)) { measured.Add(im.Key, value); } else { measured[im.Key] = value; } } } } return(measured); }
private bool ProcessMSLevel(MsDataFileUri filePath, int msLevel, IEnumerable <ChromatogramInfo> transitionPointSets, ChromatogramGroupInfo chromInfo, double?apexRT, TransitionGroupDocNode nodeGroup, LibKey libKey, float tolerance) { var transitions = new List <TransitionFullScanInfo>(); var chromSource = (msLevel == 1) ? ChromSource.ms1 : ChromSource.fragment; IList <float> times = null; foreach (var tranPointSet in transitionPointSets.Where(t => t.Source == chromSource)) { transitions.Add(new TransitionFullScanInfo { //Name = tranPointSet.Header., Source = chromSource, TimeIntensities = tranPointSet.TimeIntensities, PrecursorMz = chromInfo.PrecursorMz, ProductMz = tranPointSet.ProductMz, ExtractionWidth = tranPointSet.ExtractionWidth, //Id = nodeTran.Id }); times = tranPointSet.Times; } if (!transitions.Any()) { return(true); // Nothing to do at this ms level } IScanProvider scanProvider = new ScanProvider(_documentFilePath, filePath, chromSource, times, transitions.ToArray(), _document.Settings.MeasuredResults, () => _document.Settings.MeasuredResults.LoadMSDataFileScanIds(filePath)); // Across all spectra at the peak retention time, find the one with max total // intensity for the mz's of interest (ie the isotopic distribution) and note its ion mobility. var scanIndex = MsDataFileScanHelper.FindScanIndex(times, apexRT.Value); _msDataFileScanHelper.UpdateScanProvider(scanProvider, 0, scanIndex); _msDataFileScanHelper.MsDataSpectra = null; // Reset scanIndex = _msDataFileScanHelper.GetScanIndex(); _msDataFileScanHelper.ScanProvider.SetScanForBackgroundLoad(scanIndex); lock (this) { while (_msDataFileScanHelper.MsDataSpectra == null && _dataFileScanHelperException == null) { if (_progressMonitor != null && _progressMonitor.IsCanceled) { return(false); } Monitor.Wait(this, 500); // Let background loader do its thing } } if (_dataFileScanHelperException != null) { throw new IOException(TextUtil.LineSeparate(Resources.DriftTimeFinder_HandleLoadScanException_Problem_using_results_to_populate_drift_time_library__, _dataFileScanHelperException.Message), _dataFileScanHelperException); } if (_progressMonitor != null && !ReferenceEquals(nodeGroup, _currentDisplayedTransitionGroupDocNode)) { // Do this after scan load so first group after file switch doesn't seem laggy _progressStatus = _progressStatus.ChangeMessage(TextUtil.LineSeparate(filePath.GetFileName(), nodeGroup.ToString())). UpdatePercentCompleteProgress(_progressMonitor, _currentStep++, _totalSteps); _currentDisplayedTransitionGroupDocNode = nodeGroup; } EvaluateBestIonMobilityValue(msLevel, libKey, tolerance, transitions); return(true); }
public Dictionary <LibKey, DriftTimeInfo> FindDriftTimePeaks() { // Overwrite any existing measurements with newly derived ones var measured = new Dictionary <LibKey, DriftTimeInfo>(); if (_existing != null && _existing.MeasuredDriftTimePeptides != null) { foreach (var existingPair in _existing.MeasuredDriftTimePeptides) { measured.Add(existingPair.Key, existingPair.Value); } } var filepaths = _document.Settings.MeasuredResults.MSDataFilePaths.ToArray(); _totalSteps = filepaths.Length * _document.MoleculeTransitionGroupCount; if (_totalSteps == 0) { return(measured); } using (_msDataFileScanHelper = new MsDataFileScanHelper(SetScans, HandleLoadScanException)) { // // Avoid opening and re-opening raw files - make these the outer loop // _ms1DriftTimes = new Dictionary <LibKey, List <DriftTimeIntensityPair> >(); _ms2DriftTimes = new Dictionary <LibKey, List <DriftTimeIntensityPair> >(); var twopercent = (int)Math.Ceiling(_totalSteps * 0.02); _totalSteps += twopercent; _currentStep = twopercent; if (_progressMonitor != null) { _progressStatus = new ProgressStatus(filepaths.First().GetFileName()); _progressStatus = _progressStatus.UpdatePercentCompleteProgress(_progressMonitor, _currentStep, _totalSteps); // Make that inital lag seem less dismal to the user } foreach (var fp in filepaths) { if (!ProcessFile(fp)) { return(null); // User cancelled } } // Find drift times based on MS1 data foreach (var dt in _ms1DriftTimes) { // Choose the drift time which gave the largest signal var ms1DriftTime = dt.Value.OrderByDescending(p => p.Intensity).First().DriftTime; // Check for MS2 data to use for high energy offset List <DriftTimeIntensityPair> listDt; var ms2DriftTime = _ms2DriftTimes.TryGetValue(dt.Key, out listDt) ? listDt.OrderByDescending(p => p.Intensity).First().DriftTime : (ms1DriftTime ?? 0); var value = new DriftTimeInfo(ms1DriftTime, ms2DriftTime - ms1DriftTime ?? 0); if (!measured.ContainsKey(dt.Key)) { measured.Add(dt.Key, value); } else { measured[dt.Key] = value; } } // Check for data for which we have only MS2 to go on foreach (var dt in _ms2DriftTimes) { if (!_ms1DriftTimes.ContainsKey(dt.Key)) { // Only MS2 drift times found, use that var value = new DriftTimeInfo(dt.Value.OrderByDescending(p => p.Intensity).First().DriftTime, 0); if (!measured.ContainsKey(dt.Key)) { measured.Add(dt.Key, value); } else { measured[dt.Key] = value; } } } } return(measured); }