예제 #1
0
        private void DoValidate()
        {
            TransitionFullScan.ValidateRange(Start, TransitionFullScan.MIN_PRECURSOR_MULTI_FILTER, TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER,
                                             Resources.IsolationWindow_DoValidate_Isolation_window_Start_must_be_between__0__and__1__);
            TransitionFullScan.ValidateRange(End, TransitionFullScan.MIN_PRECURSOR_MULTI_FILTER, TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER,
                                             Resources.IsolationWindow_DoValidate_Isolation_window_End_must_be_between__0__and__1__);

            if (Start >= End)
            {
                throw new InvalidDataException(Resources.IsolationWindow_DoValidate_Isolation_window_Start_value_is_greater_than_the_End_value);
            }
            if (Target.HasValue && (Target.Value < Start || Target.Value >= End))
            {
                throw new InvalidDataException(Resources.IsolationWindow_DoValidate_Target_value_is_not_within_the_range_of_the_isolation_window);
            }
            if (StartMargin.HasValue)
            {
                if (StartMargin.Value < 0)
                {
                    throw new InvalidDataException(Resources.IsolationWindow_DoValidate_Isolation_window_margin_must_be_non_negative);
                }
                if (EndMargin.HasValue)
                {
                    if (EndMargin.Value < 0)
                    {
                        throw new InvalidDataException(Resources.IsolationWindow_DoValidate_Isolation_window_margin_must_be_non_negative);
                    }
                }
                if (IsolationStart >= IsolationEnd)
                {
                    // If the margins are too large, clipping at the ends of the instrument range may result in no useable window area.
                    throw new InvalidDataException(Resources.IsolationWindow_DoValidate_Isolation_window_margins_cover_the_entire_isolation_window_at_the_extremes_of_the_instrument_range);
                }
            }
        }
예제 #2
0
        private void DoValidate()
        {
            SpecialHandlingType.Validate(SpecialHandling);

            if (PrecursorFilter != null)
            {
                if (PrespecifiedIsolationWindows.Count > 0)
                {
                    throw new InvalidDataException(Resources.IsolationScheme_DoValidate_Isolation_scheme_cannot_have_a_filter_and_a_prespecifed_isolation_window);
                }
                TransitionFullScan.ValidateRange(PrecursorFilter,
                                                 TransitionFullScan.MIN_PRECURSOR_MULTI_FILTER,
                                                 TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER,
                                                 Resources.IsolationScheme_DoValidate_The_precursor_m_z_filter_must_be_between__0__and__1_);
                if (PrecursorRightFilter.HasValue)
                {
                    TransitionFullScan.ValidateRange(PrecursorRightFilter,
                                                     TransitionFullScan.MIN_PRECURSOR_MULTI_FILTER,
                                                     TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER,
                                                     Resources.IsolationScheme_DoValidate_The_precursor_m_z_filter_must_be_between__0__and__1_);
                }
                if (WindowsPerScan.HasValue)
                {
                    throw new InvalidDataException(Resources.IsolationScheme_DoValidate_Isolation_scheme_can_specify_multiplexed_windows_only_for_prespecified_isolation_windows);
                }
            }

            else if (PrecursorRightFilter != null)
            {
                throw new InvalidDataException(Resources.IsolationScheme_DoValidate_Isolation_scheme_cannot_have_a_right_filter_without_a_left_filter);
            }

            else
            {
                if (PrespecifiedIsolationWindows.Count != 0 && IsAllIons)
                {
                    throw new InvalidDataException(Resources.IsolationScheme_DoValidate_Isolation_scheme_for_all_ions_cannot_contain_isolation_windows);
                }

                if (Equals(SpecialHandling, SpecialHandlingType.MULTIPLEXED))
                {
                    if (!WindowsPerScan.HasValue || WindowsPerScan.Value < 1)
                    {
                        throw new InvalidDataException(Resources.IsolationScheme_DoValidate_Multiplexed_windows_require_at_least_one_window_per_scan);
                    }
                    if (PrespecifiedIsolationWindows.Count % WindowsPerScan.Value != 0)
                    {
                        throw new InvalidDataException(Resources.IsolationScheme_DoValidate_The_number_of_prespecified_isolation_windows_must_be_a_multiple_of_the_windows_per_scan_in_multiplexed_sampling);
                    }
                }
                else
                {
                    if (WindowsPerScan.HasValue)
                    {
                        throw new InvalidDataException(Resources.IsolationScheme_DoValidate_Windows_per_scan_requires_multiplexed_isolation_windows);
                    }
                }
            }
        }
        private void comboPrecursorIsotopes_SelectedIndexChanged(object sender, EventArgs e)
        {
            var precursorIsotopes = PrecursorIsotopesCurrent;

            bool percentType = (precursorIsotopes == FullScanPrecursorIsotopes.Percent);

            labelPrecursorIsotopeFilter.Text = percentType
                                                   ? Resources.TransitionSettingsUI_comboPrecursorIsotopes_SelectedIndexChanged_Min_percent_of_base_peak
                                                   : Resources.TransitionSettingsUI_comboPrecursorIsotopes_SelectedIndexChanged_Peaks;
            labelPrecursorIsotopeFilterPercent.Visible = percentType;

            if (precursorIsotopes == FullScanPrecursorIsotopes.None)
            {
                textPrecursorIsotopeFilter.Text    = string.Empty;
                textPrecursorIsotopeFilter.Enabled = false;
                comboEnrichments.SelectedIndex     = -1;
                comboEnrichments.Enabled           = false;
                // Selection change should set filter m/z textbox correctly
                comboPrecursorAnalyzerType.SelectedIndex = -1;
                comboPrecursorAnalyzerType.Enabled       = false;
            }
            else
            {
                // If the combo is being set to the type it started with, use the starting values
                if (precursorIsotopes == FullScan.PrecursorIsotopes)
                {
                    textPrecursorIsotopeFilter.Text = FullScan.PrecursorIsotopeFilter.HasValue
                                                          ? FullScan.PrecursorIsotopeFilter.Value.ToString(LocalizationHelper.CurrentCulture)
                                                          : string.Empty;
                    if (FullScan.IsotopeEnrichments != null)
                    {
                        comboEnrichments.SelectedItem = FullScan.IsotopeEnrichments.Name;
                    }
                    if (!comboPrecursorAnalyzerType.Enabled)
                    {
                        comboPrecursorAnalyzerType.SelectedItem = TransitionFullScan.MassAnalyzerToString(FullScan.PrecursorMassAnalyzer);
                    }
                }
                else
                {
                    textPrecursorIsotopeFilter.Text = (percentType
                                                           ? TransitionFullScan.DEFAULT_ISOTOPE_PERCENT
                                                           : TransitionFullScan.DEFAULT_ISOTOPE_COUNT).ToString(LocalizationHelper.CurrentCulture);

                    var precursorMassAnalyzer = PrecursorMassAnalyzer;
                    if (!comboPrecursorAnalyzerType.Enabled || (percentType && precursorMassAnalyzer == FullScanMassAnalyzerType.qit))
                    {
                        comboPrecursorAnalyzerType.SelectedItem = TransitionFullScan.MassAnalyzerToString(FullScanMassAnalyzerType.tof);
                        comboEnrichments.SelectedItem           = IsotopeEnrichmentsList.GetDefault().Name;
                    }
                }

                comboEnrichments.Enabled           = (comboEnrichments.SelectedIndex != -1);
                textPrecursorIsotopeFilter.Enabled = true;
                comboPrecursorAnalyzerType.Enabled = true;
            }
            UpdateRetentionTimeFilterUi();
        }
예제 #4
0
 private bool IsProfileMode(ComboBox comboAnalyzerType)
 {
     if (comboAnalyzerType.Visible && comboAnalyzerType.Enabled)
     {
         var analyzerType = TransitionFullScan.ParseMassAnalyzer((string)comboAnalyzerType.SelectedItem);
         return(analyzerType != FullScanMassAnalyzerType.centroided && analyzerType != FullScanMassAnalyzerType.none);
     }
     return(false);
 }
예제 #5
0
 public ImportPeptideSearchSettings(
     ImportResultsSettings importResultsSettings,
     MatchModificationsControl.MatchModificationsSettings modificationsSettings,
     TransitionSettingsControl.TransitionFilterAndLibrariesSettings filterAndLibSettings,
     TransitionFullScan fullScanSettings, ImportFastaControl.ImportFastaSettings importFastaSettings)
 {
     ImportResultsSettings      = importResultsSettings;
     ModificationsSettings      = modificationsSettings;
     FilterAndLibrariesSettings = filterAndLibSettings;
     FullScanSettings           = fullScanSettings;
     ImportFastaSettings        = importFastaSettings;
 }
예제 #6
0
 public ImportPeptideSearchSettings(
     ImportResultsSettings importResultsSettings,
     MatchModificationsControl.MatchModificationsSettings modificationsSettings,
     TransitionSettingsControl.TransitionFilterAndLibrariesSettings filterAndLibSettings,
     TransitionFullScan fullScanSettings, ImportFastaControl.ImportFastaSettings importFastaSettings,
     SrmDocument.DOCUMENT_TYPE docType)
 {
     ImportResultsSettings      = importResultsSettings;
     ModificationsSettings      = modificationsSettings;
     FilterAndLibrariesSettings = filterAndLibSettings;
     FullScanSettings           = fullScanSettings;
     ImportFastaSettings        = importFastaSettings;
     _docType = docType;
 }
        private void comboAcquisitionMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            var acquisitionMethod = AcquisitionMethod;

            if (acquisitionMethod == FullScanAcquisitionMethod.None)
            {
                EnableIsolationScheme(false);
                // Selection change should set filter m/z textbox correctly
                comboProductAnalyzerType.SelectedIndex = -1;
                comboProductAnalyzerType.Enabled       = false;
                comboIsolationScheme.SelectedIndex     = -1;
                comboIsolationScheme.Enabled           = false;
            }
            else
            {
                EnableIsolationScheme(acquisitionMethod == FullScanAcquisitionMethod.DIA);

                // If the combo is being set to the type it started with, use the starting values
                if (acquisitionMethod == FullScan.AcquisitionMethod)
                {
                    if (!comboProductAnalyzerType.Enabled)
                    {
                        comboProductAnalyzerType.SelectedItem = TransitionFullScan.MassAnalyzerToString(FullScan.ProductMassAnalyzer);
                    }
                }
                else
                {
                    if (!comboProductAnalyzerType.Enabled)
                    {
                        string tofAnalyzer = TransitionFullScan.MassAnalyzerToString(FullScanMassAnalyzerType.tof);
                        comboProductAnalyzerType.SelectedItem =
                            comboPrecursorAnalyzerType.SelectedItem != null &&
                            Equals(comboPrecursorAnalyzerType.SelectedItem.ToString(), tofAnalyzer)
                            ? tofAnalyzer
                            : TransitionFullScan.MassAnalyzerToString(FullScanMassAnalyzerType.qit);
                    }
                }
                comboProductAnalyzerType.Enabled = true;
            }
            UpdateRetentionTimeFilterUi();
        }
예제 #8
0
        private void comboAcquisitionMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            var acquisitionMethod = AcquisitionMethod;

            if (acquisitionMethod == FullScanAcquisitionMethod.None)
            {
                EnableIsolationScheme(false);
                // Selection change should set filter m/z textbox correctly
                comboProductAnalyzerType.SelectedIndex = -1;
                comboProductAnalyzerType.Enabled       = false;
                comboIsolationScheme.SelectedIndex     = -1;
                comboIsolationScheme.Enabled           = false;
            }
            else
            {
                EnableIsolationScheme(acquisitionMethod == FullScanAcquisitionMethod.DIA);

                // If the combo is being set to the type it started with, use the starting values
                if (acquisitionMethod == FullScan.AcquisitionMethod)
                {
                    if (!comboProductAnalyzerType.Enabled)
                    {
                        comboProductAnalyzerType.SelectedItem = TransitionFullScan.MassAnalyzerToString(FullScan.ProductMassAnalyzer);
                    }
                }
                else
                {
                    if (!comboProductAnalyzerType.Enabled)
                    {
                        comboProductAnalyzerType.SelectedItem =
                            comboPrecursorAnalyzerType.SelectedItem != null
                                ? comboPrecursorAnalyzerType.SelectedItem.ToString()
                                : TransitionFullScan.MassAnalyzerToString(FullScanMassAnalyzerType.centroided);
                    }
                }
                comboProductAnalyzerType.Enabled = true;
            }
            FullScanEnabledChanged?.Invoke(new FullScanEnabledChangeEventArgs(null, comboProductAnalyzerType.Enabled));// Fire event so Filter iontypes settings can update as needed
            UpdateRetentionTimeFilterUi();
        }
예제 #9
0
 private SrmDocument ChangeFullScanSettings(SrmDocument document, TransitionFullScan transitionFullScan)
 {
     return(document.ChangeSettings(
                document.Settings.ChangeTransitionSettings(
                    document.Settings.TransitionSettings.ChangeFullScan(transitionFullScan))));
 }
예제 #10
0
        public bool ValidateFullScanSettings(MessageBoxHelper helper, out TransitionFullScan fullScanSettings, TabControl tabControl = null, int tabIndex = -1)
        {
            fullScanSettings = null;

            double?precursorIsotopeFilter;

            if (!ValidatePrecursorIsotopeFilter(helper, out precursorIsotopeFilter, tabControl, tabIndex))
            {
                return(false);
            }

            double?precursorRes;

            if (!ValidatePrecursorRes(helper, precursorIsotopeFilter, out precursorRes, tabControl, tabIndex))
            {
                return(false);
            }

            double?precursorResMz;

            if (!ValidatePrecursorResMz(helper, out precursorResMz, tabControl, tabIndex))
            {
                return(false);
            }

            double?productRes;

            if (!ValidateProductRes(helper, out productRes, tabControl, tabIndex))
            {
                return(false);
            }

            double?productResMz;

            if (!ValidateProductResMz(helper, out productResMz, tabControl, tabIndex))
            {
                return(false);
            }

            RetentionTimeFilterType retentionTimeFilterType = RetentionTimeFilterType;
            double retentionTimeFilterLength;

            if (!ValidateRetentionTimeFilterLength(out retentionTimeFilterLength))
            {
                return(false);
            }

            fullScanSettings = new TransitionFullScan(AcquisitionMethod,
                                                      IsolationScheme,
                                                      ProductMassAnalyzer,
                                                      productRes,
                                                      productResMz,
                                                      PrecursorIsotopesCurrent,
                                                      precursorIsotopeFilter,
                                                      PrecursorMassAnalyzer,
                                                      precursorRes,
                                                      precursorResMz,
                                                      UseSelectiveExtraction,
                                                      Enrichments,
                                                      retentionTimeFilterType,
                                                      retentionTimeFilterLength);
            return(true);
        }
예제 #11
0
        public SpectrumFilter(SrmDocument document, MsDataFileUri msDataFileUri, IFilterInstrumentInfo instrumentInfo,
                              IRetentionTimePredictor retentionTimePredictor = null, bool firstPass = false)
        {
            _fullScan          = document.Settings.TransitionSettings.FullScan;
            _instrument        = document.Settings.TransitionSettings.Instrument;
            _acquisitionMethod = _fullScan.AcquisitionMethod;
            if (instrumentInfo != null)
            {
                _isWatersFile = instrumentInfo.IsWatersFile;
            }
            IsFirstPass = firstPass;

            var comparer = PrecursorTextId.PrecursorTextIdComparerInstance;
            var dictPrecursorMzToFilter = new SortedDictionary <PrecursorTextId, SpectrumFilterPair>(comparer);

            if (EnabledMs || EnabledMsMs)
            {
                if (EnabledMs)
                {
                    _isHighAccMsFilter = !Equals(_fullScan.PrecursorMassAnalyzer,
                                                 FullScanMassAnalyzerType.qit);

                    if (!firstPass)
                    {
                        var key = new PrecursorTextId(SignedMz.ZERO, null, ChromExtractor.summed);  // TIC
                        dictPrecursorMzToFilter.Add(key, new SpectrumFilterPair(key, PeptideDocNode.UNKNOWN_COLOR, dictPrecursorMzToFilter.Count,
                                                                                _instrument.MinTime, _instrument.MaxTime, null, null, 0, _isHighAccMsFilter, _isHighAccProductFilter));
                        key = new PrecursorTextId(SignedMz.ZERO, null, ChromExtractor.base_peak);   // BPC
                        dictPrecursorMzToFilter.Add(key, new SpectrumFilterPair(key, PeptideDocNode.UNKNOWN_COLOR, dictPrecursorMzToFilter.Count,
                                                                                _instrument.MinTime, _instrument.MaxTime, null, null, 0, _isHighAccMsFilter, _isHighAccProductFilter));
                    }
                }
                if (EnabledMsMs)
                {
                    _isHighAccProductFilter = !Equals(_fullScan.ProductMassAnalyzer,
                                                      FullScanMassAnalyzerType.qit);

                    if (_fullScan.AcquisitionMethod == FullScanAcquisitionMethod.DIA &&
                        _fullScan.IsolationScheme.IsAllIons)
                    {
                        if (instrumentInfo != null)
                        {
                            _isWatersMse  = _isWatersFile;
                            _isAgilentMse = instrumentInfo.IsAgilentFile;
                        }
                        _mseLevel = 1;
                    }
                }

                Func <double, double> calcWindowsQ1 = _fullScan.GetPrecursorFilterWindow;
                Func <double, double> calcWindowsQ3 = _fullScan.GetProductFilterWindow;
                _minTime = _instrument.MinTime;
                _maxTime = _instrument.MaxTime;
                bool canSchedule = CanSchedule(document, retentionTimePredictor);
                // TODO: Figure out a way to turn off time sharing on first SIM scan so that
                //       times can be shared for MS1 without SIM scans
                _isSharedTime = !canSchedule;

                // If we're using bare measured drift times from spectral libraries, go get those now
                var libraryIonMobilityInfo = document.Settings.PeptideSettings.Prediction.UseLibraryDriftTimes
                    ? document.Settings.GetIonMobilities(msDataFileUri)
                    : null;

                foreach (var nodePep in document.Molecules)
                {
                    if (firstPass && !retentionTimePredictor.IsFirstPassPeptide(nodePep))
                    {
                        continue;
                    }

                    foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
                    {
                        if (nodeGroup.Children.Count == 0)
                        {
                            continue;
                        }

                        double?       minTime = _minTime, maxTime = _maxTime;
                        double?       startDriftTimeMsec = null, endDriftTimeMsec = null;
                        double        windowDT;
                        double        highEnergyDriftTimeOffsetMsec = 0;
                        DriftTimeInfo centerDriftTime               = document.Settings.PeptideSettings.Prediction.GetDriftTime(
                            nodePep, nodeGroup, libraryIonMobilityInfo, out windowDT);
                        if (centerDriftTime.DriftTimeMsec(false).HasValue)
                        {
                            startDriftTimeMsec            = centerDriftTime.DriftTimeMsec(false) - windowDT / 2; // Get the low energy drift time
                            endDriftTimeMsec              = startDriftTimeMsec + windowDT;
                            highEnergyDriftTimeOffsetMsec = centerDriftTime.HighEnergyDriftTimeOffsetMsec;
                        }

                        if (canSchedule)
                        {
                            if (RetentionTimeFilterType.scheduling_windows == _fullScan.RetentionTimeFilterType)
                            {
                                double?centerTime = null;
                                double windowRT   = 0;
                                if (retentionTimePredictor != null)
                                {
                                    centerTime = retentionTimePredictor.GetPredictedRetentionTime(nodePep);
                                }
                                else
                                {
                                    var prediction = document.Settings.PeptideSettings.Prediction;
                                    if (prediction.RetentionTime == null || !prediction.RetentionTime.IsAutoCalculated)
                                    {
                                        centerTime = document.Settings.PeptideSettings.Prediction.PredictRetentionTimeForChromImport(
                                            document, nodePep, nodeGroup, out windowRT);
                                    }
                                }
                                // Force the center time to be at least zero
                                if (centerTime.HasValue && centerTime.Value < 0)
                                {
                                    centerTime = 0;
                                }
                                if (_fullScan.RetentionTimeFilterLength != 0)
                                {
                                    windowRT = _fullScan.RetentionTimeFilterLength * 2;
                                }
                                if (centerTime != null)
                                {
                                    double startTime = centerTime.Value - windowRT / 2;
                                    double endTime   = startTime + windowRT;
                                    minTime = Math.Max(minTime ?? 0, startTime);
                                    maxTime = Math.Min(maxTime ?? double.MaxValue, endTime);
                                }
                            }
                            else if (RetentionTimeFilterType.ms2_ids == _fullScan.RetentionTimeFilterType)
                            {
                                var times = document.Settings.GetBestRetentionTimes(nodePep, msDataFileUri);
                                if (times.Length > 0)
                                {
                                    minTime = Math.Max(minTime ?? 0, times.Min() - _fullScan.RetentionTimeFilterLength);
                                    maxTime = Math.Min(maxTime ?? double.MaxValue, times.Max() + _fullScan.RetentionTimeFilterLength);
                                }
                            }
                        }

                        SpectrumFilterPair filter;
                        string             textId = nodePep.RawTextId; // Modified Sequence for peptides, or some other string for custom ions
                        var mz  = new SignedMz(nodeGroup.PrecursorMz, nodeGroup.PrecursorCharge < 0);
                        var key = new PrecursorTextId(mz, textId, ChromExtractor.summed);
                        if (!dictPrecursorMzToFilter.TryGetValue(key, out filter))
                        {
                            filter = new SpectrumFilterPair(key, nodePep.Color, dictPrecursorMzToFilter.Count, minTime, maxTime,
                                                            startDriftTimeMsec, endDriftTimeMsec, highEnergyDriftTimeOffsetMsec,
                                                            _isHighAccMsFilter, _isHighAccProductFilter);
                            dictPrecursorMzToFilter.Add(key, filter);
                        }

                        if (!EnabledMs)
                        {
                            filter.AddQ3FilterValues(from TransitionDocNode nodeTran in nodeGroup.Children
                                                     select nodeTran.Mz, calcWindowsQ3);
                        }
                        else if (!EnabledMsMs)
                        {
                            filter.AddQ1FilterValues(GetMS1MzValues(nodeGroup), calcWindowsQ1);
                        }
                        else
                        {
                            filter.AddQ1FilterValues(GetMS1MzValues(nodeGroup), calcWindowsQ1);
                            filter.AddQ3FilterValues(from TransitionDocNode nodeTran in nodeGroup.Children
                                                     where !nodeTran.IsMs1
                                                     select nodeTran.Mz, calcWindowsQ3);
                        }
                    }
                }
                _filterMzValues = dictPrecursorMzToFilter.Values.ToArray();

                var listChromKeyFilterIds = new List <ChromKey>();
                foreach (var spectrumFilterPair in _filterMzValues)
                {
                    spectrumFilterPair.AddChromKeys(listChromKeyFilterIds);
                }
                _productChromKeys = listChromKeyFilterIds.ToArray();

                // Sort a copy of the filter pairs by maximum retention time so that we can detect when
                // filters are no longer active.
                _filterRTValues = new SpectrumFilterPair[_filterMzValues.Length];
                Array.Copy(_filterMzValues, _filterRTValues, _filterMzValues.Length);
                Array.Sort(_filterRTValues, CompareByRT);
            }

            InitRTLimits();
        }
예제 #12
0
 private SrmDocument ChangeFullScanSettings(SrmDocument document, TransitionFullScan transitionFullScan)
 {
     return document.ChangeSettings(
         document.Settings.ChangeTransitionSettings(
             document.Settings.TransitionSettings.ChangeFullScan(transitionFullScan)));
 }
예제 #13
0
 private static bool IsOnlyMsEnabled(TransitionFullScan fullScan)
 {
     return fullScan.IsEnabledMs && !fullScan.IsEnabledMsMs;
 }
예제 #14
0
 public static bool IsMultipleIonSources(TransitionFullScan fullScan, TransitionGroupDocNode nodeGroup)
 {
     return fullScan.IsEnabledMs &&
            (fullScan.IsEnabledMsMs ||
                 (nodeGroup != null && nodeGroup.Transitions.Contains(nodeTran => !nodeTran.IsMs1)));
 }
예제 #15
0
        /// <summary>
        /// Constructor for an IsotopeDistInfo using TransitionFullScanSettings
        /// </summary>
        public static IsotopeDistInfo MakeIsotopeDistInfo(MassDistribution mzDistribution, TypedMass monoisotopicMass, Adduct adduct, TransitionFullScan fullScan)
        {
            // Centering resolution must be inversely proportional to charge state
            // High charge states can bring major peaks close enough together to
            // cause them to be combined and centered in isotope distribution valleys
            double massResolution = TransitionFullScan.ISOTOPE_PEAK_CENTERING_RES /
                                    (1 + Math.Abs(adduct.AdductCharge / 15.0));

            return(new IsotopeDistInfo(mzDistribution, monoisotopicMass, adduct,
                                       fullScan.GetPrecursorFilterWindow,
                                       massResolution,
                                       TransitionFullScan.MIN_ISOTOPE_PEAK_ABUNDANCE));
        }
예제 #16
0
        public SpectrumFilter(SrmDocument document, MsDataFileUri msDataFileUri, IFilterInstrumentInfo instrumentInfo,
            IRetentionTimePredictor retentionTimePredictor = null, bool firstPass = false)
        {
            _fullScan = document.Settings.TransitionSettings.FullScan;
            _instrument = document.Settings.TransitionSettings.Instrument;
            _acquisitionMethod = _fullScan.AcquisitionMethod;
            if (instrumentInfo != null)
                _isWatersFile = instrumentInfo.IsWatersFile;
            IsFirstPass = firstPass;

            var comparer = PrecursorTextId.PrecursorTextIdComparerInstance;
            var dictPrecursorMzToFilter = new SortedDictionary<PrecursorTextId, SpectrumFilterPair>(comparer);

            if (EnabledMs || EnabledMsMs)
            {
                if (EnabledMs)
                {
                    _isHighAccMsFilter = !Equals(_fullScan.PrecursorMassAnalyzer,
                        FullScanMassAnalyzerType.qit);

                    if (!firstPass)
                    {
                        var key = new PrecursorTextId(0, null, ChromExtractor.summed);  // TIC
                        dictPrecursorMzToFilter.Add(key, new SpectrumFilterPair(key, PeptideDocNode.UNKNOWN_COLOR, dictPrecursorMzToFilter.Count,
                            _instrument.MinTime, _instrument.MaxTime, null, null, 0, _isHighAccMsFilter, _isHighAccProductFilter));
                        key = new PrecursorTextId(0, null, ChromExtractor.base_peak);   // BPC
                        dictPrecursorMzToFilter.Add(key, new SpectrumFilterPair(key, PeptideDocNode.UNKNOWN_COLOR, dictPrecursorMzToFilter.Count,
                            _instrument.MinTime, _instrument.MaxTime, null, null, 0, _isHighAccMsFilter, _isHighAccProductFilter));
                    }
                }
                if (EnabledMsMs)
                {
                    _isHighAccProductFilter = !Equals(_fullScan.ProductMassAnalyzer,
                        FullScanMassAnalyzerType.qit);

                    if (_fullScan.AcquisitionMethod == FullScanAcquisitionMethod.DIA &&
                        _fullScan.IsolationScheme.IsAllIons)
                    {
                        if (instrumentInfo != null)
                        {
                            _isWatersMse = _isWatersFile;
                            _isAgilentMse = instrumentInfo.IsAgilentFile;
                        }
                        _mseLevel = 1;
                    }
                }

                Func<double, double> calcWindowsQ1 = _fullScan.GetPrecursorFilterWindow;
                Func<double, double> calcWindowsQ3 = _fullScan.GetProductFilterWindow;
                _minTime = _instrument.MinTime;
                _maxTime = _instrument.MaxTime;
                bool canSchedule = CanSchedule(document, retentionTimePredictor);
                // TODO: Figure out a way to turn off time sharing on first SIM scan so that
                //       times can be shared for MS1 without SIM scans
                _isSharedTime = !canSchedule;

                // If we're using bare measured drift times from spectral libraries, go get those now
                var libraryIonMobilityInfo = document.Settings.PeptideSettings.Prediction.UseLibraryDriftTimes
                    ? document.Settings.GetIonMobilities(msDataFileUri)
                    : null;

                foreach (var nodePep in document.Molecules)
                {
                    if (firstPass && !retentionTimePredictor.IsFirstPassPeptide(nodePep))
                        continue;

                    foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
                    {
                        if (nodeGroup.Children.Count == 0)
                            continue;

                        double? minTime = _minTime, maxTime = _maxTime;
                        double? startDriftTimeMsec = null, endDriftTimeMsec = null;
                        double windowDT;
                        double highEnergyDriftTimeOffsetMsec = 0;
                        DriftTimeInfo centerDriftTime = document.Settings.PeptideSettings.Prediction.GetDriftTime(
                            nodePep, nodeGroup, libraryIonMobilityInfo, out windowDT);
                        if (centerDriftTime.DriftTimeMsec(false).HasValue)
                        {
                            startDriftTimeMsec = centerDriftTime.DriftTimeMsec(false) - windowDT / 2; // Get the low energy drift time
                            endDriftTimeMsec = startDriftTimeMsec + windowDT;
                            highEnergyDriftTimeOffsetMsec = centerDriftTime.HighEnergyDriftTimeOffsetMsec;
                        }

                        if (canSchedule)
                        {
                            if (RetentionTimeFilterType.scheduling_windows == _fullScan.RetentionTimeFilterType)
                            {
                                double? centerTime = null;
                                double windowRT = 0;
                                if (retentionTimePredictor != null)
                                {
                                    centerTime = retentionTimePredictor.GetPredictedRetentionTime(nodePep);
                                }
                                else
                                {
                                    var prediction = document.Settings.PeptideSettings.Prediction;
                                    if (prediction.RetentionTime == null || !prediction.RetentionTime.IsAutoCalculated)
                                    {
                                        centerTime = document.Settings.PeptideSettings.Prediction.PredictRetentionTimeForChromImport(
                                            document, nodePep, nodeGroup, out windowRT);
                                    }
                                }
                                // Force the center time to be at least zero
                                if (centerTime.HasValue && centerTime.Value < 0)
                                    centerTime = 0;
                                if (_fullScan.RetentionTimeFilterLength != 0)
                                {
                                    windowRT = _fullScan.RetentionTimeFilterLength * 2;
                                }
                                if (centerTime != null)
                                {
                                    double startTime = centerTime.Value - windowRT / 2;
                                    double endTime = startTime + windowRT;
                                    minTime = Math.Max(minTime ?? 0, startTime);
                                    maxTime = Math.Min(maxTime ?? double.MaxValue, endTime);
                                }
                            }
                            else if (RetentionTimeFilterType.ms2_ids == _fullScan.RetentionTimeFilterType)
                            {
                                var times = document.Settings.GetBestRetentionTimes(nodePep, msDataFileUri);
                                if (times.Length > 0)
                                {
                                    minTime = Math.Max(minTime ?? 0, times.Min() - _fullScan.RetentionTimeFilterLength);
                                    maxTime = Math.Min(maxTime ?? double.MaxValue, times.Max() + _fullScan.RetentionTimeFilterLength);
                                }
                            }
                        }

                        SpectrumFilterPair filter;
                        string textId = nodePep.RawTextId; // Modified Sequence for peptides, or some other string for custom ions
                        double mz = nodeGroup.PrecursorMz;
                        var key = new PrecursorTextId(mz, textId, ChromExtractor.summed);
                        if (!dictPrecursorMzToFilter.TryGetValue(key, out filter))
                        {
                            filter = new SpectrumFilterPair(key, nodePep.Color, dictPrecursorMzToFilter.Count, minTime, maxTime,
                                startDriftTimeMsec, endDriftTimeMsec, highEnergyDriftTimeOffsetMsec,
                                _isHighAccMsFilter, _isHighAccProductFilter);
                            dictPrecursorMzToFilter.Add(key, filter);
                        }

                        if (!EnabledMs)
                        {
                            filter.AddQ3FilterValues(from TransitionDocNode nodeTran in nodeGroup.Children
                                                     select nodeTran.Mz, calcWindowsQ3);
                        }
                        else if (!EnabledMsMs)
                        {
                            filter.AddQ1FilterValues(GetMS1MzValues(nodeGroup), calcWindowsQ1);
                        }
                        else
                        {
                            filter.AddQ1FilterValues(GetMS1MzValues(nodeGroup), calcWindowsQ1);
                            filter.AddQ3FilterValues(from TransitionDocNode nodeTran in nodeGroup.Children
                                                     where !nodeTran.IsMs1
                                                     select nodeTran.Mz, calcWindowsQ3);
                        }
                    }
                }
                _filterMzValues = dictPrecursorMzToFilter.Values.ToArray();

                var listChromKeyFilterIds = new List<ChromKey>();
                foreach (var spectrumFilterPair in _filterMzValues)
                {
                    spectrumFilterPair.AddChromKeys(listChromKeyFilterIds);
                }
                _productChromKeys = listChromKeyFilterIds.ToArray();

                // Sort a copy of the filter pairs by maximum retention time so that we can detect when
                // filters are no longer active.
                _filterRTValues = new SpectrumFilterPair[_filterMzValues.Length];
                Array.Copy(_filterMzValues, _filterRTValues, _filterMzValues.Length);
                Array.Sort(_filterRTValues, CompareByRT);
            }

            InitRTLimits();
        }
예제 #17
0
        public bool ValidateFullScanSettings(MessageBoxHelper helper, out TransitionFullScan fullScanSettings, TabControl tabControl = null, int tabIndex = -1)
        {
            fullScanSettings = null;

            double? precursorIsotopeFilter;
            if (!ValidatePrecursorIsotopeFilter(helper, out precursorIsotopeFilter, tabControl, tabIndex))
                return false;

            double? precursorRes;
            if (!ValidatePrecursorRes(helper, precursorIsotopeFilter, out precursorRes, tabControl, tabIndex))
                return false;

            double? precursorResMz;
            if (!ValidatePrecursorResMz(helper, out precursorResMz, tabControl, tabIndex))
                return false;

            double? productRes;
            if (!ValidateProductRes(helper, out productRes, tabControl, tabIndex))
                return false;

            double? productResMz;
            if (!ValidateProductResMz(helper, out productResMz, tabControl, tabIndex))
                return false;

            RetentionTimeFilterType retentionTimeFilterType = RetentionTimeFilterType;
            double retentionTimeFilterLength;
            if (!ValidateRetentionTimeFilterLength(out retentionTimeFilterLength))
                return false;

            fullScanSettings = new TransitionFullScan(AcquisitionMethod,
                                                  IsolationScheme,
                                                  ProductMassAnalyzer,
                                                  productRes,
                                                  productResMz,
                                                  PrecursorIsotopesCurrent,
                                                  precursorIsotopeFilter,
                                                  PrecursorMassAnalyzer,
                                                  precursorRes,
                                                  precursorResMz,
                                                  Enrichments,
                                                  retentionTimeFilterType,
                                                  retentionTimeFilterLength);
            return true;
        }