Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        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);
        }