/// <summary>
        /// Shows a dialog prompting user to decide whether to use embedded spectra when external spectra are preferred but cannot be found.
        /// Returns 'normal' if the user wants Embedded spectra, 'option1' to retry finding the external spectra, or to 'cancel' to abort the library build.
        /// </summary>
        public static UpdateProgressResponse ShowLibraryMissingExternalSpectraError(Control parentWindow, Exception errorException)
        {
            // E.g. could not find external raw data for MaxQuant msms.txt; ask user if they want to retry with "prefer embedded spectra" option
            if (!BiblioSpecLiteBuilder.IsLibraryMissingExternalSpectraError(errorException, out string spectrumFilename, out string resultsFilepath))
            {
                throw new InvalidOperationException(@"IsLibraryMissingExternalSpectraError returned false");
            }

            // TODO: parse supported file extensions from BiblioSpec or ProteoWizard
            var dialogResult = MultiButtonMsgDlg.Show(parentWindow,
                                                      string.Format(Resources.VendorIssueHelper_ShowLibraryMissingExternalSpectraError_Could_not_find_an_external_spectrum_file_matching__0__in_the_same_directory_as_the_MaxQuant_input_file__1__,
                                                                    spectrumFilename, resultsFilepath) +
                                                      string.Format(Resources.VendorIssueHelper_ShowLibraryMissingExternalSpectraError_ButtonDescriptionsSupportsExtensions__0__, BiblioSpecLiteBuilder.BiblioSpecSupportedFileExtensions),
                                                      Resources.BiblioSpecLiteBuilder_Embedded,
                                                      Resources.AlertDlg_GetDefaultButtonText__Retry, true);

            switch (dialogResult)
            {
            case DialogResult.Cancel: return(UpdateProgressResponse.cancel);

            case DialogResult.Yes: return(UpdateProgressResponse.normal);

            case DialogResult.No: return(UpdateProgressResponse.option1);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #2
0
        private void BuildLibrary(string inputDir, IEnumerable <string> inputFiles, string libraryPath,
                                  bool keepRedundant, bool includeAmbiguous, bool filterPeptides, bool append, IrtStandard irtStandard)
        {
            EnsurePeptideSettings();

            var           buildLibraryDlg = ShowDialog <BuildLibraryDlg>(PeptideSettingsUI.ShowBuildLibraryDlg);
            List <string> inputPaths      = null;

            if (inputFiles != null)
            {
                inputPaths = new List <string>(inputFiles).ConvertAll(f => Path.Combine(inputDir, f));
            }
            string autoLibPath = null;

            RunUI(() =>
            {
                if (libraryPath != null)
                {
                    buildLibraryDlg.LibraryPath = libraryPath;
                }
                buildLibraryDlg.LibraryName = _libraryName;
                autoLibPath = buildLibraryDlg.LibraryPath;
                buildLibraryDlg.LibraryKeepRedundant    = keepRedundant;
                buildLibraryDlg.IncludeAmbiguousMatches = includeAmbiguous;
                buildLibraryDlg.LibraryFilterPeptides   = filterPeptides;
                buildLibraryDlg.LibraryBuildAction      = (append ?
                                                           LibraryBuildAction.Append : LibraryBuildAction.Create);
                if (irtStandard != null && !irtStandard.Equals(IrtStandard.EMPTY))
                {
                    buildLibraryDlg.IrtStandard = irtStandard;
                }
                buildLibraryDlg.OkWizardPage();
                if (inputPaths != null)
                {
                    buildLibraryDlg.AddInputFiles(inputPaths);
                }
                else
                {
                    buildLibraryDlg.AddDirectory(inputDir);
                }
            });
            OkDialog(buildLibraryDlg, buildLibraryDlg.OkWizardPage);

            if (inputPaths != null)
            {
                foreach (var inputFile in inputPaths)
                {
                    if (BiblioSpecLiteBuilder.HasEmbeddedSpectra(inputFile))
                    {
                        var embeddedSpectraDlg = WaitForOpenForm <MultiButtonMsgDlg>();
                        OkDialog(embeddedSpectraDlg, embeddedSpectraDlg.BtnYesClick);
                    }
                }
            }

            Assert.AreEqual(TestFilesDir.GetTestPath(_libraryName + BiblioSpecLiteSpec.EXT),
                            autoLibPath);
        }
Beispiel #3
0
        private bool ValidateBuilder(bool validateInputFiles)
        {
            string name;

            if (!_helper.ValidateNameTextBox(textName, out name))
            {
                return(false);
            }

            string outputPath = textPath.Text;

            if (string.IsNullOrEmpty(outputPath))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath);
                return(false);
            }
            if (Directory.Exists(outputPath))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath);
                return(false);
            }
            string outputDir = Path.GetDirectoryName(outputPath);

            if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir);
                return(false);
            }
            if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT))
            {
                outputPath += BiblioSpecLiteSpec.EXT;
            }
            try
            {
                using (var sfLib = new FileSaver(outputPath))
                {
                    if (!sfLib.CanSave(this))
                    {
                        textPath.Focus();
                        textPath.SelectAll();
                        return(false);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__,
                                                                         Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir);
                return(false);
            }
            catch (IOException)
            {
                _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__,
                                                                         Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir);
                return(false);
            }

            double cutOffScore;

            if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore))
            {
                return(false);
            }
            Settings.Default.LibraryResultCutOff = cutOffScore;

            var libraryBuildAction = LibraryBuildAction;

            if (validateInputFiles)
            {
                var inputFilesChosen = new List <string>();
                foreach (int i in listInputFiles.CheckedIndices)
                {
                    inputFilesChosen.Add(_inputFileNames[i]);
                }

                List <Target> targetPeptidesChosen = null;
                if (cbFilter.Checked)
                {
                    targetPeptidesChosen = new List <Target>();
                    var doc = _documentUiContainer.Document;
                    foreach (PeptideDocNode nodePep in doc.Peptides)
                    {
                        // Add light modified sequences
                        targetPeptidesChosen.Add(nodePep.ModifiedTarget);
                        // Add heavy modified sequences
                        foreach (var nodeGroup in nodePep.TransitionGroups)
                        {
                            if (nodeGroup.TransitionGroup.LabelType.IsLight)
                            {
                                continue;
                            }
                            targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Target,
                                                                                      nodeGroup.TransitionGroup.LabelType,
                                                                                      nodePep.ExplicitMods));
                        }
                    }
                }

                if (prositDataSourceRadioButton.Checked)
                {
                    // TODO: Need to figure out a better way to do this, use PrositPeptidePrecursorPair?
                    var doc                  = _documentUiContainer.DocumentUI;
                    var peptides             = doc.Peptides.ToArray();
                    var precursorCount       = doc.PeptideTransitionGroupCount;
                    var peptidesPerPrecursor = new PeptideDocNode[precursorCount];
                    var precursors           = new TransitionGroupDocNode[precursorCount];
                    int index                = 0;

                    for (var i = 0; i < peptides.Length; ++i)
                    {
                        var groups = peptides[i].TransitionGroups.ToArray();
                        Array.Copy(Enumerable.Repeat(peptides[i], groups.Length).ToArray(), 0, peptidesPerPrecursor, index,
                                   groups.Length);
                        Array.Copy(groups, 0, precursors, index, groups.Length);
                        index += groups.Length;
                    }

                    try
                    {
                        PrositUIHelpers.CheckPrositSettings(this, _skylineWindow);
                        // Still construct the library builder, otherwise a user might configure Prosit
                        // incorrectly, causing the build to silently fail
                        Builder = new PrositLibraryBuilder(doc, name, outputPath, () => true, IrtStandard,
                                                           peptidesPerPrecursor, precursors, NCE);
                    }
                    catch (Exception ex)
                    {
                        _helper.ShowTextBoxError(this, ex.Message);
                        return(false);
                    }
                }
                else
                {
                    Builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen)
                    {
                        Action = libraryBuildAction,
                        IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked,
                        KeepRedundant           = LibraryKeepRedundant,
                        CutOffScore             = cutOffScore,
                        Id                    = Helpers.MakeId(textName.Text),
                        IrtStandard           = _driverStandards.SelectedItem,
                        PreferEmbeddedSpectra = PreferEmbeddedSpectra
                    };
                }
            }
            return(true);
        }
        private bool BuildPeptideSearchLibrary(CancelEventArgs e)
        {
            // Nothing to build, if now search files were specified
            if (!SearchFilenames.Any())
            {
                var libraries = DocumentContainer.Document.Settings.PeptideSettings.Libraries;
                if (!libraries.HasLibraries)
                {
                    return(false);
                }
                var libSpec = libraries.LibrarySpecs.FirstOrDefault(s => s.IsDocumentLibrary);
                return(libSpec != null && LoadPeptideSearchLibrary(libSpec));
            }

            double           cutOffScore;
            MessageBoxHelper helper = new MessageBoxHelper(WizardForm);

            if (!helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore))
            {
                e.Cancel = true;
                return(false);
            }
            ImportPeptideSearch.CutoffScore = cutOffScore;

            BiblioSpecLiteBuilder builder;

            try
            {
                builder = ImportPeptideSearch.GetLibBuilder(DocumentContainer.Document, DocumentContainer.DocumentFilePath, cbIncludeAmbiguousMatches.Checked);
                builder.PreferEmbeddedSpectra = PreferEmbeddedSpectra;
            }
            catch (FileEx.DeleteException de)
            {
                MessageDlg.ShowException(this, de);
                return(false);
            }

            bool retry = false;

            do
            {
                using (var longWaitDlg = new LongWaitDlg
                {
                    Text = Resources.BuildPeptideSearchLibraryControl_BuildPeptideSearchLibrary_Building_Peptide_Search_Library,
                    Message = Resources.BuildPeptideSearchLibraryControl_BuildPeptideSearchLibrary_Building_document_library_for_peptide_search_,
                })
                {
                    // Disable the wizard, because the LongWaitDlg does not
                    try
                    {
                        ImportPeptideSearch.ClosePeptideSearchLibraryStreams(DocumentContainer.Document);
                        var status = longWaitDlg.PerformWork(WizardForm, 800,
                                                             monitor => LibraryManager.BuildLibraryBackground(DocumentContainer, builder, monitor, new LibraryManager.BuildState(null, null)));
                        if (status.IsError)
                        {
                            // E.g. could not find external raw data for MaxQuant msms.txt; ask user if they want to retry with "prefer embedded spectra" option
                            if (BiblioSpecLiteBuilder.IsLibraryMissingExternalSpectraError(status.ErrorException))
                            {
                                var response = ShowLibraryMissingExternalSpectraError(WizardForm, status.ErrorException);
                                if (response == UpdateProgressResponse.cancel)
                                {
                                    return(false);
                                }
                                else if (response == UpdateProgressResponse.normal)
                                {
                                    builder.PreferEmbeddedSpectra = true;
                                }

                                retry = true;
                            }
                            else
                            {
                                MessageDlg.ShowException(WizardForm, status.ErrorException);
                                return(false);
                            }
                        }
                    }
                    catch (Exception x)
                    {
                        MessageDlg.ShowWithException(WizardForm, TextUtil.LineSeparate(string.Format(Resources.BuildPeptideSearchLibraryControl_BuildPeptideSearchLibrary_Failed_to_build_the_library__0__,
                                                                                                     Path.GetFileName(BiblioSpecLiteSpec.GetLibraryFileName(DocumentContainer.DocumentFilePath))), x.Message), x);
                        return(false);
                    }
                }
            } while (retry);

            var docLibSpec = builder.LibrarySpec.ChangeDocumentLibrary(true);

            Settings.Default.SpectralLibraryList.Insert(0, docLibSpec);

            // Go ahead and load the library - we'll need it for
            // the modifications and chromatograms page.
            if (!LoadPeptideSearchLibrary(docLibSpec))
            {
                return(false);
            }

            var selectedIrtStandard = comboStandards.SelectedItem as IrtStandard;
            var addedIrts           = false;

            if (selectedIrtStandard != null && selectedIrtStandard != IrtStandard.EMPTY)
            {
                addedIrts = AddIrtLibraryTable(docLibSpec.FilePath, selectedIrtStandard);
            }

            var docNew = ImportPeptideSearch.AddDocumentSpectralLibrary(DocumentContainer.Document, docLibSpec);

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

            if (addedIrts)
            {
                docNew = ImportPeptideSearch.AddRetentionTimePredictor(docNew, docLibSpec);
            }

            DocumentContainer.ModifyDocumentNoUndo(doc => docNew);

            if (!string.IsNullOrEmpty(builder.AmbiguousMatchesMessage))
            {
                MessageDlg.Show(WizardForm, builder.AmbiguousMatchesMessage);
            }
            return(true);
        }
Beispiel #5
0
        private bool ValidateBuilder(bool validateInputFiles)
        {
            string name;

            if (!_helper.ValidateNameTextBox(textName, out name))
            {
                return(false);
            }

            string outputPath = textPath.Text;

            if (string.IsNullOrEmpty(outputPath))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath);
                return(false);
            }
            if (Directory.Exists(outputPath))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath);
                return(false);
            }
            string outputDir = Path.GetDirectoryName(outputPath);

            if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir);
                return(false);
            }
            if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT))
            {
                outputPath += BiblioSpecLiteSpec.EXT;
            }
            try
            {
                using (var sfLib = new FileSaver(outputPath))
                {
                    if (!sfLib.CanSave(this))
                    {
                        textPath.Focus();
                        textPath.SelectAll();
                        return(false);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__,
                                                                         Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir);
                return(false);
            }
            catch (IOException)
            {
                _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__,
                                                                         Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir);
                return(false);
            }

            double cutOffScore;

            if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore))
            {
                return(false);
            }
            Settings.Default.LibraryResultCutOff = cutOffScore;

            var    libraryBuildAction = LibraryBuildAction;
            string authority          = null;
            string id = null;

            if (libraryBuildAction == LibraryBuildAction.Create)
            {
                authority = LibraryAuthority;
                if (Uri.CheckHostName(authority) != UriHostNameType.Dns)
                {
                    _helper.ShowTextBoxError(textAuthority, Resources.BuildLibraryDlg_ValidateBuilder_The_lab_authority_name__0__is_not_valid_This_should_look_like_an_internet_server_address_e_g_mylab_myu_edu_and_be_unlikely_to_be_used_by_any_other_lab_but_need_not_refer_to_an_actual_server,
                                             authority);
                    return(false);
                }
                Settings.Default.LibraryAuthority = authority;

                id = textID.Text;
                if (!Regex.IsMatch(id, @"\w[0-9A-Za-z_\-]*")) // Not L10N: Easier to keep IDs restricted to these values.
                {
                    _helper.ShowTextBoxError(textID, Resources.BuildLibraryDlg_ValidateBuilder_The_library_identifier__0__is_not_valid_Identifiers_start_with_a_letter_number_or_underscore_and_contain_only_letters_numbers_underscores_and_dashes, id);
                    return(false);
                }
            }

            if (validateInputFiles)
            {
                var inputFilesChosen = new List <string>();
                foreach (int i in listInputFiles.CheckedIndices)
                {
                    inputFilesChosen.Add(_inputFileNames[i]);
                }

                List <string> targetPeptidesChosen = null;
                if (cbFilter.Checked)
                {
                    targetPeptidesChosen = new List <string>();
                    var doc = _documentUiContainer.Document;
                    foreach (PeptideDocNode nodePep in doc.Peptides)
                    {
                        // Add light modified sequences
                        targetPeptidesChosen.Add(nodePep.ModifiedSequence);
                        // Add heavy modified sequences
                        foreach (var nodeGroup in nodePep.TransitionGroups)
                        {
                            if (nodeGroup.TransitionGroup.LabelType.IsLight)
                            {
                                continue;
                            }
                            targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Sequence,
                                                                                      nodeGroup.TransitionGroup.LabelType,
                                                                                      nodePep.ExplicitMods));
                        }
                    }
                }

                _builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen)
                {
                    Action = libraryBuildAction,
                    IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked,
                    KeepRedundant           = LibraryKeepRedundant,
                    CutOffScore             = cutOffScore,
                    Authority = authority,
                    Id        = id
                };
            }
            return(true);
        }
Beispiel #6
0
        private bool ValidateBuilder(bool validateInputFiles)
        {
            string name;

            if (!_helper.ValidateNameTextBox(textName, out name))
            {
                return(false);
            }

            string outputPath = textPath.Text;

            if (string.IsNullOrEmpty(outputPath))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath);
                return(false);
            }
            if (Directory.Exists(outputPath))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath);
                return(false);
            }
            string outputDir = Path.GetDirectoryName(outputPath);

            if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir))
            {
                _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir);
                return(false);
            }
            if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT))
            {
                outputPath += BiblioSpecLiteSpec.EXT;
            }
            try
            {
                using (var sfLib = new FileSaver(outputPath))
                {
                    if (!sfLib.CanSave(this))
                    {
                        textPath.Focus();
                        textPath.SelectAll();
                        return(false);
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__,
                                                                         Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir);
                return(false);
            }
            catch (IOException)
            {
                _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__,
                                                                         Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir);
                return(false);
            }

            double cutOffScore;

            if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore))
            {
                return(false);
            }
            Settings.Default.LibraryResultCutOff = cutOffScore;

            var libraryBuildAction = LibraryBuildAction;

            if (validateInputFiles)
            {
                var inputFilesChosen = new List <string>();
                foreach (int i in listInputFiles.CheckedIndices)
                {
                    inputFilesChosen.Add(_inputFileNames[i]);
                }

                List <Target> targetPeptidesChosen = null;
                if (cbFilter.Checked)
                {
                    targetPeptidesChosen = new List <Target>();
                    var doc = _documentUiContainer.Document;
                    foreach (PeptideDocNode nodePep in doc.Peptides)
                    {
                        // Add light modified sequences
                        targetPeptidesChosen.Add(nodePep.ModifiedTarget);
                        // Add heavy modified sequences
                        foreach (var nodeGroup in nodePep.TransitionGroups)
                        {
                            if (nodeGroup.TransitionGroup.LabelType.IsLight)
                            {
                                continue;
                            }
                            targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Target,
                                                                                      nodeGroup.TransitionGroup.LabelType,
                                                                                      nodePep.ExplicitMods));
                        }
                    }
                }

                _builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen)
                {
                    Action = libraryBuildAction,
                    IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked,
                    KeepRedundant           = LibraryKeepRedundant,
                    CutOffScore             = cutOffScore,
                    Id          = Helpers.MakeId(textName.Text),
                    IrtStandard = comboStandards.SelectedItem as IrtStandard
                };
            }
            return(true);
        }