Esempio n. 1
0
        public void OpenDocumentNoWait(string documentPath)
        {
            var documentFile = TestFilesDir.GetTestPath(documentPath);

            WaitForCondition(() => File.Exists(documentFile));
            SkylineWindow.BeginInvoke((Action)(() => SkylineWindow.OpenFile(documentFile)));
        }
Esempio n. 2
0
        protected bool RunAndMaybeTryCancel(Action action, bool tryToCancel)
        {
            bool finished = false;

            SkylineWindow.BeginInvoke(new Action(() =>
            {
                action();
                finished = true;
            }));
            bool triedToCancel = false;

            while (!finished)
            {
                if (tryToCancel)
                {
                    var longWaitDlg = FindOpenForm <LongWaitDlg>();
                    if (longWaitDlg != null)
                    {
                        RunUI(longWaitDlg.Close);
                        triedToCancel = true;
                    }
                }
                Thread.Sleep(0);
            }
            return(triedToCancel);
        }
Esempio n. 3
0
 private static void PrepareLibraryDlg(ViewLibraryDlg libraryDlg, Action prepareAction = null)
 {
     if (prepareAction != null)
     {
         SkylineWindow.BeginInvoke(prepareAction);
     }
     if (!TryWaitForCondition(2000, () => libraryDlg.IsUpdateComplete))
     {
         libraryDlg.IsUpdateCanceled = true;
         Assert.Fail("Unexpected long wait filling peptide list form");
     }
 }
        protected void TestUsePredictedTime()
        {
            const double FILTER_LENGTH = 2.7;

            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("RetentionTimeFilterTest.sky")));
            var docStart = WaitForDocumentLoaded();

            RunUI(() => SkylineWindow.SaveDocument(TestFilesDir.GetTestPath("TestUsePredictedTime.sky")));
            SetUiDocument(docStart.ChangeSettings(docStart.Settings.ChangeTransitionFullScan(f =>
                                                                                             f.ChangeRetentionTimeFilter(RetentionTimeFilterType.scheduling_windows, FILTER_LENGTH))));
            Assert.IsNull(SkylineWindow.Document.Settings.PeptideSettings.Prediction.RetentionTime);
            Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Prediction.UseMeasuredRTs);
            // When we try to import a file, we should get an error about not having a peptide prediction algorithm
            var messageDlg = ShowDialog <MessageDlg>(() => SkylineWindow.ImportResults());

            RunUI(() =>
            {
                Assert.AreEqual(Resources.SkylineWindow_CheckRetentionTimeFilter_NoPredictionAlgorithm, messageDlg.Message);
                messageDlg.Close();
            });

            var ssrCalcRegression = new RetentionTimeRegression("SSRCALC_FOR_RtFilterTest",
                                                                new RetentionScoreCalculator(RetentionTimeRegression.SSRCALC_100_A), .63,
                                                                5.8, 1.4, new MeasuredRetentionTime[0]);
            // Now give the document a prediction algorithm
            var docBeforeImport = SkylineWindow.Document;

            docBeforeImport = docBeforeImport.ChangeSettings(docBeforeImport.Settings.ChangePeptidePrediction(p =>
                                                                                                              p.ChangeRetentionTime(ssrCalcRegression)));
            SetUiDocument(docBeforeImport);
            // Now import two result files
            {
                var importResultsDlg     = ShowDialog <ImportResultsDlg>(SkylineWindow.ImportResults);
                var openDataSourceDialog = ShowDialog <OpenDataSourceDialog>(importResultsDlg.OkDialog);
                RunUI(() =>
                {
                    openDataSourceDialog.SelectFile("200fmol" + extension);
                    openDataSourceDialog.SelectFile("20fmol" + extension);
                });
                OkDialog(openDataSourceDialog, openDataSourceDialog.Open);
            }
            {
                var document = WaitForDocumentChangeLoaded(docBeforeImport);
                foreach (var chromatogramSet in document.Settings.MeasuredResults.Chromatograms)
                {
                    foreach (var tuple in LoadAllChromatograms(document, chromatogramSet))
                    {
                        var peptide = tuple.Item1;
                        if (!peptide.IsProteomic)
                        {
                            continue;
                        }
                        var transitionGroup        = tuple.Item2;
                        var predictedRetentionTime = ssrCalcRegression.GetRetentionTime(
                            document.Settings.GetModifiedSequence(peptide.Peptide.Sequence,
                                                                  transitionGroup.TransitionGroup.LabelType, peptide.ExplicitMods)).Value;
                        AssertChromatogramWindow(document, chromatogramSet,
                                                 predictedRetentionTime - FILTER_LENGTH,
                                                 predictedRetentionTime + FILTER_LENGTH, tuple.Item3);
                    }
                }
            }
            ChromatogramSet chromSetForScheduling = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms[1];
            // Create a SrmDocument with just the one ChromatogramSet that we are going to use for scheduling, so that
            // we can assert later that the chromatogram windows are where this document says they should be.
            var docForScheduling = SkylineWindow.Document.ChangeMeasuredResults(
                SkylineWindow.Document.Settings.MeasuredResults.ChangeChromatograms(new[] { chromSetForScheduling }));

            docForScheduling = docForScheduling.ChangeSettings(docForScheduling.Settings.ChangePeptidePrediction(p =>
                                                                                                                 p.ChangeUseMeasuredRTs(true).ChangeRetentionTime(null)));
            SetUiDocument(docForScheduling);
            {
                var chooseSchedulingReplicatesDlg = ShowDialog <ChooseSchedulingReplicatesDlg>(SkylineWindow.ImportResults);
                // Choose a scheduling replicate (the one saved above)
                RunUI(() => Assert.IsTrue(chooseSchedulingReplicatesDlg.TrySetReplicateChecked(
                                              chromSetForScheduling, true)));
                var importResultsDlg     = ShowDialog <ImportResultsDlg>(chooseSchedulingReplicatesDlg.OkDialog);
                var openDataSourceDialog = ShowDialog <OpenDataSourceDialog>(importResultsDlg.OkDialog);
                RunUI(() => openDataSourceDialog.SelectFile("40fmol" + extension));
                OkDialog(openDataSourceDialog, openDataSourceDialog.Open);
            }
            {
                var document        = WaitForDocumentChangeLoaded(docForScheduling);
                var chromatogramSet = document.Settings.MeasuredResults.Chromatograms.First(cs => cs.Name == "40fmol");
                int countNull       = 0;
                foreach (var tuple in LoadAllChromatograms(document, chromatogramSet))
                {
                    var    prediction = new PeptidePrediction(null, null, true, 1, false, 0);
                    double windowRtIgnored;

                    var schedulingPeptide =
                        docForScheduling.Molecules.First(pep => ReferenceEquals(pep.Peptide, tuple.Item1.Peptide));
                    var    schedulingTransitionGroup = (TransitionGroupDocNode)schedulingPeptide.FindNode(tuple.Item2.TransitionGroup);
                    double?predictedRt = prediction.PredictRetentionTime(docForScheduling,
                                                                         schedulingPeptide,
                                                                         schedulingTransitionGroup,
                                                                         null, ExportSchedulingAlgorithm.Average, true, out windowRtIgnored);
                    if (!predictedRt.HasValue)
                    {
                        countNull++;
                        continue;
                    }
                    AssertChromatogramWindow(document, chromatogramSet, predictedRt.Value - FILTER_LENGTH, predictedRt.Value + FILTER_LENGTH, tuple.Item3);
                }
                Assert.AreEqual((TestSmallMolecules ? 1 : 0), countNull);
            }

            // Test using iRT with auto-calculated regression
            {
                const string calcName           = "TestCalculator";
                const string regressionName     = "TestCalculatorAutoCalcRegression";
                var          peptideSettingsDlg = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
                var          editIrtDlg         = ShowDialog <EditIrtCalcDlg>(peptideSettingsDlg.AddCalculator);
                RunUI(() =>
                {
                    editIrtDlg.OpenDatabase(TestFilesDir.GetTestPath("RetentionTimeFilterTest.irtdb"));
                    editIrtDlg.CalcName = calcName;
                });

                SkylineWindow.BeginInvoke(new Action(editIrtDlg.OkDialog));
                var multiButtonMsgDlg = WaitForOpenForm <MultiButtonMsgDlg>();
                OkDialog(multiButtonMsgDlg, () => multiButtonMsgDlg.DialogResult = DialogResult.Yes);
                var editRtDlg = ShowDialog <EditRTDlg>(peptideSettingsDlg.AddRTRegression);
                RunUI(() =>
                {
                    editRtDlg.ChooseCalculator(calcName);
                    editRtDlg.SetAutoCalcRegression(true);
                    editRtDlg.SetRegressionName(regressionName);
                    editRtDlg.SetTimeWindow(1.0);
                });
                OkDialog(editRtDlg, editRtDlg.OkDialog);
                RunUI(() =>
                {
                    peptideSettingsDlg.ChooseRegression(regressionName);
                    peptideSettingsDlg.UseMeasuredRT(false);
                });
                OkDialog(peptideSettingsDlg, peptideSettingsDlg.OkDialog);
                Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Prediction.UseMeasuredRTs);
                docBeforeImport = SkylineWindow.Document;
                var importResultsDlg     = ShowDialog <ImportResultsDlg>(SkylineWindow.ImportResults);
                var openDataSourceDialog = ShowDialog <OpenDataSourceDialog>(importResultsDlg.OkDialog);
                RunUI(() => openDataSourceDialog.SelectFile("8fmol" + extension));
                OkDialog(openDataSourceDialog, openDataSourceDialog.Open);
                var document        = WaitForDocumentChangeLoaded(docBeforeImport);
                var chromatogramSet = document.Settings.MeasuredResults.Chromatograms.First(cs => cs.Name == "8fmol");

                var regressionLine =
                    document.Settings.PeptideSettings.Prediction.RetentionTime.GetConversion(
                        chromatogramSet.MSDataFileInfos.First().FileId);
                var    calculator = document.Settings.PeptideSettings.Prediction.RetentionTime.Calculator;
                double fullGradientStartTime;
                double fullGradientEndTime;
                using (var msDataFile = new MsDataFileImpl(TestFilesDir.GetTestPath("8fmol" + extension)))
                {
                    fullGradientStartTime = msDataFile.GetSpectrum(0).RetentionTime.Value;
                    fullGradientEndTime   = msDataFile.GetSpectrum(msDataFile.SpectrumCount - 1).RetentionTime.Value;
                }

                foreach (var tuple in LoadAllChromatograms(document, chromatogramSet))
                {
                    if (tuple.Item1.GlobalStandardType != PeptideDocNode.STANDARD_TYPE_IRT)
                    {
                        double?score =
                            calculator.ScoreSequence(document.Settings.GetModifiedSequence(tuple.Item1.Peptide.Sequence,
                                                                                           tuple.Item2.TransitionGroup.LabelType, tuple.Item1.ExplicitMods));
                        if (score.HasValue)
                        {
                            double?predictedRt = regressionLine.GetY(score.Value);
                            AssertChromatogramWindow(document, chromatogramSet, predictedRt.Value - FILTER_LENGTH,
                                                     predictedRt.Value + FILTER_LENGTH, tuple.Item3);
                        }
                    }
                    else
                    {
                        // IRT Standards get extracted for the full gradient
                        AssertChromatogramWindow(document, chromatogramSet, fullGradientStartTime, fullGradientEndTime, tuple.Item3);
                    }
                }
            }
        }