Exemplo n.º 1
0
        public void Refresh()
        {
            if (websocket.IsConnected)
            {
                MidiObserver.Display(EMidiOBSItemType.ReloadOBSData, EMidiOBSOutputType.Off, -1, -1, true);

                var studiomode = websocket.StudioModeEnabled();
                Mode              = studiomode ? 2 : 1;
                OutputStatus      = websocket.GetStreamingStatus();
                CurrentTransition = websocket.GetCurrentTransition();

                LoadSources();
                LoadScenesAndSources();
                LoadTransitions();

                if (studiomode)
                {
                    ActivePScene = -1;
                    var pscene = websocket.GetPreviewScene();
                    ActivePSceneName = pscene.Name;
                    for (int i = 0; i < Scenes.Count(); i++)
                    {
                        if (Scenes[i].Name == ActivePSceneName)
                        {
                            ActivePScene = i;
                        }
                    }
                }

                MidiObserver.Display(EMidiOBSItemType.ReloadOBSData, EMidiOBSOutputType.On, -1, -1, true);
                MidiObserver.RenderSurface();
            }
        }
Exemplo n.º 2
0
        private bool UpdateTransitionSettings()
        {
            TransitionSettings newTransitionSettings = TransitionSettingsControl.GetTransitionSettings(this);

            if (newTransitionSettings == null)
            {
                return(false);
            }

            TransitionSettingsControl.SetFields(newTransitionSettings);

            // Only update, if anything changed
            Helpers.AssignIfEquals(ref newTransitionSettings, TransitionSettings);
            if (Equals(newTransitionSettings, TransitionSettings))
            {
                return(true);
            }

            if (SkylineWindow.ChangeSettings(SkylineWindow.DocumentUI.Settings.ChangeTransitionSettings(newTransitionSettings), true))
            {
                _transitionSettingsChanged = true;
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        void Transition(TransitionSettings transitionSettings, TransitionModeType transitionMode)
        {
            if (transitionMode == TransitionModeType.In && TransitionInConfig.OnTransitionStart != null)
            {
                TransitionInConfig.OnTransitionStart.Invoke();
            }
            else if (transitionMode == TransitionModeType.Out && TransitionOutConfig.OnTransitionStart != null)
            {
                TransitionOutConfig.OnTransitionStart.Invoke();
            }

            // set new transition id to stop all old transitions.
            _activeTransitionId = Guid.NewGuid().ToString();
            _transitionSettings = transitionSettings;
            TransitionMode      = transitionMode;

            // get the easing function - will be null for unsupported types.
            _easingFunction = TweenMethods.GetEasingFunction(_transitionSettings.TransitionType);

            // if delay and duration are both zero then just set end state, otherwise run the transition.
            if (Mathf.Approximately(_transitionSettings.Delay, 0) && Mathf.Approximately(_transitionSettings.Duration, 0))
            {
                SetProgress(1);
                SetAmount(_endFloat);
            }
            else
            {
                SetProgress(0);
                StartCoroutine(TransitionInternal(_activeTransitionId, transitionMode));
            }
        }
Exemplo n.º 4
0
 public static TransitionFilterAndLibrariesSettings GetDefault(TransitionSettings transitionSettings)
 {
     return(new TransitionFilterAndLibrariesSettings(transitionSettings.Filter.PeptidePrecursorChargesString,
                                                     transitionSettings.Filter.PeptideProductChargesString,
                                                     transitionSettings.Filter.PeptideIonTypesString, transitionSettings.Filter.ExclusionUseDIAWindow,
                                                     transitionSettings.Libraries.IonMatchTolerance, transitionSettings.Libraries.MinIonCount,
                                                     transitionSettings.Libraries.IonCount));
 }
        public TransitionSettings GetTransitionSettings(Form parent)
        {
            var helper = new MessageBoxHelper(parent);
            TransitionSettings settings = SkylineWindow.DocumentUI.Settings.TransitionSettings;

            // Validate and store filter settings
            int[] precursorCharges;
            if (!helper.ValidateNumberListTextBox(txtPrecursorCharges, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE, out precursorCharges))
            {
                return(null);
            }
            precursorCharges = precursorCharges.Distinct().ToArray();

            int[] productCharges;
            if (!helper.ValidateNumberListTextBox(txtIonCharges, Transition.MIN_PRODUCT_CHARGE, Transition.MAX_PRODUCT_CHARGE, out productCharges))
            {
                return(null);
            }
            productCharges = productCharges.Distinct().ToArray();

            IonType[] types = IonTypes;
            if (types.Length == 0)
            {
                helper.ShowTextBoxError(txtIonTypes, Resources.TransitionSettingsUI_OkDialog_Ion_types_must_contain_a_comma_separated_list_of_ion_types_a_b_c_x_y_z_and_p_for_precursor);
                return(null);
            }
            types = types.Distinct().ToArray();

            bool exclusionUseDIAWindow = cbExclusionUseDIAWindow.Visible && cbExclusionUseDIAWindow.Checked;
            var  filter = new TransitionFilter(precursorCharges, productCharges, types, settings.Filter.FragmentRangeFirstName, settings.Filter.FragmentRangeLastName,
                                               settings.Filter.MeasuredIons, settings.Filter.PrecursorMzWindow, exclusionUseDIAWindow, settings.Filter.AutoSelect);

            Helpers.AssignIfEquals(ref filter, settings.Filter);

            // Validate and store library settings
            double ionMatchTolerance;

            if (!helper.ValidateDecimalTextBox(txtTolerance, TransitionLibraries.MIN_MATCH_TOLERANCE, TransitionLibraries.MAX_MATCH_TOLERANCE, out ionMatchTolerance))
            {
                return(null);
            }

            int ionCount = settings.Libraries.IonCount;

            if (!helper.ValidateNumberTextBox(txtIonCount, TransitionLibraries.MIN_ION_COUNT, TransitionLibraries.MAX_ION_COUNT, out ionCount))
            {
                return(null);
            }

            TransitionLibraryPick pick = (settings.Libraries.Pick != TransitionLibraryPick.none) ? settings.Libraries.Pick : TransitionLibraryPick.all;
            var libraries = new TransitionLibraries(ionMatchTolerance, ionCount, pick);

            Helpers.AssignIfEquals(ref libraries, settings.Libraries);

            return(new TransitionSettings(settings.Prediction, filter, libraries, settings.Integration, settings.Instrument, settings.FullScan));
        }
Exemplo n.º 6
0
 public static TransitionFilterAndLibrariesSettings GetDefault(TransitionSettings transitionSettings)
 {
     return(new TransitionFilterAndLibrariesSettings(transitionSettings.Filter.PeptidePrecursorChargesString,
                                                     transitionSettings.Filter.PeptideProductChargesString,
                                                     transitionSettings.Filter.PeptideIonTypesString, transitionSettings.Filter.ExclusionUseDIAWindow,
                                                     transitionSettings.Libraries.IonMatchTolerance, transitionSettings.Libraries.MinIonCount,
                                                     transitionSettings.Libraries.IonCount, transitionSettings.Filter.FragmentRangeFirst.Label,
                                                     transitionSettings.Filter.FragmentRangeLast.Label, transitionSettings.Instrument.MinMz,
                                                     transitionSettings.Instrument.MaxMz));
 }
Exemplo n.º 7
0
 public FragmentFilter(TransitionSettings transitionSettings, IEnumerable <Adduct> rankedAdducts, IEnumerable <IonType> rankedIonTypes)
 {
     TransitionSettings = transitionSettings;
     FragmentMatchCount = TransitionSettings.Libraries.IonCount;
     LibraryPick        = TransitionSettings.Libraries.Pick;
     AdductsToDisplay   = RankedAdducts = ImmutableList.ValueOf(rankedAdducts);
     IonTypesToDisplay  = RankedIonTypes = ImmutableList.ValueOf(rankedIonTypes);
     RankedCharges      = ImmutableList.ValueOf(RankedAdducts.Select(adduct => Math.Abs(adduct.AdductCharge)).Distinct());
     UseFilter          = true;
 }
Exemplo n.º 8
0
 public void SetFields(TransitionSettings settings)
 {
     PeptidePrecursorCharges = settings.Filter.PeptidePrecursorCharges.ToArray();
     PeptideIonCharges       = settings.Filter.PeptideProductCharges.ToArray();
     PeptideIonTypes         = settings.Filter.PeptideIonTypes.ToArray();
     ExclusionUseDIAWindow   = settings.Filter.ExclusionUseDIAWindow;
     IonMatchTolerance       = settings.Libraries.IonMatchTolerance;
     MinIonCount             = settings.Libraries.MinIonCount;
     IonCount = settings.Libraries.IonCount;
 }
Exemplo n.º 9
0
        private bool ApplyRanking(RankingState rankingState, double ionMz, MatchedFragmentIon match, bool filter, int start, int end, double startMz, ref RankedMI rankedMI)
        {
            // Avoid ranking precursor ions without losses, if the precursor isotopes will
            // not be taken from product ions
            if (!ExcludePrecursorIsotopes || match.IonType != IonType.precursor || match.Losses != null)
            {
                int offset = OrdinalToOffset(match.IonType, match.Ordinal);
                var type   = match.IonType;
                if (filter)
                {
                    if (TargetInfoObj.LookupMods == null || !TargetInfoObj.LookupMods.HasCrosslinks)
                    {
                        if (!TransitionSettings.Accept(Sequence, MoleculeMassesObj.precursorMz, type, offset, ionMz, start,
                                                       end, startMz))
                        {
                            return(false);
                        }
                    }
                }
                if (rankingState.matchAll)
                {
                    if (MinMz > ionMz || ionMz > MaxMz)
                    {
                        return(false);
                    }

                    if (!RankTypes.Contains(type))
                    {
                        return(false);
                    }

                    if (RankLimit.HasValue && rankingState.Ranked >= RankLimit)
                    {
                        return(false);
                    }

                    if (type != IonType.precursor)
                    {
                        // CONSIDER(bspratt) we may eventually want adduct-level control for small molecules, not just abs charge
                        if (!RankCharges.Contains(Math.Abs(match.Charge.AdductCharge)))
                        {
                            return(false);
                        }
                    }
                }

                rankedMI = rankedMI.ChangeRank(rankingState.RankNext());
                return(true);
            }

            return(false);
        }
        public TransitionSettingsControl(SkylineWindow skylineWindow)
        {
            SkylineWindow = skylineWindow;
            TransitionSettings settings = SkylineWindow.DocumentUI.Settings.TransitionSettings;

            InitializeComponent();

            PrecursorCharges      = settings.Filter.PrecursorCharges.ToArray();
            IonCharges            = settings.Filter.ProductCharges.ToArray();
            IonTypes              = settings.Filter.IonTypes.Union(new[] { IonType.precursor, IonType.y }).ToArray(); // Add p, y if not already set
            ExclusionUseDIAWindow = settings.Filter.ExclusionUseDIAWindow;
            IonMatchTolerance     = settings.Libraries.IonMatchTolerance;
            IonCount              = settings.Libraries.IonCount;
        }
Exemplo n.º 11
0
 public void SetFields(TransitionSettings settings)
 {
     PeptidePrecursorCharges = settings.Filter.PeptidePrecursorCharges.ToArray();
     PeptideIonCharges       = settings.Filter.PeptideProductCharges.ToArray();
     PeptideIonTypes         = settings.Filter.PeptideIonTypes.ToArray();
     ExclusionUseDIAWindow   = settings.Filter.ExclusionUseDIAWindow;
     IonMatchTolerance       = settings.Libraries.IonMatchTolerance;
     MinIonCount             = settings.Libraries.MinIonCount;
     IonCount     = settings.Libraries.IonCount;
     IonRangeFrom = settings.Filter.FragmentRangeFirst.Label;
     IonRangeTo   = settings.Filter.FragmentRangeLast.Label;
     MinIonMz     = settings.Instrument.MinMz;
     MaxIonMz     = settings.Instrument.MaxMz;
 }
Exemplo n.º 12
0
        public void OBSCurrentTransitionInfo_BuildFromJSON()
        {
            string transitionName = "Transition name éèïöü";
            int    duration       = 2000;

            var data = new JObject();

            data.Add("name", transitionName);
            data.Add("duration", duration);

            var transitionInfo = new TransitionSettings(data);

            Assert.AreEqual(transitionName, transitionInfo.Name);
            Assert.AreEqual(duration, transitionInfo.Duration);
        }
Exemplo n.º 13
0
        private SOBSTransition _translateActiveTransition(TransitionSettings input)
        {
            SOBSTransition transition = new SOBSTransition();

            transition.Name = input.Name;
            transition.Id   = _uidFromString(input.Name);
            for (int i = 0; i < Transitions.Count; i++)
            {
                if (Transitions[i].Id == transition.Id)
                {
                    transition.Index = i;
                }
            }
            return(transition);
        }
Exemplo n.º 14
0
        public void Transition(TransitionSettings transitionSettings, Vector3 startAmount, Vector3 endAmount, TransitionModeType transitionMode)
        {
            // if this transition should not run then return immediately
            if (transitionSettings.TransitionType == TransitionHelper.TransitionType.none)
            {
                return;
            }

            // save transition values
            _targetType   = TargetTypeEnum.Vector3;
            _startVector3 = startAmount;
            _endVector3   = endAmount;

            // start transition
            Transition(transitionSettings, transitionMode);
        }
Exemplo n.º 15
0
        private bool UpdateTransitionSettings()
        {
            TransitionSettings newTransitionSettings = TransitionSettingsControl.GetTransitionSettings(this);

            if (newTransitionSettings == null)
            {
                return(false);
            }

            TransitionSettingsControl.SetFields(newTransitionSettings);

            // Only update, if anything changed
            Helpers.AssignIfEquals(ref newTransitionSettings, TransitionSettings);
            if (Equals(newTransitionSettings, TransitionSettings))
            {
                return(true);
            }

            ModifyDocumentNoUndo(doc => doc.ChangeSettings(doc.Settings.ChangeTransitionSettings(newTransitionSettings)));
            _transitionSettingsChanged = true;
            return(true);
        }
Exemplo n.º 16
0
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                this.ExtendClientAreaToDecorationsHint  = true;
                this.ExtendClientAreaTitleBarHeightHint = -1;
                this.ExtendClientAreaChromeHints        = Avalonia.Platform.ExtendClientAreaChromeHints.NoChrome;
                this.TransparencyLevelHint = WindowTransparencyLevel.AcrylicBlur;
                this.Background            = new SolidColorBrush(Colors.Transparent);
            }

            WindowTitle = "SingleWindow";
            Transition  = new TransitionSettings(TransitionSettings.EnterTransitions.SlideLeft, TimeSpan.FromMilliseconds(250));
            BackKey     = Key.Escape;

            m_Container = this.FindControl <Grid>("m_Container");
            m_TitleBar  = this.FindControl <Controls.TitleBar>("m_TitleBar");

            Closing += OnWindowClosing;
            KeyDown += OnKeyDown;
        }
Exemplo n.º 17
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            // Validate and store prediction settings
            string massType = comboPrecursorMass.SelectedItem.ToString();
            MassType precursorMassType = MassTypeExtension.GetEnum(massType);
            massType = comboIonMass.SelectedItem.ToString();
            MassType fragmentMassType = MassTypeExtension.GetEnum(massType);
            string nameCE = comboCollisionEnergy.SelectedItem.ToString();
            CollisionEnergyRegression collisionEnergy =
                Settings.Default.GetCollisionEnergyByName(nameCE);
            string nameDP = comboDeclusterPotential.SelectedItem.ToString();
            DeclusteringPotentialRegression declusteringPotential =
                Settings.Default.GetDeclusterPotentialByName(nameDP);
            string nameCoV = comboCompensationVoltage.SelectedItem.ToString();
            CompensationVoltageParameters compensationVoltage =
                Settings.Default.GetCompensationVoltageByName(nameCoV);
            string nameOptLib = comboOptimizationLibrary.SelectedItem.ToString();
            OptimizationLibrary optimizationLibrary =
                Settings.Default.GetOptimizationLibraryByName(nameOptLib);
            OptimizedMethodType optimizedMethodType = OptimizedMethodType.None;
            if (cbUseOptimized.Checked)
            {
                optimizedMethodType = OptimizedMethodTypeExtension.GetEnum(comboOptimizeType.SelectedItem.ToString());
            }
            TransitionPrediction prediction = new TransitionPrediction(precursorMassType,
                                                                       fragmentMassType, collisionEnergy,
                                                                       declusteringPotential,
                                                                       compensationVoltage,
                                                                       optimizationLibrary,
                                                                       optimizedMethodType);
            Helpers.AssignIfEquals(ref prediction, Prediction);

            // Validate and store filter settings
            int[] precursorCharges;
            int min = TransitionGroup.MIN_PRECURSOR_CHARGE;
            int max = TransitionGroup.MAX_PRECURSOR_CHARGE;
            if (!helper.ValidateNumberListTextBox(tabControl1, (int) TABS.Filter, textPrecursorCharges,
                    min, max, out precursorCharges))
                return;
            precursorCharges = precursorCharges.Distinct().ToArray();

            int[] productCharges;
            min = Transition.MIN_PRODUCT_CHARGE;
            max = Transition.MAX_PRODUCT_CHARGE;
            if (!helper.ValidateNumberListTextBox(tabControl1, (int) TABS.Filter, textIonCharges,
                    min, max, out productCharges))
                return;
            productCharges = productCharges.Distinct().ToArray();

            IonType[] types = TransitionFilter.ParseTypes(textIonTypes.Text, new IonType[0]);
            if (types.Length == 0)
            {
                helper.ShowTextBoxError(tabControl1, (int) TABS.Filter, textIonTypes,
                                        Resources.TransitionSettingsUI_OkDialog_Ion_types_must_contain_a_comma_separated_list_of_ion_types_a_b_c_x_y_z_and_p_for_precursor);
                return;
            }
            types = types.Distinct().ToArray();

            double exclusionWindow = 0;
            if (!string.IsNullOrEmpty(textExclusionWindow.Text) &&
                !Equals(textExclusionWindow.Text, exclusionWindow.ToString(LocalizationHelper.CurrentCulture)))
            {
                if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Filter, textExclusionWindow,
                        TransitionFilter.MIN_EXCLUSION_WINDOW, TransitionFilter.MAX_EXCLUSION_WINDOW, out exclusionWindow))
                {
                    return;
                }
            }

            string fragmentRangeFirst = TransitionFilter.GetStartFragmentNameFromLabel(comboRangeFrom.SelectedItem.ToString());
            string fragmentRangeLast = TransitionFilter.GetEndFragmentNameFromLabel(comboRangeTo.SelectedItem.ToString());

            var measuredIons = _driverIons.Chosen;
            bool autoSelect = cbAutoSelect.Checked;
            bool exclusionUseDIAWindow = FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked;
            var filter = new TransitionFilter(precursorCharges, productCharges, types,
                                              fragmentRangeFirst, fragmentRangeLast, measuredIons,
                                              exclusionWindow, exclusionUseDIAWindow, autoSelect);
            Helpers.AssignIfEquals(ref filter, Filter);

            // Validate and store library settings
            TransitionLibraryPick pick = TransitionLibraryPick.none;
            if (cbLibraryPick.Checked)
            {
                if (radioAll.Checked)
                    pick = TransitionLibraryPick.all;
                else if (radioAllAndFiltered.Checked)
                    pick = TransitionLibraryPick.all_plus;
                else
                    pick = TransitionLibraryPick.filter;
            }

            double ionMatchTolerance;

            double minTol = TransitionLibraries.MIN_MATCH_TOLERANCE;
            double maxTol = TransitionLibraries.MAX_MATCH_TOLERANCE;
            if (!helper.ValidateDecimalTextBox(tabControl1, (int) TABS.Library, textTolerance,
                    minTol, maxTol, out ionMatchTolerance))
                return;

            int ionCount = Libraries.IonCount;

            if (pick != TransitionLibraryPick.none)
            {
                min = TransitionLibraries.MIN_ION_COUNT;
                max = TransitionLibraries.MAX_ION_COUNT;
                if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Library, textIonCount,
                        min, max, out ionCount))
                    return;
            }

            TransitionLibraries libraries = new TransitionLibraries(ionMatchTolerance, ionCount, pick);
            Helpers.AssignIfEquals(ref libraries, Libraries);

            // This dialog does not yet change integration settings
            TransitionIntegration integration = _transitionSettings.Integration;

            // Validate and store instrument settings
            int minMz;
            min = TransitionInstrument.MIN_MEASUREABLE_MZ;
            max = TransitionInstrument.MAX_MEASURABLE_MZ - TransitionInstrument.MIN_MZ_RANGE;
            if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMinMz, min, max, out minMz))
                return;
            int maxMz;
            min = minMz + TransitionInstrument.MIN_MZ_RANGE;
            max = TransitionInstrument.MAX_MEASURABLE_MZ;
            if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMaxMz, min, max, out maxMz))
                return;
            bool isDynamicMin = cbDynamicMinimum.Checked;
            double mzMatchTolerance;
            minTol = TransitionInstrument.MIN_MZ_MATCH_TOLERANCE;
            maxTol = TransitionInstrument.MAX_MZ_MATCH_TOLERANCE;
            if (!helper.ValidateDecimalTextBox(tabControl1, (int) TABS.Instrument, textMzMatchTolerance,
                    minTol, maxTol, out mzMatchTolerance))
                return;
            int? maxTrans = null;
            if (!string.IsNullOrEmpty(textMaxTrans.Text))
            {
                int maxTransTemp;
                min = TransitionInstrument.MIN_TRANSITION_MAX;
                max = TransitionInstrument.MAX_TRANSITION_MAX;
                if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMaxTrans,
                        min, max, out maxTransTemp))
                    return;
                maxTrans = maxTransTemp;
            }
            int? maxInclusions = null;
            if (!string.IsNullOrEmpty(textMaxInclusions.Text))
            {
                int maxInclusionsTemp;
                min = TransitionInstrument.MIN_INCLUSION_MAX;
                max = TransitionInstrument.MAX_INCLUSION_MAX;
                if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMaxInclusions,
                        min, max, out maxInclusionsTemp))
                    return;
                maxInclusions = maxInclusionsTemp;
            }
            int? minTime = null, maxTime = null;
            min = TransitionInstrument.MIN_TIME;
            max = TransitionInstrument.MAX_TIME;
            if (!string.IsNullOrEmpty(textMinTime.Text))
            {
                int minTimeTemp;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMinTime,
                        min, max, out minTimeTemp))
                    return;
                minTime = minTimeTemp;
            }
            if (!string.IsNullOrEmpty(textMaxTime.Text))
            {
                int maxTimeTemp;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxTime,
                        min, max, out maxTimeTemp))
                    return;
                maxTime = maxTimeTemp;
            }
            if (minTime.HasValue && maxTime.HasValue && maxTime.Value - minTime.Value < TransitionInstrument.MIN_TIME_RANGE)
            {
                helper.ShowTextBoxError(tabControl1, (int) TABS.Instrument, textMaxTime,
                                        string.Format(Resources.TransitionSettingsUI_OkDialog_The_allowable_retention_time_range__0__to__1__must_be_at_least__2__minutes_apart,
                                                      minTime, maxTime, TransitionInstrument.MIN_TIME_RANGE));
                return;
            }

            TransitionInstrument instrument = new TransitionInstrument(minMz,
                maxMz, isDynamicMin, mzMatchTolerance, maxTrans, maxInclusions, minTime, maxTime);
            Helpers.AssignIfEquals(ref instrument, Instrument);

            // Validate and store full-scan settings

            // If high resolution MS1 filtering is enabled, make sure precursor m/z type
            // is monoisotopic and isotope enrichments are set
            FullScanPrecursorIsotopes precursorIsotopes = PrecursorIsotopesCurrent;
            FullScanMassAnalyzerType precursorAnalyzerType = PrecursorMassAnalyzer;
            if (precursorIsotopes != FullScanPrecursorIsotopes.None &&
                    precursorAnalyzerType != FullScanMassAnalyzerType.qit)
            {
                if (precursorMassType != MassType.Monoisotopic)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_High_resolution_MS1_filtering_requires_use_of_monoisotopic_precursor_masses);
                    tabControl1.SelectedIndex = (int)TABS.Prediction;
                    comboPrecursorMass.Focus();
                    return;
                }

                if (FullScanSettingsControl.Enrichments == null)
                {
                    tabControl1.SelectedIndex = (int) TABS.FullScan;
                    MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers);
                    FullScanSettingsControl.ComboEnrichmentsSetFocus();
                    return;
                }
            }

            IsolationScheme isolationScheme = FullScanSettingsControl.IsolationScheme;
            FullScanAcquisitionMethod acquisitionMethod = AcquisitionMethod;
            if (isolationScheme == null && acquisitionMethod == FullScanAcquisitionMethod.DIA)
            {
                tabControl1.SelectedIndex = (int)TABS.FullScan;
                MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors);
                FullScanSettingsControl.ComboIsolationSchemeSetFocus();
                return;
            }

            if (isolationScheme != null && isolationScheme.WindowsPerScan.HasValue && !maxInclusions.HasValue)
            {
                MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Before_performing_a_multiplexed_DIA_scan_the_instrument_s_firmware_inclusion_limit_must_be_specified);
                tabControl1.SelectedIndex = (int)TABS.Instrument;
                textMaxInclusions.Focus();
                return;
            }

            if (FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked)
            {
                if (FullScanSettingsControl.IsolationScheme.IsAllIons)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_);
                    tabControl1.SelectedIndex = (int)TABS.Filter;
                    cbExclusionUseDIAWindow.Focus();
                    return;
                }
                if (FullScanSettingsControl.IsolationScheme.FromResults)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_);
                    tabControl1.SelectedIndex = (int)TABS.Filter;
                    cbExclusionUseDIAWindow.Focus();
                    return;
                }
            }

            TransitionFullScan fullScan;
            if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan, tabControl1, (int)TABS.FullScan))
                return;

            Helpers.AssignIfEquals(ref fullScan, FullScan);

            TransitionSettings settings = new TransitionSettings(prediction,
                filter, libraries, integration, instrument, fullScan);

            // Only update, if anything changed
            if (!Equals(settings, _transitionSettings))
            {
                if (!_parent.ChangeSettingsMonitored(this, Resources.TransitionSettingsUI_OkDialog_Changing_transition_settings,
                                                     s => s.ChangeTransitionSettings(settings)))
                {
                    return;
                }
                _transitionSettings = settings;
            }

            DialogResult = DialogResult.OK;
        }
Exemplo n.º 18
0
        private bool UpdateFullScanSettings()
        {
            var helper = new MessageBoxHelper(this);

            // Validate and store MS1 full-scan settings

            // If high resolution MS1 filtering is enabled, make sure precursor m/z type
            // is monoisotopic and isotope enrichments are set
            var precursorIsotopes = FullScanSettingsControl.PrecursorIsotopesCurrent;
            var precursorAnalyzerType = FullScanSettingsControl.PrecursorMassAnalyzer;
            var precursorMassType = TransitionSettings.Prediction.PrecursorMassType;
            if (precursorIsotopes != FullScanPrecursorIsotopes.None &&
                    precursorAnalyzerType != FullScanMassAnalyzerType.qit)
            {
                precursorMassType = MassType.Monoisotopic;
                if (FullScanSettingsControl.Enrichments == null)
                {
                    MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers);
                    return false;
                }
            }

            if (FullScanSettingsControl.IsolationScheme == null && FullScanSettingsControl.AcquisitionMethod == FullScanAcquisitionMethod.DIA)
            {
                MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors);
                return false;
            }

            TransitionFilter filter = TransitionSettings.Filter;
            if (FullScanSettingsControl.PrecursorChargesTextBox.Visible)
            {
                int[] precursorCharges;
                if (!helper.ValidateNumberListTextBox(FullScanSettingsControl.PrecursorChargesTextBox, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE, out precursorCharges))
                    return false;
                precursorCharges = precursorCharges.Distinct().ToArray();
                filter = TransitionSettings.Filter.ChangePrecursorCharges(precursorCharges);
            }
            if (WorkflowType == Workflow.dda && !filter.IonTypes.Contains(IonType.precursor))
                filter = filter.ChangeIonTypes(new[] {IonType.precursor});
            if (!filter.AutoSelect)
                filter = filter.ChangeAutoSelect(true);
            Helpers.AssignIfEquals(ref filter, TransitionSettings.Filter);

            if (FullScanSettingsControl.IsDIA() && filter.ExclusionUseDIAWindow)
            {
                if (FullScanSettingsControl.IsolationScheme.IsAllIons)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_);
                    return false;
                }
                if (FullScanSettingsControl.IsolationScheme.FromResults)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_);
                    return false;
                }
            }

            TransitionFullScan fullScan;
            if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan))
                return false;

            Helpers.AssignIfEquals(ref fullScan, TransitionSettings.FullScan);

            var prediction = TransitionSettings.Prediction.ChangePrecursorMassType(precursorMassType);
            Helpers.AssignIfEquals(ref prediction, TransitionSettings.Prediction);

            TransitionSettings settings;
            try
            {
                 settings = new TransitionSettings(prediction, filter,
                     TransitionSettings.Libraries, TransitionSettings.Integration, TransitionSettings.Instrument, fullScan);
            }
            catch (Exception x)
            {
                MessageDlg.Show(this, x.Message);
                return false;
            }

            // Only update, if anything changed
            if (!Equals(settings, TransitionSettings))
            {
                SrmSettings newSettings = SkylineWindow.DocumentUI.Settings.ChangeTransitionSettings(settings);
                if (!SkylineWindow.ChangeSettings(newSettings, true))
                {
                    return false;
                }
            }

            // MS1 filtering must be enabled
            if (!FullScan.IsEnabledMs)
            {
                MessageDlg.Show(this, Resources.ImportPeptideSearchDlg_UpdateFullScanSettings_Full_scan_MS1_filtering_must_be_enabled_in_order_to_import_a_peptide_search_);
                return false;
            }

            return true;
        }
Exemplo n.º 19
0
        public TransitionSettingsUI(SkylineWindow parent)
        {
            InitializeComponent();

            // Populate the fragment finder combo boxes
            foreach (string item in TransitionFilter.GetStartFragmentFinderLabels())
                comboRangeFrom.Items.Add(item);
            foreach (string item in TransitionFilter.GetEndFragmentFinderLabels())
                comboRangeTo.Items.Add(item);

            _parent = parent;
            _transitionSettings = _parent.DocumentUI.Settings.TransitionSettings;

            // Initialize prediction settings
            comboPrecursorMass.SelectedItem = Prediction.PrecursorMassType.GetLocalizedString();
            comboIonMass.SelectedItem = Prediction.FragmentMassType.GetLocalizedString();

            _driverCE = new SettingsListComboDriver<CollisionEnergyRegression>(comboCollisionEnergy,
                                                                               Settings.Default.CollisionEnergyList);
            string sel = (Prediction.CollisionEnergy == null ? null : Prediction.CollisionEnergy.Name);
            _driverCE.LoadList(sel);

            _driverDP = new SettingsListComboDriver<DeclusteringPotentialRegression>(comboDeclusterPotential,
                                                                                     Settings.Default.DeclusterPotentialList);
            sel = (Prediction.DeclusteringPotential == null ? null : Prediction.DeclusteringPotential.Name);
            _driverDP.LoadList(sel);

            _driverCoV = new SettingsListComboDriver<CompensationVoltageParameters>(comboCompensationVoltage,
                                                                                    Settings.Default.CompensationVoltageList);
            _driverCoV.LoadList(Prediction.CompensationVoltage == null ? null : Prediction.CompensationVoltage.Name);

            _driverOptimizationLibrary = new SettingsListComboDriver<OptimizationLibrary>(comboOptimizationLibrary,
                Settings.Default.OptimizationLibraryList);
            _driverOptimizationLibrary.LoadList(Prediction.OptimizedLibrary == null ? null : Prediction.OptimizedLibrary.Name);

            if (Prediction.OptimizedMethodType == OptimizedMethodType.None)
                comboOptimizeType.SelectedIndex = 0;
            else
            {
                cbUseOptimized.Checked = true;
                comboOptimizeType.SelectedItem = Prediction.OptimizedMethodType.GetLocalizedString();
            }

            // Initialize filter settings
            textPrecursorCharges.Text = Filter.PrecursorCharges.ToArray().ToString(", "); // Not L10N? Internationalization of comma?
            textIonCharges.Text = Filter.ProductCharges.ToArray().ToString(", "); // Not L10N? Internationalization of comma?
            textIonTypes.Text = TransitionFilter.ToStringIonTypes(Filter.IonTypes, true);
            comboRangeFrom.SelectedItem = Filter.FragmentRangeFirst.Label;
            comboRangeTo.SelectedItem = Filter.FragmentRangeLast.Label;
            textExclusionWindow.Text = Filter.PrecursorMzWindow != 0
                                           ? Filter.PrecursorMzWindow.ToString(LocalizationHelper.CurrentCulture)
                                           : string.Empty;
            cbExclusionUseDIAWindow.Checked = Filter.ExclusionUseDIAWindow;
            cbAutoSelect.Checked = Filter.AutoSelect;

            _driverIons = new MeasuredIonListBoxDriver(listAlwaysAdd, Settings.Default.MeasuredIonList);
            _driverIons.LoadList(Filter.MeasuredIons);

            // Initialize library settings
            cbLibraryPick.Checked = (Libraries.Pick != TransitionLibraryPick.none);
            panelPick.Visible = cbLibraryPick.Checked;
            textTolerance.Text = Libraries.IonMatchTolerance.ToString(LocalizationHelper.CurrentCulture);
            textIonCount.Text = Libraries.IonCount.ToString(LocalizationHelper.CurrentCulture);
            if (Libraries.Pick == TransitionLibraryPick.filter)
                radioFiltered.Checked = true;
            else if (Libraries.Pick == TransitionLibraryPick.all_plus)
                radioAllAndFiltered.Checked = true;

            // Initialize instrument settings
            textMinMz.Text = Instrument.MinMz.ToString(LocalizationHelper.CurrentCulture);
            textMaxMz.Text = Instrument.MaxMz.ToString(LocalizationHelper.CurrentCulture);
            cbDynamicMinimum.Checked = Instrument.IsDynamicMin;
            textMzMatchTolerance.Text = Instrument.MzMatchTolerance.ToString(LocalizationHelper.CurrentCulture);
            if (Instrument.MaxTransitions.HasValue)
                textMaxTrans.Text = Instrument.MaxTransitions.Value.ToString(LocalizationHelper.CurrentCulture);
            if (Instrument.MaxInclusions.HasValue)
                textMaxInclusions.Text = Instrument.MaxInclusions.Value.ToString(LocalizationHelper.CurrentCulture);
            if (Instrument.MinTime.HasValue)
                textMinTime.Text = Instrument.MinTime.Value.ToString(LocalizationHelper.CurrentCulture);
            if (Instrument.MaxTime.HasValue)
                textMaxTime.Text = Instrument.MaxTime.Value.ToString(LocalizationHelper.CurrentCulture);

            // Initialize full-scan settings
            FullScanSettingsControl = new FullScanSettingsControl(_parent)
                                          {
                                              Anchor = (AnchorStyles.Top | AnchorStyles.Left),
                                              Location = new Point(0, 0),
                                              Size = new Size(363, 491)
                                          };
            FullScanSettingsControl.IsolationSchemeChangedEvent += IsolationSchemeChanged;
            tabFullScan.Controls.Add(FullScanSettingsControl);

            // VISUAL:
            // - Store the distance between the cbExclusionDIAWindow and the lower end of the box (to use as margin later)
            // - Shift the cbExclusionDIAWindow down (it is only higher in the designer for better manipulation)
            _lower_margin = groupBox1.Height - textExclusionWindow.Location.Y - textExclusionWindow.Height;
            int pixelShift = cbExclusionUseDIAWindow.Location.Y - lbPrecursorMzWindow.Location.Y;
            cbExclusionUseDIAWindow.Location = new Point(cbExclusionUseDIAWindow.Location.X, cbExclusionUseDIAWindow.Location.Y - pixelShift);

            DoIsolationSchemeChanged();
        }
Exemplo n.º 20
0
        public TransitionSettings GetTransitionSettings(Form parent)
        {
            var helper = new MessageBoxHelper(parent);
            TransitionSettings settings = _documentContainer.Document.Settings.TransitionSettings;

            // Validate and store filter settings
            Adduct[] peptidePrecursorCharges;
            if (!ValidateAdductListTextBox(helper, txtPeptidePrecursorCharges, true, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE, out peptidePrecursorCharges))
            {
                return(null);
            }
            peptidePrecursorCharges = peptidePrecursorCharges.Distinct().ToArray();

            Adduct[] peptideProductCharges;
            if (!ValidateAdductListTextBox(helper, txtPrecursorIonCharges, true, Transition.MIN_PRODUCT_CHARGE, Transition.MAX_PRODUCT_CHARGE, out peptideProductCharges))
            {
                return(null);
            }
            peptideProductCharges = peptideProductCharges.Distinct().ToArray();

            IonType[] peptideIonTypes = PeptideIonTypes;
            if (peptideIonTypes.Length == 0)
            {
                helper.ShowTextBoxError(txtIonTypes, Resources.TransitionSettingsUI_OkDialog_Ion_types_must_contain_a_comma_separated_list_of_ion_types_a_b_c_x_y_z_and_p_for_precursor);
                return(null);
            }
            peptideIonTypes = peptideIonTypes.Distinct().ToArray();

            bool exclusionUseDIAWindow = cbExclusionUseDIAWindow.Visible && cbExclusionUseDIAWindow.Checked;
            var  filter = new TransitionFilter(peptidePrecursorCharges, peptideProductCharges, peptideIonTypes,
                                               settings.Filter.SmallMoleculePrecursorAdducts, settings.Filter.SmallMoleculeFragmentAdducts, settings.Filter.SmallMoleculeIonTypes,
                                               settings.Filter.FragmentRangeFirstName, settings.Filter.FragmentRangeLastName,
                                               settings.Filter.MeasuredIons, settings.Filter.PrecursorMzWindow, exclusionUseDIAWindow, settings.Filter.AutoSelect);

            Helpers.AssignIfEquals(ref filter, settings.Filter);

            // Validate and store library settings
            double ionMatchTolerance;

            if (!helper.ValidateDecimalTextBox(txtTolerance, TransitionLibraries.MIN_MATCH_TOLERANCE, TransitionLibraries.MAX_MATCH_TOLERANCE, out ionMatchTolerance))
            {
                return(null);
            }

            int minIonCount = settings.Libraries.MinIonCount;

            if (string.IsNullOrEmpty(txtMinIonCount.Text))
            {
                minIonCount = 0;
            }
            else if (!helper.ValidateNumberTextBox(txtMinIonCount, 0, TransitionLibraries.MAX_ION_COUNT, out minIonCount))
            {
                return(null);
            }

            int ionCount = settings.Libraries.IonCount;

            if (!helper.ValidateNumberTextBox(txtIonCount, TransitionLibraries.MIN_ION_COUNT, TransitionLibraries.MAX_ION_COUNT, out ionCount))
            {
                return(null);
            }

            if (minIonCount > ionCount)
            {
                helper.ShowTextBoxError(txtIonCount, string.Format(Resources.TransitionLibraries_DoValidate_Library_ion_count_value__0__must_not_be_less_than_min_ion_count_value__1__,
                                                                   ionCount, minIonCount));
                return(null);
            }

            TransitionLibraryPick pick = settings.Libraries.Pick != TransitionLibraryPick.none ? settings.Libraries.Pick : TransitionLibraryPick.all;
            var libraries = new TransitionLibraries(ionMatchTolerance, minIonCount, ionCount, pick);

            Helpers.AssignIfEquals(ref libraries, settings.Libraries);

            return(new TransitionSettings(settings.Prediction, filter, libraries, settings.Integration, settings.Instrument, settings.FullScan));
        }
Exemplo n.º 21
0
        /// <summary>
        /// For creating at the Molecule level (create molecule and first transition group) or modifying at the transition level
        /// Null values imply "don't ask user for this"
        /// </summary>
        public EditCustomMoleculeDlg(SkylineWindow parent, string title, Identity initialId, IEnumerable <Identity> existingIds, int minCharge, int maxCharge,
                                     SrmSettings settings, string defaultName, string defaultFormula, int?defaultCharge, ExplicitTransitionGroupValues explicitAttributes,
                                     ExplicitRetentionTimeInfo explicitRetentionTime,
                                     IsotopeLabelType defaultIsotopeLabelType, bool enableFormulaEditing = true)
        {
            Text                = title;
            _parent             = parent;
            _initialId          = initialId;
            _existingIds        = existingIds;
            _minCharge          = minCharge;
            _maxCharge          = maxCharge;
            _transitionSettings = settings != null ? settings.TransitionSettings : null;
            _peptideSettings    = settings != null ? settings.PeptideSettings : null;

            InitializeComponent();

            NameText = defaultName;
            var needOptionalValuesBox = explicitRetentionTime != null || explicitAttributes != null;
            var heightDelta           = 0;

            if (explicitAttributes == null)
            {
                ResultExplicitTransitionGroupValues = null;
                labelCollisionEnergy.Visible        = false;
                textCollisionEnergy.Visible         = false;
                labelSLens.Visible = false;
                textSLens.Visible  = false;
                labelCompensationVoltage.Visible           = false;
                textCompensationVoltage.Visible            = false;
                labelConeVoltage.Visible                   = false;
                textConeVoltage.Visible                    = false;
                labelDriftTimeHighEnergyOffsetMsec.Visible = false;
                textDriftTimeHighEnergyOffsetMsec.Visible  = false;
                labelDriftTimeMsec.Visible                 = false;
                textDriftTimeMsec.Visible                  = false;
                if (needOptionalValuesBox)
                {
                    // We blanked out everything but the retention time
                    var vmargin   = labelRetentionTime.Location.Y;
                    var newHeight = textRetentionTime.Location.Y + textRetentionTime.Height + vmargin;
                    heightDelta = groupBoxOptionalValues.Height - newHeight;
                    groupBoxOptionalValues.Height = newHeight;
                }
            }
            else
            {
                ResultExplicitTransitionGroupValues = new ExplicitTransitionGroupValues(explicitAttributes);
            }

            string labelAverage = defaultCharge.HasValue
                ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_m_z_
                : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_mass_;
            string labelMono = defaultCharge.HasValue
                ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_m_z_
                : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_mass_;

            _formulaBox =
                new FormulaBox(Resources.EditMeasuredIonDlg_EditMeasuredIonDlg_Ion__chemical_formula_,
                               labelAverage,
                               labelMono,
                               defaultCharge)
            {
                Formula  = defaultFormula,
                Location = new Point(textName.Left, textName.Bottom + 12)
            };
            Controls.Add(_formulaBox);
            _formulaBox.TabIndex = 2;
            _formulaBox.Enabled  = enableFormulaEditing;
            bool needCharge = defaultCharge.HasValue;

            textCharge.Visible = labelCharge.Visible = needCharge;
            Charge             = defaultCharge ?? 0;
            if (needOptionalValuesBox && !needCharge)
            {
                heightDelta += groupBoxOptionalValues.Location.Y - labelCharge.Location.Y;
                groupBoxOptionalValues.Location = new Point(groupBoxOptionalValues.Location.X, labelCharge.Location.Y);
            }
            if (explicitRetentionTime == null)
            {
                // Don't ask user for retetention times
                RetentionTime                    = null;
                RetentionTimeWindow              = null;
                labelRetentionTime.Visible       = false;
                labelRetentionTimeWindow.Visible = false;
                textRetentionTime.Visible        = false;
                textRetentionTimeWindow.Visible  = false;
                if (needOptionalValuesBox)
                {
                    var rtHeight = labelCollisionEnergy.Location.Y - labelRetentionTimeWindow.Location.Y;
                    groupBoxOptionalValues.Height -= rtHeight;
                    heightDelta += rtHeight;
                }
            }
            else
            {
                RetentionTime       = explicitRetentionTime.RetentionTime;
                RetentionTimeWindow = explicitRetentionTime.RetentionTimeWindow;
            }
            if (!needOptionalValuesBox)
            {
                groupBoxOptionalValues.Visible = false;
                heightDelta = groupBoxOptionalValues.Height;
            }
            // Initialize label
            if (settings != null && defaultIsotopeLabelType != null)
            {
                _driverLabelType = new PeptideSettingsUI.LabelTypeComboDriver(comboIsotopeLabelType,
                                                                              settings.PeptideSettings.Modifications, null, null, null, null)
                {
                    SelectedName = defaultIsotopeLabelType.Name
                };
            }
            else
            {
                comboIsotopeLabelType.Visible = false;
                labelIsotopeLabelType.Visible = false;
            }
            Height -= heightDelta;
        }
Exemplo n.º 22
0
        public void ReporterIonTest()
        {
            // Test the code that updates old-style formulas
            Assert.AreEqual("C5C'H13N2", BioMassCalc.AddH("C5C'H12N2"));
            Assert.AreEqual("CO2H", BioMassCalc.AddH("CO2"));

            var          docOriginal = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(instrument => instrument.ChangeMinMz(10))); // H2O2 is not very heavy!
            IdentityPath path;
            SrmDocument  docPeptide = docOriginal.ImportFasta(new StringReader(">peptide1\nPEPMCIDEPR"),
                                                              true, IdentityPath.ROOT, out path);

            // One of the prolines should have caused an extra transition
            Assert.AreEqual(4, docPeptide.PeptideTransitionCount);
            Assert.IsTrue(docPeptide.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 8));

            const string formula          = "H2O2"; // This was H2O, but that falls below mz=10 at z > 1
            const string hydrogenPeroxide = "Hydrogen Perxoide";
            var          reporterIons     = new[] { new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.SINGLY_PROTONATED), new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.DOUBLY_PROTONATED), new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.TRIPLY_PROTONATED), MeasuredIonList.NTERM_PROLINE };
            SrmDocument  docReporterIon   = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter =>
                                                                                                                 filter.ChangeMeasuredIons(reporterIons)));

            AssertEx.IsDocumentTransitionCount(docReporterIon, 7);

            //Check With Monoisotopic
            var mass = BioMassCalc.MONOISOTOPIC.CalculateMassFromFormula(formula);

            for (int i = 0; i < 3; i++)
            {
                TransitionDocNode tranNode = docReporterIon.MoleculeTransitions.ElementAt(i);
                Transition        tran     = tranNode.Transition;
                Assert.AreEqual(reporterIons[i].SettingsCustomIon, tran.CustomIon);
                Assert.AreEqual(tran.Charge, i + 1);
                Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, tran.Adduct), tranNode.Mz, BioMassCalc.MassElectron / 100);
            }

            //Check with Average
            TransitionPrediction predSettings =
                docReporterIon.Settings.TransitionSettings.Prediction.ChangeFragmentMassType(MassType.Average);
            TransitionSettings tranSettings    = docReporterIon.Settings.TransitionSettings.ChangePrediction(predSettings);
            SrmSettings        srmSettings     = docReporterIon.Settings.ChangeTransitionSettings(tranSettings);
            SrmDocument        averageDocument = docReporterIon.ChangeSettings(srmSettings);

            mass = BioMassCalc.AVERAGE.CalculateMassFromFormula(formula);
            for (int i = 0; i < 3; i++)
            {
                TransitionDocNode tranNode = averageDocument.MoleculeTransitions.ElementAt(i);
                Transition        tran     = tranNode.Transition;
                Assert.AreEqual(reporterIons[i].SettingsCustomIon, tran.CustomIon);
                Assert.AreEqual(tran.Charge, i + 1);
                Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, tran.Adduct), tranNode.Mz, BioMassCalc.MassElectron / 100);
            }

            //Make sure the rest of the transitions aren't reporter ions
            for (int i = 3; i < 7; i++)
            {
                Transition tran = docReporterIon.MoleculeTransitions.ElementAt(i).Transition;
                Assert.AreNotEqual(tran.CustomIon, reporterIons);
            }
            var         optionalIon = new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.SINGLY_PROTONATED, true);
            SrmDocument optionalDoc = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter =>
                                                                                                           filter.ChangeMeasuredIons(new[] { optionalIon })));

            Assert.AreEqual(3, optionalDoc.PeptideTransitionCount);
            optionalDoc = optionalDoc.ChangeSettings(optionalDoc.Settings.ChangeTransitionFilter(filter =>
                                                                                                 filter.ChangeMeasuredIons(new[] { optionalIon.ChangeIsOptional(false) })));
            AssertEx.IsDocumentTransitionCount(optionalDoc, 4);
            Assert.AreEqual(optionalIon.ChangeIsOptional(false).SettingsCustomIon,
                            optionalDoc.MoleculeTransitions.ElementAt(0).Transition.CustomIon);
            optionalDoc =
                optionalDoc.ChangeSettings(
                    optionalDoc.Settings.ChangeTransitionFilter(
                        filter => filter.ChangeMeasuredIons(new[] { optionalIon.ChangeIsOptional(true) })));


            TransitionGroupDocNode nodeGroup = optionalDoc.MoleculeTransitionGroups.ElementAt(0);
            var filteredNodes =
                nodeGroup.GetPrecursorChoices(optionalDoc.Settings,
                                              optionalDoc.Molecules.ElementAt(0).ExplicitMods, true)
                .Cast <TransitionDocNode>()
                .Where(node => Equals(node.Transition.CustomIon, optionalIon.SettingsCustomIon));

            var unfilteredNodes =
                nodeGroup.GetPrecursorChoices(optionalDoc.Settings,
                                              optionalDoc.Molecules.ElementAt(0).ExplicitMods, false)
                .Cast <TransitionDocNode>()
                .Where(node => Equals(node.Transition.CustomIon, optionalIon.SettingsCustomIon));

            Assert.AreEqual(0, filteredNodes.Count());
            Assert.AreEqual(1, unfilteredNodes.Count());
        }
Exemplo n.º 23
0
        /// <summary>
        /// For creating at the Molecule level (create molecule and first transition group) or modifying at the transition level
        /// Null values imply "don't ask user for this"
        /// </summary>
        public EditCustomMoleculeDlg(SkylineWindow parent, string title, Identity initialId, IEnumerable<Identity> existingIds, int minCharge, int maxCharge,
            SrmSettings settings, string defaultName, string defaultFormula, int? defaultCharge, ExplicitTransitionGroupValues explicitAttributes,
            ExplicitRetentionTimeInfo explicitRetentionTime,
            IsotopeLabelType defaultIsotopeLabelType, bool enableFormulaEditing = true)
        {
            Text = title;
            _parent = parent;
            _initialId = initialId;
            _existingIds = existingIds;
            _minCharge = minCharge;
            _maxCharge = maxCharge;
            _transitionSettings = settings != null ? settings.TransitionSettings : null;
            _peptideSettings = settings != null ? settings.PeptideSettings : null;

            InitializeComponent();

            NameText = defaultName;
            var needOptionalValuesBox = explicitRetentionTime != null || explicitAttributes != null;
            var heightDelta = 0;

            if (explicitAttributes == null)
            {
                ResultExplicitTransitionGroupValues = null;
                labelCollisionEnergy.Visible = false;
                textCollisionEnergy.Visible = false;
                labelSLens.Visible = false;
                textSLens.Visible = false;
                labelCompensationVoltage.Visible = false;
                textCompensationVoltage.Visible = false;
                labelConeVoltage.Visible = false;
                textConeVoltage.Visible = false;
                labelDriftTimeHighEnergyOffsetMsec.Visible = false;
                textDriftTimeHighEnergyOffsetMsec.Visible = false;
                labelDriftTimeMsec.Visible = false;
                textDriftTimeMsec.Visible = false;
                if (needOptionalValuesBox)
                {
                    // We blanked out everything but the retention time
                    var vmargin = labelRetentionTime.Location.Y;
                    var newHeight = textRetentionTime.Location.Y + textRetentionTime.Height +  vmargin;
                    heightDelta = groupBoxOptionalValues.Height - newHeight;
                    groupBoxOptionalValues.Height = newHeight;
                }
            }
            else
            {
                ResultExplicitTransitionGroupValues = new ExplicitTransitionGroupValues(explicitAttributes);
            }

            string labelAverage = defaultCharge.HasValue
                ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_m_z_
                : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_mass_;
            string labelMono = defaultCharge.HasValue
                ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_m_z_
                : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_mass_;

            _formulaBox =
                new FormulaBox(Resources.EditMeasuredIonDlg_EditMeasuredIonDlg_Ion__chemical_formula_,
                    labelAverage,
                    labelMono,
                    defaultCharge)
                {
                    Formula = defaultFormula,
                    Location = new Point(textName.Left, textName.Bottom + 12)
                };
            Controls.Add(_formulaBox);
            _formulaBox.TabIndex = 2;
            _formulaBox.Enabled = enableFormulaEditing;
            bool needCharge = defaultCharge.HasValue;
            textCharge.Visible = labelCharge.Visible = needCharge;
            Charge = defaultCharge ?? 0;
            if (needOptionalValuesBox && !needCharge)
            {
                heightDelta += groupBoxOptionalValues.Location.Y - labelCharge.Location.Y;
                groupBoxOptionalValues.Location = new Point(groupBoxOptionalValues.Location.X, labelCharge.Location.Y);
            }
            if (explicitRetentionTime == null)
            {
                // Don't ask user for retetention times
                RetentionTime = null;
                RetentionTimeWindow = null;
                labelRetentionTime.Visible = false;
                labelRetentionTimeWindow.Visible = false;
                textRetentionTime.Visible = false;
                textRetentionTimeWindow.Visible = false;
                if (needOptionalValuesBox)
                {
                    var rtHeight = labelCollisionEnergy.Location.Y - labelRetentionTimeWindow.Location.Y;
                    groupBoxOptionalValues.Height -= rtHeight;
                    heightDelta += rtHeight;
                }
            }
            else
            {
                RetentionTime = explicitRetentionTime.RetentionTime;
                RetentionTimeWindow = explicitRetentionTime.RetentionTimeWindow;
            }
            if (!needOptionalValuesBox)
            {
                groupBoxOptionalValues.Visible = false;
                heightDelta = groupBoxOptionalValues.Height;
            }
            // Initialize label
            if (settings != null && defaultIsotopeLabelType != null)
            {
                _driverLabelType = new PeptideSettingsUI.LabelTypeComboDriver(comboIsotopeLabelType,
                    settings.PeptideSettings.Modifications, null, null, null, null)
                {
                    SelectedName = defaultIsotopeLabelType.Name
                };
            }
            else
            {
                comboIsotopeLabelType.Visible = false;
                labelIsotopeLabelType.Visible = false;
            }
            Height -= heightDelta;
        }
Exemplo n.º 24
0
        private bool UpdateFullScanSettings()
        {
            var helper = new MessageBoxHelper(this);

            // Validate and store MS1 full-scan settings

            // If high resolution MS1 filtering is enabled, make sure precursor m/z type
            // is monoisotopic and isotope enrichments are set
            var precursorIsotopes     = FullScanSettingsControl.PrecursorIsotopesCurrent;
            var precursorAnalyzerType = FullScanSettingsControl.PrecursorMassAnalyzer;
            var precursorMassType     = TransitionSettings.Prediction.PrecursorMassType;

            if (precursorIsotopes == FullScanPrecursorIsotopes.None)
            {
                if (WorkflowType != Workflow.dia)
                {
                    MessageDlg.Show(this, Resources.ImportPeptideSearchDlg_UpdateFullScanSettings_Full_scan_MS1_filtering_must_be_enabled_in_order_to_import_a_peptide_search_);
                    return(false);
                }
                else if (FullScanSettingsControl.AcquisitionMethod == FullScanAcquisitionMethod.None)
                {
                    MessageDlg.Show(this, Resources.ImportPeptideSearchDlg_UpdateFullScanSettings_Full_scan_MS1_or_MS_MS_filtering_must_be_enabled_in_order_to_import_a_peptide_search_);
                    return(false);
                }
            }
            else if (precursorAnalyzerType != FullScanMassAnalyzerType.qit)
            {
                precursorMassType = MassType.Monoisotopic;
                if (FullScanSettingsControl.Enrichments == null)
                {
                    MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers);
                    return(false);
                }
            }

            if (FullScanSettingsControl.IsolationScheme == null && FullScanSettingsControl.AcquisitionMethod == FullScanAcquisitionMethod.DIA)
            {
                MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors);
                return(false);
            }

            TransitionFilter filter = TransitionSettings.Filter;

            if (FullScanSettingsControl.PrecursorChargesTextBox.Visible)
            {
                Adduct[] precursorCharges;
                if (!TransitionSettingsControl.ValidateAdductListTextBox(helper, FullScanSettingsControl.PrecursorChargesTextBox, true, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE, out precursorCharges))
                {
                    return(false);
                }
                precursorCharges = precursorCharges.Distinct().ToArray();
                FullScanSettingsControl.PrecursorChargesString = TransitionFilter.AdductListToString(precursorCharges);
                filter = TransitionSettings.Filter.ChangePeptidePrecursorCharges(precursorCharges);
            }
            if (WorkflowType == Workflow.dda && !filter.PeptideIonTypes.Contains(IonType.precursor))
            {
                filter = filter.ChangePeptideIonTypes(new[] { IonType.precursor });
            }
            if (!filter.AutoSelect)
            {
                filter = filter.ChangeAutoSelect(true);
            }
            Helpers.AssignIfEquals(ref filter, TransitionSettings.Filter);

            if (FullScanSettingsControl.IsDIA() && filter.ExclusionUseDIAWindow)
            {
                if (FullScanSettingsControl.IsolationScheme.IsAllIons)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_);
                    return(false);
                }
                if (FullScanSettingsControl.IsolationScheme.FromResults)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_);
                    return(false);
                }
            }

            TransitionFullScan fullScan;

            if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan))
            {
                return(false);
            }

            Helpers.AssignIfEquals(ref fullScan, TransitionSettings.FullScan);

            var prediction = TransitionSettings.Prediction.ChangePrecursorMassType(precursorMassType);

            Helpers.AssignIfEquals(ref prediction, TransitionSettings.Prediction);

            TransitionSettings settings;

            try
            {
                settings = new TransitionSettings(prediction, filter,
                                                  TransitionSettings.Libraries, TransitionSettings.Integration, TransitionSettings.Instrument, fullScan);
            }
            catch (Exception x)
            {
                MessageDlg.Show(this, x.Message);
                return(false);
            }

            // Did user change the "use spectral libary ion mobility" values?
            PeptidePrediction updatedPeptidePrediction;
            bool peptidePredictionChanged = false;

            try
            {
                updatedPeptidePrediction =
                    FullScanSettingsControl.UseSpectralLibraryIonMobilityValuesControl.ValidateNewSettings(true);
                if (updatedPeptidePrediction == null)
                {
                    return(false);
                }

                peptidePredictionChanged = !Equals(Document.Settings.PeptideSettings.Prediction, updatedPeptidePrediction);
            }
            catch (Exception)
            {
                return(false);
            }


            // Only update, if anything changed
            if (Equals(settings, TransitionSettings) && !peptidePredictionChanged)
            {
                return(true);
            }

            ModifyDocumentNoUndo(doc => doc.ChangeSettings(doc.Settings.ChangeTransitionSettings(settings).ChangePeptideSettings(doc.Settings.PeptideSettings.ChangePrediction(updatedPeptidePrediction))));
            _fullScanSettingsChanged = true;
            return(true);
        }
Exemplo n.º 25
0
        public TransitionSettingsUI(SkylineWindow parent)
        {
            InitializeComponent();

            // Populate the fragment finder combo boxes
            foreach (string item in TransitionFilter.GetStartFragmentFinderLabels())
            {
                comboRangeFrom.Items.Add(item);
            }
            foreach (string item in TransitionFilter.GetEndFragmentFinderLabels())
            {
                comboRangeTo.Items.Add(item);
            }

            _parent             = parent;
            _transitionSettings = _parent.DocumentUI.Settings.TransitionSettings;

            // Initialize prediction settings
            comboPrecursorMass.SelectedItem = Prediction.PrecursorMassType.GetLocalizedString();
            comboIonMass.SelectedItem       = Prediction.FragmentMassType.GetLocalizedString();

            _driverCE = new SettingsListComboDriver <CollisionEnergyRegression>(comboCollisionEnergy,
                                                                                Settings.Default.CollisionEnergyList);
            string sel = (Prediction.CollisionEnergy == null ? null : Prediction.CollisionEnergy.Name);

            _driverCE.LoadList(sel);

            _driverDP = new SettingsListComboDriver <DeclusteringPotentialRegression>(comboDeclusterPotential,
                                                                                      Settings.Default.DeclusterPotentialList);
            sel = (Prediction.DeclusteringPotential == null ? null : Prediction.DeclusteringPotential.Name);
            _driverDP.LoadList(sel);

            _driverCoV = new SettingsListComboDriver <CompensationVoltageParameters>(comboCompensationVoltage,
                                                                                     Settings.Default.CompensationVoltageList);
            _driverCoV.LoadList(Prediction.CompensationVoltage == null ? null : Prediction.CompensationVoltage.Name);

            _driverOptimizationLibrary = new SettingsListComboDriver <OptimizationLibrary>(comboOptimizationLibrary,
                                                                                           Settings.Default.OptimizationLibraryList);
            _driverOptimizationLibrary.LoadList(Prediction.OptimizedLibrary == null ? null : Prediction.OptimizedLibrary.Name);

            if (Prediction.OptimizedMethodType == OptimizedMethodType.None)
            {
                comboOptimizeType.SelectedIndex = 0;
            }
            else
            {
                cbUseOptimized.Checked         = true;
                comboOptimizeType.SelectedItem = Prediction.OptimizedMethodType.GetLocalizedString();
            }

            // Initialize filter settings
            textPrecursorCharges.Text   = Filter.PrecursorCharges.ToArray().ToString(", "); // Not L10N? Internationalization of comma?
            textIonCharges.Text         = Filter.ProductCharges.ToArray().ToString(", ");   // Not L10N? Internationalization of comma?
            textIonTypes.Text           = TransitionFilter.ToStringIonTypes(Filter.IonTypes, true);
            comboRangeFrom.SelectedItem = Filter.FragmentRangeFirst.Label;
            comboRangeTo.SelectedItem   = Filter.FragmentRangeLast.Label;
            textExclusionWindow.Text    = Filter.PrecursorMzWindow != 0
                                           ? Filter.PrecursorMzWindow.ToString(LocalizationHelper.CurrentCulture)
                                           : string.Empty;
            cbExclusionUseDIAWindow.Checked = Filter.ExclusionUseDIAWindow;
            cbAutoSelect.Checked            = Filter.AutoSelect;

            _driverIons = new MeasuredIonListBoxDriver(listAlwaysAdd, Settings.Default.MeasuredIonList);
            _driverIons.LoadList(Filter.MeasuredIons);

            // Initialize library settings
            cbLibraryPick.Checked = (Libraries.Pick != TransitionLibraryPick.none);
            panelPick.Visible     = cbLibraryPick.Checked;
            textTolerance.Text    = Libraries.IonMatchTolerance.ToString(LocalizationHelper.CurrentCulture);
            textIonCount.Text     = Libraries.IonCount.ToString(LocalizationHelper.CurrentCulture);
            if (Libraries.Pick == TransitionLibraryPick.filter)
            {
                radioFiltered.Checked = true;
            }
            else if (Libraries.Pick == TransitionLibraryPick.all_plus)
            {
                radioAllAndFiltered.Checked = true;
            }

            // Initialize instrument settings
            textMinMz.Text            = Instrument.MinMz.ToString(LocalizationHelper.CurrentCulture);
            textMaxMz.Text            = Instrument.MaxMz.ToString(LocalizationHelper.CurrentCulture);
            cbDynamicMinimum.Checked  = Instrument.IsDynamicMin;
            textMzMatchTolerance.Text = Instrument.MzMatchTolerance.ToString(LocalizationHelper.CurrentCulture);
            if (Instrument.MaxTransitions.HasValue)
            {
                textMaxTrans.Text = Instrument.MaxTransitions.Value.ToString(LocalizationHelper.CurrentCulture);
            }
            if (Instrument.MaxInclusions.HasValue)
            {
                textMaxInclusions.Text = Instrument.MaxInclusions.Value.ToString(LocalizationHelper.CurrentCulture);
            }
            if (Instrument.MinTime.HasValue)
            {
                textMinTime.Text = Instrument.MinTime.Value.ToString(LocalizationHelper.CurrentCulture);
            }
            if (Instrument.MaxTime.HasValue)
            {
                textMaxTime.Text = Instrument.MaxTime.Value.ToString(LocalizationHelper.CurrentCulture);
            }

            // Initialize full-scan settings
            FullScanSettingsControl = new FullScanSettingsControl(_parent)
            {
                Anchor   = (AnchorStyles.Top | AnchorStyles.Left),
                Location = new Point(0, 0),
                Size     = new Size(363, 491)
            };
            FullScanSettingsControl.IsolationSchemeChangedEvent += IsolationSchemeChanged;
            tabFullScan.Controls.Add(FullScanSettingsControl);

            // VISUAL:
            // - Store the distance between the cbExclusionDIAWindow and the lower end of the box (to use as margin later)
            // - Shift the cbExclusionDIAWindow down (it is only higher in the designer for better manipulation)
            _lower_margin = groupBox1.Height - textExclusionWindow.Location.Y - textExclusionWindow.Height;
            int pixelShift = cbExclusionUseDIAWindow.Location.Y - lbPrecursorMzWindow.Location.Y;

            cbExclusionUseDIAWindow.Location = new Point(cbExclusionUseDIAWindow.Location.X, cbExclusionUseDIAWindow.Location.Y - pixelShift);

            DoIsolationSchemeChanged();
        }
Exemplo n.º 26
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            // Validate and store prediction settings
            string   massType          = comboPrecursorMass.SelectedItem.ToString();
            MassType precursorMassType = MassTypeExtension.GetEnum(massType);

            massType = comboIonMass.SelectedItem.ToString();
            MassType fragmentMassType = MassTypeExtension.GetEnum(massType);
            string   nameCE           = comboCollisionEnergy.SelectedItem.ToString();
            CollisionEnergyRegression collisionEnergy =
                Settings.Default.GetCollisionEnergyByName(nameCE);
            string nameDP = comboDeclusterPotential.SelectedItem.ToString();
            DeclusteringPotentialRegression declusteringPotential =
                Settings.Default.GetDeclusterPotentialByName(nameDP);
            string nameCoV = comboCompensationVoltage.SelectedItem.ToString();
            CompensationVoltageParameters compensationVoltage =
                Settings.Default.GetCompensationVoltageByName(nameCoV);
            string nameOptLib = comboOptimizationLibrary.SelectedItem.ToString();
            OptimizationLibrary optimizationLibrary =
                Settings.Default.GetOptimizationLibraryByName(nameOptLib);
            OptimizedMethodType optimizedMethodType = OptimizedMethodType.None;

            if (cbUseOptimized.Checked)
            {
                optimizedMethodType = OptimizedMethodTypeExtension.GetEnum(comboOptimizeType.SelectedItem.ToString());
            }
            TransitionPrediction prediction = new TransitionPrediction(precursorMassType,
                                                                       fragmentMassType, collisionEnergy,
                                                                       declusteringPotential,
                                                                       compensationVoltage,
                                                                       optimizationLibrary,
                                                                       optimizedMethodType);

            Helpers.AssignIfEquals(ref prediction, Prediction);

            // Validate and store filter settings
            int[] precursorCharges;
            int   min = TransitionGroup.MIN_PRECURSOR_CHARGE;
            int   max = TransitionGroup.MAX_PRECURSOR_CHARGE;

            if (!helper.ValidateNumberListTextBox(tabControl1, (int)TABS.Filter, textPrecursorCharges,
                                                  min, max, out precursorCharges))
            {
                return;
            }
            precursorCharges = precursorCharges.Distinct().ToArray();

            int[] productCharges;
            min = Transition.MIN_PRODUCT_CHARGE;
            max = Transition.MAX_PRODUCT_CHARGE;
            if (!helper.ValidateNumberListTextBox(tabControl1, (int)TABS.Filter, textIonCharges,
                                                  min, max, out productCharges))
            {
                return;
            }
            productCharges = productCharges.Distinct().ToArray();

            IonType[] types = TransitionFilter.ParseTypes(textIonTypes.Text, new IonType[0]);
            if (types.Length == 0)
            {
                helper.ShowTextBoxError(tabControl1, (int)TABS.Filter, textIonTypes,
                                        Resources.TransitionSettingsUI_OkDialog_Ion_types_must_contain_a_comma_separated_list_of_ion_types_a_b_c_x_y_z_and_p_for_precursor);
                return;
            }
            types = types.Distinct().ToArray();

            double exclusionWindow = 0;

            if (!string.IsNullOrEmpty(textExclusionWindow.Text) &&
                !Equals(textExclusionWindow.Text, exclusionWindow.ToString(LocalizationHelper.CurrentCulture)))
            {
                if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Filter, textExclusionWindow,
                                                   TransitionFilter.MIN_EXCLUSION_WINDOW, TransitionFilter.MAX_EXCLUSION_WINDOW, out exclusionWindow))
                {
                    return;
                }
            }

            string fragmentRangeFirst = TransitionFilter.GetStartFragmentNameFromLabel(comboRangeFrom.SelectedItem.ToString());
            string fragmentRangeLast  = TransitionFilter.GetEndFragmentNameFromLabel(comboRangeTo.SelectedItem.ToString());

            var  measuredIons          = _driverIons.Chosen;
            bool autoSelect            = cbAutoSelect.Checked;
            bool exclusionUseDIAWindow = FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked;
            var  filter = new TransitionFilter(precursorCharges, productCharges, types,
                                               fragmentRangeFirst, fragmentRangeLast, measuredIons,
                                               exclusionWindow, exclusionUseDIAWindow, autoSelect);

            Helpers.AssignIfEquals(ref filter, Filter);

            // Validate and store library settings
            TransitionLibraryPick pick = TransitionLibraryPick.none;

            if (cbLibraryPick.Checked)
            {
                if (radioAll.Checked)
                {
                    pick = TransitionLibraryPick.all;
                }
                else if (radioAllAndFiltered.Checked)
                {
                    pick = TransitionLibraryPick.all_plus;
                }
                else
                {
                    pick = TransitionLibraryPick.filter;
                }
            }

            double ionMatchTolerance;

            double minTol = TransitionLibraries.MIN_MATCH_TOLERANCE;
            double maxTol = TransitionLibraries.MAX_MATCH_TOLERANCE;

            if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Library, textTolerance,
                                               minTol, maxTol, out ionMatchTolerance))
            {
                return;
            }

            int ionCount = Libraries.IonCount;

            if (pick != TransitionLibraryPick.none)
            {
                min = TransitionLibraries.MIN_ION_COUNT;
                max = TransitionLibraries.MAX_ION_COUNT;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Library, textIonCount,
                                                  min, max, out ionCount))
                {
                    return;
                }
            }

            TransitionLibraries libraries = new TransitionLibraries(ionMatchTolerance, ionCount, pick);

            Helpers.AssignIfEquals(ref libraries, Libraries);

            // This dialog does not yet change integration settings
            TransitionIntegration integration = _transitionSettings.Integration;

            // Validate and store instrument settings
            int minMz;

            min = TransitionInstrument.MIN_MEASUREABLE_MZ;
            max = TransitionInstrument.MAX_MEASURABLE_MZ - TransitionInstrument.MIN_MZ_RANGE;
            if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMinMz, min, max, out minMz))
            {
                return;
            }
            int maxMz;

            min = minMz + TransitionInstrument.MIN_MZ_RANGE;
            max = TransitionInstrument.MAX_MEASURABLE_MZ;
            if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxMz, min, max, out maxMz))
            {
                return;
            }
            bool   isDynamicMin = cbDynamicMinimum.Checked;
            double mzMatchTolerance;

            minTol = TransitionInstrument.MIN_MZ_MATCH_TOLERANCE;
            maxTol = TransitionInstrument.MAX_MZ_MATCH_TOLERANCE;
            if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Instrument, textMzMatchTolerance,
                                               minTol, maxTol, out mzMatchTolerance))
            {
                return;
            }
            int?maxTrans = null;

            if (!string.IsNullOrEmpty(textMaxTrans.Text))
            {
                int maxTransTemp;
                min = TransitionInstrument.MIN_TRANSITION_MAX;
                max = TransitionInstrument.MAX_TRANSITION_MAX;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxTrans,
                                                  min, max, out maxTransTemp))
                {
                    return;
                }
                maxTrans = maxTransTemp;
            }
            int?maxInclusions = null;

            if (!string.IsNullOrEmpty(textMaxInclusions.Text))
            {
                int maxInclusionsTemp;
                min = TransitionInstrument.MIN_INCLUSION_MAX;
                max = TransitionInstrument.MAX_INCLUSION_MAX;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxInclusions,
                                                  min, max, out maxInclusionsTemp))
                {
                    return;
                }
                maxInclusions = maxInclusionsTemp;
            }
            int?minTime = null, maxTime = null;

            min = TransitionInstrument.MIN_TIME;
            max = TransitionInstrument.MAX_TIME;
            if (!string.IsNullOrEmpty(textMinTime.Text))
            {
                int minTimeTemp;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMinTime,
                                                  min, max, out minTimeTemp))
                {
                    return;
                }
                minTime = minTimeTemp;
            }
            if (!string.IsNullOrEmpty(textMaxTime.Text))
            {
                int maxTimeTemp;
                if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxTime,
                                                  min, max, out maxTimeTemp))
                {
                    return;
                }
                maxTime = maxTimeTemp;
            }
            if (minTime.HasValue && maxTime.HasValue && maxTime.Value - minTime.Value < TransitionInstrument.MIN_TIME_RANGE)
            {
                helper.ShowTextBoxError(tabControl1, (int)TABS.Instrument, textMaxTime,
                                        string.Format(Resources.TransitionSettingsUI_OkDialog_The_allowable_retention_time_range__0__to__1__must_be_at_least__2__minutes_apart,
                                                      minTime, maxTime, TransitionInstrument.MIN_TIME_RANGE));
                return;
            }

            TransitionInstrument instrument = new TransitionInstrument(minMz,
                                                                       maxMz, isDynamicMin, mzMatchTolerance, maxTrans, maxInclusions, minTime, maxTime);

            Helpers.AssignIfEquals(ref instrument, Instrument);

            // Validate and store full-scan settings

            // If high resolution MS1 filtering is enabled, make sure precursor m/z type
            // is monoisotopic and isotope enrichments are set
            FullScanPrecursorIsotopes precursorIsotopes = PrecursorIsotopesCurrent;
            FullScanMassAnalyzerType  precursorAnalyzerType = PrecursorMassAnalyzer;

            if (precursorIsotopes != FullScanPrecursorIsotopes.None &&
                precursorAnalyzerType != FullScanMassAnalyzerType.qit)
            {
                if (precursorMassType != MassType.Monoisotopic)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_High_resolution_MS1_filtering_requires_use_of_monoisotopic_precursor_masses);
                    tabControl1.SelectedIndex = (int)TABS.Prediction;
                    comboPrecursorMass.Focus();
                    return;
                }

                if (FullScanSettingsControl.Enrichments == null)
                {
                    tabControl1.SelectedIndex = (int)TABS.FullScan;
                    MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers);
                    FullScanSettingsControl.ComboEnrichmentsSetFocus();
                    return;
                }
            }

            IsolationScheme           isolationScheme = FullScanSettingsControl.IsolationScheme;
            FullScanAcquisitionMethod acquisitionMethod = AcquisitionMethod;

            if (isolationScheme == null && acquisitionMethod == FullScanAcquisitionMethod.DIA)
            {
                tabControl1.SelectedIndex = (int)TABS.FullScan;
                MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors);
                FullScanSettingsControl.ComboIsolationSchemeSetFocus();
                return;
            }

            if (isolationScheme != null && isolationScheme.WindowsPerScan.HasValue && !maxInclusions.HasValue)
            {
                MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Before_performing_a_multiplexed_DIA_scan_the_instrument_s_firmware_inclusion_limit_must_be_specified);
                tabControl1.SelectedIndex = (int)TABS.Instrument;
                textMaxInclusions.Focus();
                return;
            }

            if (FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked)
            {
                if (FullScanSettingsControl.IsolationScheme.IsAllIons)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_);
                    tabControl1.SelectedIndex = (int)TABS.Filter;
                    cbExclusionUseDIAWindow.Focus();
                    return;
                }
                if (FullScanSettingsControl.IsolationScheme.FromResults)
                {
                    MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_);
                    tabControl1.SelectedIndex = (int)TABS.Filter;
                    cbExclusionUseDIAWindow.Focus();
                    return;
                }
            }

            TransitionFullScan fullScan;

            if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan, tabControl1, (int)TABS.FullScan))
            {
                return;
            }

            Helpers.AssignIfEquals(ref fullScan, FullScan);

            TransitionSettings settings = new TransitionSettings(prediction,
                                                                 filter, libraries, integration, instrument, fullScan);

            // Only update, if anything changed
            if (!Equals(settings, _transitionSettings))
            {
                if (!_parent.ChangeSettingsMonitored(this, Resources.TransitionSettingsUI_OkDialog_Changing_transition_settings,
                                                     s => s.ChangeTransitionSettings(settings)))
                {
                    return;
                }
                _transitionSettings = settings;
            }

            DialogResult = DialogResult.OK;
        }
Exemplo n.º 27
0
        public SrmSettings ChangeTransitionSettings(TransitionSettings prop)
        {
            // If changing to only MS1 filtering, make sure Integrat All is on
            if (IsOnlyMsEnabled(prop.FullScan) && !IsOnlyMsEnabled(TransitionSettings.FullScan))
            {
                if (!prop.Integration.IsIntegrateAll)
                    prop = prop.ChangeIntegration(prop.Integration.ChangeIntegrateAll(true));
            }

            SrmSettings settings = ChangeProp(ImClone(this), im => im.TransitionSettings = prop);

            if (prop.Prediction.PrecursorMassType != TransitionSettings.Prediction.PrecursorMassType)
                settings.CreatePrecursorMassCalcs();
            if (prop.Prediction.FragmentMassType != TransitionSettings.Prediction.FragmentMassType)
                settings.CreateFragmentMassCalcs();

            return settings;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Makes sure settings loaded from XML are complete, and uses default
        /// values where anything is missing.
        /// </summary>
        private void ValidateLoad()
        {
            SrmSettings defaults = SrmSettingsList.GetDefault();
            PeptideSettings defPep = defaults.PeptideSettings;
            if (PeptideSettings == null)
                PeptideSettings = defPep;
            else
            {
                PeptideSettings = PeptideSettings.MergeDefaults(defPep);
            }

            TransitionSettings defTran = defaults.TransitionSettings;
            if (TransitionSettings == null)
                TransitionSettings = defTran;
            else
            {
                TransitionPrediction prediction = TransitionSettings.Prediction;
                // Backward compatibility: handle the move of RetentionTime
                // from TransitionSettings to PeptideSettings after v0.1.0.0
                if (TransitionSettings.Prediction == null)
                    prediction = defTran.Prediction;
                else if (prediction.RetentionTime != null)
                {
                    if (PeptideSettings.Prediction != null && // Make Resharper happy
                        PeptideSettings.Prediction.RetentionTime == null)
                    {
                        PeptideSettings = PeptideSettings.ChangePrediction(
                            new PeptidePrediction(prediction.RetentionTime));
                    }
                    prediction = new TransitionPrediction(prediction);
                }

                TransitionFilter filter = TransitionSettings.Filter ?? defTran.Filter;
                TransitionLibraries libraries = TransitionSettings.Libraries ?? defTran.Libraries;
                TransitionIntegration integration = TransitionSettings.Integration ?? defTran.Integration;
                TransitionInstrument instrument = TransitionSettings.Instrument ?? defTran.Instrument;
                TransitionFullScan fullScan = TransitionSettings.FullScan ?? defTran.FullScan;
                // Backward compatibility with v2.1, get a RT filter length from peptide prediction settings
                if (fullScan.RetentionTimeFilterType == RetentionTimeFilterType.scheduling_windows &&
                    fullScan.RetentionTimeFilterLength == 0 &&
                    PeptideSettings.Prediction != null)
                {
                    double rtFilterLen = 0;
                    if (PeptideSettings.Prediction.UseMeasuredRTs)
                    {
                        rtFilterLen = PeptideSettings.Prediction.MeasuredRTWindow.Value / 2;
                    }
                    else if (PeptideSettings.Prediction.RetentionTime != null)
                    {
                        rtFilterLen = PeptideSettings.Prediction.RetentionTime.TimeWindow / 2;
                    }
                    if (rtFilterLen > 0)
                    {
                        fullScan = fullScan.ChangeRetentionTimeFilter(fullScan.RetentionTimeFilterType, rtFilterLen);
                    }
                }
                TransitionSettings transitionSettings = new TransitionSettings(prediction,
                                                                               filter,
                                                                               libraries,
                                                                               integration,
                                                                               instrument,
                                                                               fullScan);
                // If the above null checks result in a changed PeptideSettings object,
                // then use the changed version.
                if (!Equals(TransitionSettings, transitionSettings))
                    TransitionSettings = transitionSettings;
            }

            // Initialize mass calculators
            CreatePrecursorMassCalcs();
            CreateFragmentMassCalcs();
        }
Exemplo n.º 29
0
        public SrmSettings(string name, PeptideSettings peptideSettings, TransitionSettings transitionSettings, DataSettings dataSettings, DocumentRetentionTimes documentRetentionTimes)
            : base(name)
        {
            PeptideSettings = peptideSettings;
            TransitionSettings = transitionSettings;
            DataSettings = dataSettings;
            DocumentRetentionTimes = documentRetentionTimes;

            // Create cached calculator instances
            CreatePrecursorMassCalcs();
            CreateFragmentMassCalcs();
        }
Exemplo n.º 30
0
        public override void ReadXml(XmlReader reader)
        {
            // Read tag attributes
            base.ReadXml(reader);
            reader.ReadStartElement();
            PeptideSettings = reader.DeserializeElement<PeptideSettings>();
            TransitionSettings = reader.DeserializeElement<TransitionSettings>();

            // 10.23.12 -- The order of <measured_results> and <data_settings> has been switched to enable parsing (in Panorama)
            // of all annotation definitions before reading any replicate annotations in <measured_results>.
            // We want Skyline to be able to read older documents where <measured_results> come before <data_settings>
            if (reader.IsStartElement(new XmlElementHelper<MeasuredResults>().ElementNames[0]))
            {
                MeasuredResults = reader.DeserializeElement<MeasuredResults>();
                DataSettings = reader.DeserializeElement<DataSettings>() ?? DataSettings.DEFAULT;
            }
            else
            {
                DataSettings = reader.DeserializeElement<DataSettings>() ?? DataSettings.DEFAULT;
                MeasuredResults = reader.DeserializeElement<MeasuredResults>();
            }

            DocumentRetentionTimes = reader.DeserializeElement<DocumentRetentionTimes>() ?? DocumentRetentionTimes.EMPTY;
            reader.ReadEndElement();
            ValidateLoad();
        }
Exemplo n.º 31
0
        /// <summary>
        /// For creating at the Molecule level (create molecule and first transition group) or modifying at the transition level
        /// Null values imply "don't ask user for this"
        /// </summary>
        public EditCustomMoleculeDlg(SkylineWindow parent, UsageMode usageMode, string title, Identity initialId,
                                     IEnumerable <Identity> existingIds, int minCharge, int maxCharge,
                                     SrmSettings settings, CustomMolecule molecule, Adduct defaultCharge,
                                     ExplicitTransitionGroupValues explicitTransitionGroupAttributes,
                                     ExplicitTransitionValues explicitTransitionAttributes,
                                     ExplicitRetentionTimeInfo explicitRetentionTime,
                                     IsotopeLabelType defaultIsotopeLabelType)
        {
            Text                  = title;
            _parent               = parent;
            _initialId            = initialId;
            _existingIds          = existingIds;
            _minCharge            = minCharge;
            _maxCharge            = maxCharge;
            _transitionSettings   = settings != null ? settings.TransitionSettings : null;
            _peptideSettings      = settings != null ? settings.PeptideSettings : null;
            _resultAdduct         = Adduct.EMPTY;
            _resultCustomMolecule = molecule;
            _usageMode            = usageMode;

            var enableFormulaEditing = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.moleculeEdit ||
                                       usageMode == UsageMode.fragment;
            var enableAdductEditing = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.precursor ||
                                      usageMode == UsageMode.fragment;
            var suggestOnlyAdductsWithMass        = usageMode != UsageMode.fragment;
            var needExplicitTransitionValues      = usageMode == UsageMode.fragment;
            var needExplicitTransitionGroupValues = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.precursor;

            InitializeComponent();

            NameText         = molecule == null ? String.Empty : molecule.Name;
            textName.Enabled = usageMode == UsageMode.moleculeNew || usageMode == UsageMode.moleculeEdit ||
                               usageMode == UsageMode.fragment; // Can user edit name?

            var needOptionalValuesBox = explicitRetentionTime != null || explicitTransitionGroupAttributes != null || explicitTransitionAttributes != null;

            if (!needExplicitTransitionValues)
            {
                labelCollisionEnergy.Visible             = false;
                textCollisionEnergy.Visible              = false;
                labelSLens.Visible                       = false;
                textSLens.Visible                        = false;
                labelConeVoltage.Visible                 = false;
                textConeVoltage.Visible                  = false;
                labelIonMobilityHighEnergyOffset.Visible = false;
                textIonMobilityHighEnergyOffset.Visible  = false;
                labelDeclusteringPotential.Visible       = false;
                textDeclusteringPotential.Visible        = false;
            }

            if (!needExplicitTransitionGroupValues)
            {
                labelCCS.Visible                 = false;
                textBoxCCS.Visible               = false;
                labelIonMobility.Visible         = false;
                textIonMobility.Visible          = false;
                labelIonMobilityUnits.Visible    = false;
                comboBoxIonMobilityUnits.Visible = false;
            }

            var heightDelta = 0;

            // Initialise the ion mobility units dropdown with L10N values
            foreach (eIonMobilityUnits t in Enum.GetValues(typeof(eIonMobilityUnits)))
            {
                comboBoxIonMobilityUnits.Items.Add(IonMobilityFilter.IonMobilityUnitsL10NString(t));
            }

            if (needOptionalValuesBox)
            {
                var newHeight = groupBoxOptionalValues.Height;
                var movers    = new List <Control>();
                int offset    = 0;
                if (!needExplicitTransitionGroupValues && !needExplicitTransitionValues)
                {
                    // We blanked out everything but the retention time
                    newHeight = labelCollisionEnergy.Location.Y;
                }
                else if (!needExplicitTransitionGroupValues)
                {
                    // We need to shift transition-level items up to where retention time was
                    movers.AddRange(new Control[] {
                        textCollisionEnergy, labelCollisionEnergy, textDeclusteringPotential, labelDeclusteringPotential, textSLens,
                        labelSLens, textConeVoltage, labelConeVoltage, textIonMobilityHighEnergyOffset, labelIonMobilityHighEnergyOffset
                    });
                    labelIonMobilityHighEnergyOffset.Location = labelIonMobility.Location;
                    textIonMobilityHighEnergyOffset.Location  = textIonMobility.Location;
                    offset    = labelCollisionEnergy.Location.Y - labelRetentionTime.Location.Y;
                    newHeight = textBoxCCS.Location.Y;
                }
                else if (!needExplicitTransitionValues)
                {
                    // We need to shift precursor-level items up to where retention time was
                    movers.AddRange(new Control[] { textBoxCCS, labelCCS, textIonMobility,
                                                    labelIonMobility, comboBoxIonMobilityUnits, labelIonMobilityUnits });
                    offset    = labelIonMobility.Location.Y - (explicitRetentionTime == null ? labelRetentionTime.Location.Y : labelCollisionEnergy.Location.Y);
                    newHeight = explicitRetentionTime == null ? textSLens.Location.Y : textIonMobility.Location.Y;
                }

                foreach (var mover in movers)
                {
                    mover.Anchor   = AnchorStyles.Left | AnchorStyles.Top;
                    mover.Location = new Point(mover.Location.X, mover.Location.Y - offset);
                }

                heightDelta = groupBoxOptionalValues.Height - newHeight;
                groupBoxOptionalValues.Height = newHeight;
            }

            ResultExplicitTransitionGroupValues = new ExplicitTransitionGroupValues(explicitTransitionGroupAttributes);
            ResultExplicitTransitionValues      = new ExplicitTransitionValues(explicitTransitionAttributes);

            string labelAverage = !defaultCharge.IsEmpty
                ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_m_z_
                : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_A_verage_mass_;
            string labelMono = !defaultCharge.IsEmpty
                ? Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_m_z_
                : Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg__Monoisotopic_mass_;
            var defaultFormula = molecule == null ? string.Empty : molecule.Formula;
            var transition     = initialId as Transition;

            FormulaBox.EditMode editMode;
            if (enableAdductEditing && !enableFormulaEditing)
            {
                editMode = FormulaBox.EditMode.adduct_only;
            }
            else if (!enableAdductEditing && enableFormulaEditing)
            {
                editMode = FormulaBox.EditMode.formula_only;
            }
            else
            {
                editMode = FormulaBox.EditMode.formula_and_adduct;
            }
            string formulaBoxLabel;

            if (defaultCharge.IsEmpty)
            {
                formulaBoxLabel = Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_Chemi_cal_formula_;
            }
            else if (editMode == FormulaBox.EditMode.adduct_only)
            {
                var prompt = defaultFormula;
                if (string.IsNullOrEmpty(defaultFormula) && molecule != null)
                {
                    // Defined by mass only
                    prompt = molecule.ToString();
                }
                formulaBoxLabel = string.Format(Resources.EditCustomMoleculeDlg_EditCustomMoleculeDlg_Addu_ct_for__0__,
                                                prompt);
            }
            else
            {
                formulaBoxLabel = Resources.EditMeasuredIonDlg_EditMeasuredIonDlg_Ion__chemical_formula_;
            }

            double?averageMass = null;
            double?monoMass    = null;

            if (transition != null && string.IsNullOrEmpty(defaultFormula) && transition.IsCustom())
            {
                averageMass = transition.CustomIon.AverageMass;
                monoMass    = transition.CustomIon.MonoisotopicMass;
            }
            else if (molecule != null)
            {
                averageMass = molecule.AverageMass;
                monoMass    = molecule.MonoisotopicMass;
            }

            _formulaBox =
                new FormulaBox(false, // Not proteomic, so offer Cl and Br in atoms popup
                               formulaBoxLabel,
                               labelAverage,
                               labelMono,
                               defaultCharge,
                               editMode,
                               suggestOnlyAdductsWithMass)
            {
                NeutralFormula = defaultFormula,
                AverageMass    = averageMass,
                MonoMass       = monoMass,
                Location       = new Point(textName.Left, textName.Bottom + 12)
            };
            _formulaBox.ChargeChange += (sender, args) =>
            {
                if (!_formulaBox.Adduct.IsEmpty)
                {
                    Adduct = _formulaBox.Adduct;
                    var revisedFormula = _formulaBox.NeutralFormula + Adduct.AdductFormula;
                    if (!Equals(revisedFormula, _formulaBox.Formula))
                    {
                        _formulaBox.Formula = revisedFormula;
                    }
                    if (string.IsNullOrEmpty(_formulaBox.NeutralFormula) && averageMass.HasValue)
                    {
                        _formulaBox.AverageMass = averageMass;
                        _formulaBox.MonoMass    = monoMass;
                    }
                }
            };
            Controls.Add(_formulaBox);
            _formulaBox.TabIndex = 2;
            _formulaBox.Enabled  = enableFormulaEditing || enableAdductEditing;
            Adduct = defaultCharge;
            var needCharge = !Adduct.IsEmpty;

            textCharge.Visible = labelCharge.Visible = needCharge;
            if (needOptionalValuesBox && !needCharge)
            {
                heightDelta += groupBoxOptionalValues.Location.Y - labelCharge.Location.Y;
                groupBoxOptionalValues.Location = new Point(groupBoxOptionalValues.Location.X, labelCharge.Location.Y);
            }
            if (explicitRetentionTime == null)
            {
                // Don't ask user for retetention times
                RetentionTime                    = null;
                RetentionTimeWindow              = null;
                labelRetentionTime.Visible       = false;
                labelRetentionTimeWindow.Visible = false;
                textRetentionTime.Visible        = false;
                textRetentionTimeWindow.Visible  = false;
            }
            else
            {
                RetentionTime       = explicitRetentionTime.RetentionTime;
                RetentionTimeWindow = explicitRetentionTime.RetentionTimeWindow;
            }
            if (!needOptionalValuesBox)
            {
                groupBoxOptionalValues.Visible = false;
                heightDelta = groupBoxOptionalValues.Height;
            }
            // Initialize label
            if (settings != null && defaultIsotopeLabelType != null)
            {
                _driverLabelType = new PeptideSettingsUI.LabelTypeComboDriver(PeptideSettingsUI.LabelTypeComboDriver.UsageType.InternalStandardPicker, comboIsotopeLabelType,
                                                                              settings.PeptideSettings.Modifications, null, null, null, null)
                {
                    SelectedName = defaultIsotopeLabelType.Name
                };
            }
            else
            {
                comboIsotopeLabelType.Visible = false;
                labelIsotopeLabelType.Visible = false;
            }
            Height -= heightDelta;
        }