Ejemplo n.º 1
0
        private void NextPage()
        {
            switch (CurrentPage)
            {
            case Pages.spectra_page:
            {
                HasPeakBoundaries = BuildPepSearchLibControl.SearchFilenames.All(f => f.EndsWith(BiblioSpecLiteBuilder.EXT_TSV));
                if (BuildPepSearchLibControl.SearchFilenames.Any(f => f.EndsWith(BiblioSpecLiteBuilder.EXT_TSV)) && !HasPeakBoundaries)
                {
                    MessageDlg.Show(this, Resources.ImportPeptideSearchDlg_NextPage_Cannot_build_library_from_OpenSWATH_results_mixed_with_results_from_other_tools_);
                    return;
                }

                var eCancel = new CancelEventArgs();
                if (!BuildPeptideSearchLibrary(eCancel))
                {
                    // Page shows error
                    if (eCancel.Cancel)
                    {
                        return;
                    }
                    CloseWizard(DialogResult.Cancel);
                }

                // The user had the option to finish right after
                // building the peptide search library, but they
                // did not, so hide the "early finish" button for
                // the rest of the wizard pages.
                ShowEarlyFinish(false);

                if (FastaOptional)
                {
                    lblFasta.Text = Resources.ImportPeptideSearchDlg_NextPage_Import_FASTA__optional_;
                }

                // The next page is going to be the chromatograms page.
                var oldImportResultsControl = (ImportResultsControl)ImportResultsControl;

                if (WorkflowType != Workflow.dia || HasPeakBoundaries)
                {
                    oldImportResultsControl.InitializeChromatogramsPage(Document);

                    if (WorkflowType == Workflow.dda)
                    {
                        _pagesToSkip.Add(Pages.transition_settings_page);
                    }
                }
                else
                {
                    // DIA workflow, replace old ImportResultsControl
                    ImportResultsControl = new ImportResultsDIAControl(this)
                    {
                        Anchor   = oldImportResultsControl.Anchor,
                        Location = oldImportResultsControl.Location
                    };
                    getChromatogramsPage.Controls.Remove(oldImportResultsControl);
                    getChromatogramsPage.Controls.Add((Control)ImportResultsControl);
                }
                ImportResultsControl.ResultsFilesChanged += ImportResultsControl_OnResultsFilesChanged;

                // Set up full scan settings page
                TransitionSettingsControl.Initialize(WorkflowType);
                FullScanSettingsControl.ModifyOptionsForImportPeptideSearchWizard(WorkflowType);

                if (!MatchModificationsControl.Initialize(Document))
                {
                    _pagesToSkip.Add(Pages.match_modifications_page);
                }
                if (BuildPepSearchLibControl.FilterForDocumentPeptides)
                {
                    _pagesToSkip.Add(Pages.import_fasta_page);
                }

                // Decoy options enabled only for DIA
                ImportFastaControl.RequirePrecursorTransition = WorkflowType != Workflow.dia;
                ImportFastaControl.DecoyGenerationEnabled     = WorkflowType == Workflow.dia && !HasPeakBoundaries;
            }
            break;

            case Pages.chromatograms_page:
            {
                if (!ImportPeptideSearch.VerifyRetentionTimes(ImportResultsControl.FoundResultsFiles.Select(f => f.Path)))
                {
                    MessageDlg.Show(this, TextUtil.LineSeparate(Resources.ImportPeptideSearchDlg_NextPage_The_document_specific_spectral_library_does_not_have_valid_retention_times_,
                                                                Resources.ImportPeptideSearchDlg_NextPage_Please_check_your_peptide_search_pipeline_or_contact_Skyline_support_to_ensure_retention_times_appear_in_your_spectral_libraries_));
                    CloseWizard(DialogResult.Cancel);
                }

                if (ImportResultsControl.ResultsFilesMissing)
                {
                    if (MessageBox.Show(this, Resources.ImportPeptideSearchDlg_NextPage_Some_results_files_are_still_missing__Are_you_sure_you_want_to_continue_,
                                        Program.Name, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                var foundResults = ImportResultsControl.FoundResultsFiles;
                if (foundResults.Count > 1)
                {
                    // Older Resharper code inspection implementations insist on warning here
                    // Resharper disable PossibleMultipleEnumeration
                    string[] resultNames = foundResults.Select(f => f.Name).ToArray();
                    string   prefix      = ImportResultsDlg.GetCommonPrefix(resultNames);
                    string   suffix      = ImportResultsDlg.GetCommonSuffix(resultNames);
                    // Resharper restore PossibleMultipleEnumeration
                    if (!string.IsNullOrEmpty(prefix) || !string.IsNullOrEmpty(suffix))
                    {
                        using (var dlgName = new ImportResultsNameDlg(prefix, suffix, resultNames))
                        {
                            var result = dlgName.ShowDialog(this);
                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                            else if (dlgName.IsRemove)
                            {
                                ImportResultsControl.FoundResultsFiles = ImportResultsControl.FoundResultsFiles.Select(f =>
                                                                                                                       new ImportPeptideSearch.FoundResultsFile(dlgName.ApplyNameChange(f.Name), f.Path)).ToList();

                                ImportResultsControl.Prefix =
                                    string.IsNullOrEmpty(prefix) ? null : prefix;
                                ImportResultsControl.Suffix =
                                    string.IsNullOrEmpty(suffix) ? null : suffix;
                            }
                        }
                    }
                }
            }
            break;

            case Pages.match_modifications_page:
                if (!UpdateModificationSettings())
                {
                    return;
                }
                break;

            case Pages.transition_settings_page:
                // Try to accept changes to transition settings
                if (!UpdateTransitionSettings())
                {
                    return;
                }
                break;

            case Pages.full_scan_settings_page:
                // Try to accept changes to MS1 full-scan settings
                if (!UpdateFullScanSettings())
                {
                    // We can't allow the user to progress any further until
                    // we can verify that the MS1 full scan settings are valid.
                    return;
                }
                break;

            case Pages.import_fasta_page:     // This is the last page
                if (FastaOptional && !ImportFastaControl.ContainsFastaContent || ImportFastaControl.ImportFasta())
                {
                    WizardFinish();
                }
                return;
            }

            var newPage = CurrentPage + 1;

            while (_pagesToSkip.Contains(newPage))
            {
                ++newPage;
            }

            // Skip import FASTA if user filters for document peptides
            if (newPage > Pages.import_fasta_page)
            {
                WizardFinish();
                return;
            }

            CurrentPage = newPage;
            UpdateButtons();
        }
        private void NextPage()
        {
            switch (CurrentPage)
            {
            case Pages.spectra_page:
            {
                var eCancel = new CancelEventArgs();
                if (!BuildPepSearchLibControl.BuildPeptideSearchLibrary(eCancel))
                {
                    // Page shows error
                    if (eCancel.Cancel)
                    {
                        return;
                    }
                    CloseWizard(DialogResult.Cancel);
                }

                // The user had the option to finish right after
                // building the peptide search library, but they
                // did not, so hide the "early finish" button for
                // the rest of the wizard pages.
                ShowEarlyFinish(false);

                if (FastaOptional)
                {
                    lblFasta.Text = Resources.ImportPeptideSearchDlg_NextPage_Import_FASTA__optional_;
                }

                // The next page is going to be the chromatograms page.
                var oldImportResultsControl = (ImportResultsControl)ImportResultsControl;

                if (WorkflowType != Workflow.dia)
                {
                    oldImportResultsControl.InitializeChromatogramsPage(SkylineWindow.DocumentUI);

                    if (WorkflowType == Workflow.dda)
                    {
                        _pagesToSkip.Add(Pages.transition_settings_page);
                    }
                }
                else
                {
                    // DIA workflow, replace old ImportResultsControl
                    ImportResultsControl = new ImportResultsDIAControl(SkylineWindow)
                    {
                        Anchor   = oldImportResultsControl.Anchor,
                        Location = oldImportResultsControl.Location
                    };
                    getChromatogramsPage.Controls.Remove(oldImportResultsControl);
                    getChromatogramsPage.Controls.Add((Control)ImportResultsControl);
                }
                ImportResultsControl.ResultsFilesChanged += ImportResultsControl_OnResultsFilesChanged;

                // Set up full scan settings page
                TransitionSettingsControl.Initialize(WorkflowType);
                FullScanSettingsControl.ModifyOptionsForImportPeptideSearchWizard(WorkflowType);

                if (!MatchModificationsControl.Initialize(SkylineWindow.Document))
                {
                    _pagesToSkip.Add(Pages.match_modifications_page);
                }
                if (BuildPepSearchLibControl.FilterForDocumentPeptides)
                {
                    _pagesToSkip.Add(Pages.import_fasta_page);
                }
            }
            break;

            case Pages.chromatograms_page:
            {
                if (!ImportPeptideSearch.VerifyRetentionTimes(ImportResultsControl.FoundResultsFiles.Select(f => f.Path)))
                {
                    MessageDlg.Show(this, TextUtil.LineSeparate(Resources.ImportPeptideSearchDlg_NextPage_The_document_specific_spectral_library_does_not_have_valid_retention_times_,
                                                                Resources.ImportPeptideSearchDlg_NextPage_Please_check_your_peptide_search_pipeline_or_contact_Skyline_support_to_ensure_retention_times_appear_in_your_spectral_libraries_));
                    CloseWizard(DialogResult.Cancel);
                }

                if (ImportResultsControl.ResultsFilesMissing)
                {
                    if (MessageBox.Show(this, Resources.ImportPeptideSearchDlg_NextPage_Some_results_files_are_still_missing__Are_you_sure_you_want_to_continue_,
                                        Program.Name, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        return;
                    }
                }

                if (ImportResultsControl.FoundResultsFiles.Count > 1)
                {
                    string prefix = ImportResultsDlg.GetCommonPrefix(ImportResultsControl.FoundResultsFiles.Select(f => f.Name));
                    if (prefix.Length >= ImportResultsDlg.MIN_COMMON_PREFIX_LENGTH)
                    {
                        using (var dlgName = new ImportResultsNameDlg(prefix))
                        {
                            var result = dlgName.ShowDialog(this);
                            if (result == DialogResult.Cancel)
                            {
                                return;
                            }
                            else if (result == DialogResult.Yes)
                            {
                                // Rename all the replicates to remove the specified prefix.
                                ImportResultsControl.FoundResultsFiles = ImportResultsControl.FoundResultsFiles.Select(f =>
                                                                                                                       new ImportPeptideSearch.FoundResultsFile(f.Name.Substring(dlgName.Prefix.Length), f.Path)).ToList();
                            }
                        }
                    }
                }
            }
            break;

            case Pages.match_modifications_page:
            {
                var newSettings = MatchModificationsControl.AddCheckedModifications(SkylineWindow.Document);
                if (!ReferenceEquals(SkylineWindow.Document.Settings, newSettings))
                {
                    SkylineWindow.ChangeSettings(newSettings, true, Resources.MatchModificationsControl_AddCheckedModifications_Add_checked_modifications);
                    SkylineWindow.Document.Settings.UpdateDefaultModifications(false);
                }

                // The next page is going to be the MS1 Full-Scan Settings
                // page, so initialize it.
                // FullScanSettingsControl.InitializeMs1FullScanSettingsPage();
            }
            break;

            case Pages.transition_settings_page:
                // Try to accept changes to transition settings
                if (!UpdateTransitionSettings())
                {
                    return;
                }
                break;

            case Pages.full_scan_settings_page:
                // Try to accept changes to MS1 full-scan settings
                if (!UpdateFullScanSettings())
                {
                    // We can't allow the user to progress any further until
                    // we can verify that the MS1 full scan settings are valid.
                    return;
                }
                break;

            case Pages.import_fasta_page:     // This is the last page
                if ((FastaOptional && !ImportFastaControl.ContainsFastaContent) ||
                    ImportFastaControl.ImportFasta())
                {
                    WizardFinish();
                }
                return;
            }

            Pages newPage = CurrentPage + 1;

            while (_pagesToSkip.Contains(newPage))
            {
                ++newPage;
            }

            // Skip import FASTA if user filters for document peptides
            if (newPage > Pages.import_fasta_page)
            {
                WizardFinish();
                return;
            }

            CurrentPage = newPage;
            if (CurrentPage == LastPage)
            {
                btnNext.Text = Resources.ImportPeptideSearchDlg_NextPage_Finish;
            }
        }