Ejemplo n.º 1
0
 private static bool EquivalentLibraries(PeptideLibraries newLib, PeptideLibraries oldLib)
 {
     if (ReferenceEquals(newLib, oldLib))
         return true;
     if (!ArrayUtil.ReferencesEqual(newLib.LibrarySpecs, oldLib.LibrarySpecs))
         return false;
     // If library spec arrays are equal, then library arrays should
     // at least have the same number of elements
     Debug.Assert(newLib.Libraries.Count == oldLib.Libraries.Count);
     for (int i = 0; i < newLib.Libraries.Count; i++)
     {
         var oldLibrary = oldLib.Libraries[i];
         var newLibrary = newLib.Libraries[i];
         // If the old settings had a library that had never been
         // loaded before or differs from the previously loaded library,
         // then peptides must be updated.
         if (oldLibrary == null ||
             newLibrary == null ||
             // Do not check for difference in loaded state!!  This will cause
             // all precursors to load library spectra during file open, which
             // is too slow.
             // oldLibrary.IsLoaded != newLibrary.IsLoaded ||
             !oldLibrary.IsSameLibrary(newLibrary) ||
             oldLibrary.CompareRevisions(newLibrary) != 0)
         {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
        private PeptideSettings ValidateNewSettings(bool showMessages)
        {
            var helper = new MessageBoxHelper(this, showMessages);

            // Validate and hold digestion settings
            Enzyme enzyme = Settings.Default.GetEnzymeByName(comboEnzyme.SelectedItem.ToString());
            Helpers.AssignIfEquals(ref enzyme, _peptideSettings.Enzyme);

            int maxMissedCleavages =
                int.Parse(comboMissedCleavages.SelectedItem.ToString());
            bool excludeRaggedEnds = cbRaggedEnds.Checked;
            DigestSettings digest = new DigestSettings(maxMissedCleavages, excludeRaggedEnds);
            Helpers.AssignIfEquals(ref digest, Digest);

            var backgroundProteomeSpec = _driverBackgroundProteome.SelectedItem;
            BackgroundProteome backgroundProteome = BackgroundProteome.NONE;
            if (!backgroundProteomeSpec.IsNone)
            {
                backgroundProteome = new BackgroundProteome(backgroundProteomeSpec, true);
                if (backgroundProteome.DatabaseInvalid)
                {

                    var message = TextUtil.LineSeparate(string.Format(Resources.PeptideSettingsUI_ValidateNewSettings_Failed_to_load_background_proteome__0__,
                                                                      backgroundProteomeSpec.Name),
                                                        string.Format(Resources.PeptideSettingsUI_ValidateNewSettings_The_file__0__may_not_be_a_valid_proteome_file,
                                                                      backgroundProteomeSpec.DatabasePath));
                    MessageDlg.Show(this, message);
                    tabControl1.SelectedIndex = 0;
                    _driverBackgroundProteome.Combo.Focus();
                    return null;
                }
            }
            Helpers.AssignIfEquals(ref backgroundProteome, _peptideSettings.BackgroundProteome);

            // Validate and hold prediction settings
            string nameRT = comboRetentionTime.SelectedItem.ToString();
            RetentionTimeRegression retentionTime =
                Settings.Default.GetRetentionTimeByName(nameRT);
            if (retentionTime != null && retentionTime.Calculator != null)
            {
                RetentionScoreCalculatorSpec retentionCalc =
                    Settings.Default.GetCalculatorByName(retentionTime.Calculator.Name);
                // Just in case the calculator in use in the current documet got removed,
                // never set the calculator to null.  Just keep using the one we have.
                if (retentionCalc != null && !ReferenceEquals(retentionCalc, retentionTime.Calculator))
                    retentionTime = retentionTime.ChangeCalculator(retentionCalc);
            }
            bool useMeasuredRT = cbUseMeasuredRT.Checked;
            double? measuredRTWindow = null;
            if (!string.IsNullOrEmpty(textMeasureRTWindow.Text))
            {
                double measuredRTWindowOut;
                const double minWindow = PeptidePrediction.MIN_MEASURED_RT_WINDOW;
                const double maxWindow = PeptidePrediction.MAX_MEASURED_RT_WINDOW;
                if (!helper.ValidateDecimalTextBox(tabControl1, (int) TABS.Prediction,
                        textMeasureRTWindow, minWindow, maxWindow, out measuredRTWindowOut))
                    return null;
                measuredRTWindow = measuredRTWindowOut;
            }

            string nameDt = comboDriftTimePredictor.SelectedItem.ToString();
            DriftTimePredictor driftTimePredictor =
                Settings.Default.GetDriftTimePredictorByName(nameDt);
            if (driftTimePredictor != null && driftTimePredictor.IonMobilityLibrary != null)
            {
                IonMobilityLibrarySpec ionMobilityLibrary =
                    Settings.Default.GetIonMobilityLibraryByName(driftTimePredictor.IonMobilityLibrary.Name);
                // Just in case the library in use in the current documet got removed,
                // never set the library to null.  Just keep using the one we have.
                if (ionMobilityLibrary != null && !ReferenceEquals(ionMobilityLibrary, driftTimePredictor.IonMobilityLibrary))
                    driftTimePredictor = driftTimePredictor.ChangeLibrary(ionMobilityLibrary);
            }
            bool useLibraryDriftTime = cbUseSpectralLibraryDriftTimes.Checked;
            double? libraryDTResolvingPower = null;
            if (useLibraryDriftTime || !string.IsNullOrEmpty(textSpectralLibraryDriftTimesResolvingPower.Text))
            {
                double libraryDTWindowOut;
                if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Prediction,
                        textSpectralLibraryDriftTimesResolvingPower, null, null, out libraryDTWindowOut))
                    return null;
                string errmsg = EditDriftTimePredictorDlg.ValidateResolvingPower(libraryDTWindowOut);
                if (errmsg != null)
                {
                    helper.ShowTextBoxError(tabControl1, (int)TABS.Prediction, textSpectralLibraryDriftTimesResolvingPower, errmsg);
                    return null;
                }
                libraryDTResolvingPower = libraryDTWindowOut;
            }

            var prediction = new PeptidePrediction(retentionTime, driftTimePredictor, useMeasuredRT, measuredRTWindow, useLibraryDriftTime, libraryDTResolvingPower);
            Helpers.AssignIfEquals(ref prediction, Prediction);

            // Validate and hold filter settings
            int excludeNTermAAs;
            if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Filter, textExcludeAAs,
                    PeptideFilter.MIN_EXCLUDE_NTERM_AA, PeptideFilter.MAX_EXCLUDE_NTERM_AA, out excludeNTermAAs))
                return null;
            int minPeptideLength;
            if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Filter, textMinLength,
                    PeptideFilter.MIN_MIN_LENGTH, PeptideFilter.MAX_MIN_LENGTH, out minPeptideLength))
                return null;
            int maxPeptideLength;
            if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Filter, textMaxLength,
                    Math.Max(PeptideFilter.MIN_MAX_LENGTH, minPeptideLength), PeptideFilter.MAX_MAX_LENGTH, out maxPeptideLength))
                return null;

            PeptideExcludeRegex[] exclusions = _driverExclusion.Chosen;

            bool autoSelect = cbAutoSelect.Checked;
            PeptideFilter filter;
            try
            {
                filter = new PeptideFilter(excludeNTermAAs,
                                           minPeptideLength,
                                           maxPeptideLength,
                                           exclusions,
                                           autoSelect);
            }
            catch (InvalidDataException x)
            {
                if (showMessages)
                    MessageDlg.ShowException(this, x);
                return null;
            }

            Helpers.AssignIfEquals(ref filter, Filter);

            // Validate and hold libraries
            PeptideLibraries libraries;
            IList<LibrarySpec> librarySpecs = _driverLibrary.Chosen;
            if (librarySpecs.Count == 0)
                libraries = new PeptideLibraries(PeptidePick.library, null, null, false, librarySpecs, new Library[0]);
            else
            {
                int? peptideCount = null;
                if (cbLimitPeptides.Checked)
                {
                    int peptideCountVal;
                    if (!helper.ValidateNumberTextBox(textPeptideCount, PeptideLibraries.MIN_PEPTIDE_COUNT,
                            PeptideLibraries.MAX_PEPTIDE_COUNT, out peptideCountVal))
                        return null;
                    peptideCount = peptideCountVal;
                }
                PeptidePick pick = (PeptidePick) comboMatching.SelectedIndex;

                IList<Library> librariesLoaded = new Library[librarySpecs.Count];
                bool documentLibrary = false;
                if (Libraries != null)
                {
                    // Use existing library spec's, if nothing was changed.
                    // Avoid changing the libraries, just because the the picking
                    // algorithm changed.
                    if (ArrayUtil.EqualsDeep(librarySpecs, Libraries.LibrarySpecs))
                    {
                        librarySpecs = Libraries.LibrarySpecs;
                        librariesLoaded = Libraries.Libraries;
                    }

                    documentLibrary = Libraries.HasDocumentLibrary;
                    // Otherwise, leave the list of loaded libraries empty,
                    // and let the LibraryManager refill it.  This ensures a
                    // clean save of library specs only in the user config, rather
                    // than a mix of library specs and libraries.
                }

                PeptideRankId rankId = (PeptideRankId) comboRank.SelectedItem;
                if (comboRank.SelectedIndex == 0)
                    rankId = null;

                libraries = new PeptideLibraries(pick, rankId, peptideCount, documentLibrary, librarySpecs, librariesLoaded);
            }
            Helpers.AssignIfEquals(ref libraries, Libraries);

            // Validate and hold modifications
            int maxVariableMods;
            if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Modifications, textMaxVariableMods,
                    PeptideModifications.MIN_MAX_VARIABLE_MODS, PeptideModifications.MAX_MAX_VARIABLE_MODS, out maxVariableMods))
                return null;
            int maxNeutralLosses;
            if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Modifications, textMaxNeutralLosses,
                    PeptideModifications.MIN_MAX_NEUTRAL_LOSSES, PeptideModifications.MAX_MAX_NEUTRAL_LOSSES, out maxNeutralLosses))
                return null;

            var standardTypes = _driverLabelType.InternalStandardTypes;
            PeptideModifications modifications = new PeptideModifications(
                _driverStaticMod.Chosen, maxVariableMods, maxNeutralLosses,
                _driverLabelType.GetHeavyModifications(), standardTypes);
            // Should not be possible to change explicit modifications in the background,
            // so this should be safe.  CONSIDER: Document structure because of a library load?
            modifications = modifications.DeclareExplicitMods(_parent.DocumentUI,
                Settings.Default.StaticModList, Settings.Default.HeavyModList);
            Helpers.AssignIfEquals(ref modifications, _peptideSettings.Modifications);

            PeptideIntegration integration = new PeptideIntegration(_driverPeakScoringModel.SelectedItem);
            Helpers.AssignIfEquals(ref integration, Integration);

            QuantificationSettings quantification = QuantificationSettings.DEFAULT
                .ChangeNormalizationMethod(comboNormalizationMethod.SelectedItem as NormalizationMethod ?? NormalizationMethod.NONE)
                .ChangeRegressionWeighting(comboWeighting.SelectedItem as RegressionWeighting)
                .ChangeRegressionFit(comboRegressionFit.SelectedItem as RegressionFit)
                .ChangeMsLevel(_quantMsLevels[comboQuantMsLevel.SelectedIndex])
                .ChangeUnits(tbxQuantUnits.Text);

            return new PeptideSettings(enzyme, digest, prediction, filter, libraries, modifications, integration, backgroundProteome)
                    .ChangeAbsoluteQuantification(quantification);
        }
Ejemplo n.º 3
0
        public PeptideLibraries MergeLibrarySpecs(PeptideLibraries newPepLibraries, FindLibrary findLibrary)
        {
            IList<LibrarySpec> librarySpecs = LibrarySpecs.ToList();

            for (int i = 0; i < newPepLibraries.Libraries.Count; i++)
            {
                LibrarySpec spec = newPepLibraries.LibrarySpecs[i];
                Library library = newPepLibraries.Libraries[i];
                string libraryName;
                string fileName;
                if (library != null)
                {
                    libraryName = library.Name;
                    fileName = library.FileNameHint;
                }
                else if (spec != null)
                {
                    libraryName = spec.Name;
                    fileName = Path.GetFileName(spec.FilePath);
                }
                else
                {
                    // If no library and no spec, give up
                    continue;
                }

                // If already in the list, nothing more to do
                if (librarySpecs.Contains(s => Equals(s.Name, libraryName)) ||
                        (_disconnectedLibraries != null && _disconnectedLibraries.Contains(l => Equals(l.Name, libraryName))))
                    continue;

                // If the named spec is in the global settings, use it
                // CONSIDER: Remove access to Settings from model?
                LibrarySpec specSettings;
                if (Settings.Default.SpectralLibraryList.TryGetValue(libraryName, out specSettings))
                {
                    librarySpecs.Add(specSettings);
                    continue;
                }

                // If it is a library spec, and the path exists then use the spec
                if (spec != null && File.Exists(spec.FilePath))
                {
                    librarySpecs.Add(spec);
                    Settings.Default.SpectralLibraryList.Add(spec);
                    continue;
                }

                // If there is no filename, give up
                if (fileName == null)
                    continue;

                // Look for the library in the user's default library path
                var pathLibrary = Settings.Default.LibraryDirectory != null
                    ? Path.Combine(Settings.Default.LibraryDirectory, fileName)
                    : null;
                if (pathLibrary != null && !File.Exists(pathLibrary) && findLibrary != null)
                {
                    pathLibrary = findLibrary(libraryName, fileName);
                    if (pathLibrary == null)
                        continue;
                }

                // Create a new library spec from the library, or change existing library
                // spec path to the newly found path.
                var libSpec = (library != null
                                   ? library.CreateSpec(pathLibrary)
                                   : spec.ChangeFilePath(pathLibrary));
                librarySpecs.Add(libSpec);
                Settings.Default.SpectralLibraryList.Add(libSpec);
            }

            if (ArrayUtil.ReferencesEqual(LibrarySpecs, librarySpecs))
                return this;

            return ChangeLibrarySpecs(librarySpecs);
        }
Ejemplo n.º 4
0
 public bool Equals(PeptideLibraries obj)
 {
     if (ReferenceEquals(null, obj)) return false;
     if (ReferenceEquals(this, obj)) return true;
     return ArrayUtil.EqualsDeep(obj._librarySpecs, _librarySpecs) &&
         ArrayUtil.EqualsDeep(obj._libraries, _libraries) &&
         Equals(obj._rankIdName, _rankIdName) &&
         Equals(obj.Pick, Pick) &&
         Equals(obj.RankId, RankId) &&
         obj.PeptideCount.Equals(PeptideCount);
 }
Ejemplo n.º 5
0
 public PeptideSettings ChangeLibraries(PeptideLibraries prop)
 {
     return ChangeProp(ImClone(this), im => im.Libraries = prop);
 }
Ejemplo n.º 6
0
 public PeptideSettings(Enzyme enzyme,
     DigestSettings digestSettings,
     PeptidePrediction prediction,
     PeptideFilter filter,
     PeptideLibraries libraries,
     PeptideModifications modifications,
     PeptideIntegration integration,
     BackgroundProteome backgroundProteome
     )
 {
     Enzyme = enzyme;
     DigestSettings = digestSettings;
     Prediction = prediction;
     Filter = filter;
     Libraries = libraries;
     Modifications = modifications;
     Integration = integration;
     BackgroundProteome = backgroundProteome;
     Quantification = QuantificationSettings.DEFAULT;
 }