Beispiel #1
0
        public void ChromatogramExportTest()
        {
            var    testFilesDir    = new TestFilesDir(TestContext, TEST_ZIP_PATH);
            string chromExportDoc  = testFilesDir.GetTestPath("ChromToExport.sky");
            string fileExpected1   = testFilesDir.GetTestPathLocale(EXPORT_1);
            string fileActual1     = GetActualName(fileExpected1);
            string fileExpected2   = testFilesDir.GetTestPathLocale(EXPORT_2);
            string fileActual2     = GetActualName(fileExpected2);
            string fileExpectedAll = testFilesDir.GetTestPathLocale(EXPORT_ALL);
            string fileActualAll   = GetActualName(fileExpectedAll);

            SrmDocument doc = ResultsUtil.DeserializeDocument(chromExportDoc);

            // Load an empty doc, so that we can make a change and
            // cause the .skyd to be loaded
            using (var docContainer = new ResultsTestDocumentContainer(null, chromExportDoc))
            {
                docContainer.SetDocument(doc, null, true);
                docContainer.AssertComplete();
                SrmDocument docResults = docContainer.Document;
                if (IsSaveAll)
                {
                    // For regenerating all of the required expected files, if things change
                    SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_1), FILE_NAMES_1.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_1, SOURCES_1);
                    SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_2), FILE_NAMES_2.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_2, SOURCES_2);
                    SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_ALL), FILE_NAMES_ALL.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_ALL, SOURCES_ALL);
                    SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_1), FILE_NAMES_1.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_1, SOURCES_1);
                    SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_2), FILE_NAMES_2.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_2, SOURCES_2);
                    SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_ALL), FILE_NAMES_ALL.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_ALL, SOURCES_ALL);
                }

                SaveChrom(docResults, fileActual1, FILE_NAMES_1.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_1, SOURCES_1);
                SaveChrom(docResults, fileActual2, FILE_NAMES_2.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_2, SOURCES_2);
                SaveChrom(docResults, fileActualAll, FILE_NAMES_ALL.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_ALL, SOURCES_ALL);

                var tolerance = new Dictionary <int, double> {
                    { 3, .0001 }
                };                                                      // Allow a little wiggle in mz column since we tweak the calculation with Adduct work

                AssertEx.FileEquals(fileExpected1, fileActual1, tolerance);
                AssertEx.FileEquals(fileExpected2, fileActual2, tolerance);
                AssertEx.FileEquals(fileExpectedAll, fileActualAll, tolerance);
            }
        }
Beispiel #2
0
        protected override void DoTest()
        {
            // 1. Document with no imported results gives error message
            ConfirmErrorOnOpen("ChromNoFiles.sky", Resources.SkylineWindow_ShowReintegrateDialog_The_document_must_have_imported_results_);
            // 2. Document with no peptides gives error message
            ConfirmErrorOnOpen("ChromNoPeptides.sky", Resources.SkylineWindow_ShowReintegrateDialog_The_document_must_have_targets_in_order_to_reintegrate_chromatograms_);
            // 3. Document with no trained model gives error message
            var documentNoModel = TestFilesDir.GetTestPath("ChromNoModel.sky");

            RunUI(() => SkylineWindow.OpenFile(documentNoModel));
            WaitForDocumentLoaded();
            var reintegrateDlgNoModel = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() => reintegrateDlgNoModel.ReintegrateAll = true);
            OkDialog(reintegrateDlgNoModel, reintegrateDlgNoModel.CancelDialog);

            // 4. No value for q cutoff gives error message
            var document = TestFilesDir.GetTestPath("MProphetGold-trained.sky");

            RunUI(() => SkylineWindow.OpenFile(document));
            WaitForDocumentLoaded();
            var reintegrateDlg = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() => reintegrateDlg.ReintegrateAll = false);
            RunDlg <MessageDlg>(reintegrateDlg.OkDialog, messageBox =>
            {
                AssertEx.AreComparableStrings(Resources.MessageBoxHelper_ValidateDecimalTextBox__0__must_contain_a_decimal_value, messageBox.Message);
                messageBox.OkDialog();
            });

            // 6. Negative value for q cutoff gives error message
            RunUI(() => reintegrateDlg.Cutoff = -1.0);
            RunDlg <MessageDlg>(reintegrateDlg.OkDialog, messageBox =>
            {
                AssertEx.AreComparableStrings(Resources.MessageBoxHelper_ValidateDecimalTextBox__0__must_be_greater_than_or_equal_to__1__, messageBox.Message);
                messageBox.OkDialog();
            });

            string docNewExpected    = TestFilesDir.GetTestPathLocale(REPORT_EXPECTED);
            string docNewActual      = TestFilesDir.GetTestPath(REPORT_ACTUAL);
            string docNewExpectedAll = TestFilesDir.GetTestPathLocale(REPORT_EXPECTED_ALL);
            var    reportSpec        = MakeReportSpec();

            // Test export gives same result as through non-UI
            RunUI(() =>
            {
                reintegrateDlg.ReintegrateAll = false;
                reintegrateDlg.Cutoff         = 0.01;
            });
            OkDialog(reintegrateDlg, reintegrateDlg.OkDialog);
            RunUI(() =>
            {
                ReportToCsv(reportSpec, SkylineWindow.DocumentUI, docNewActual, CultureInfo.CurrentCulture);
                if (IsSaveAll)
                {
                    // For regenerating expected files if things change
                    ReportToCsv(reportSpec, SkylineWindow.DocumentUI, TestFilesDir.GetTestPath(REPORT_EXPECTED), CultureInfo.GetCultureInfo("en-US"));
                    ReportToCsv(reportSpec, SkylineWindow.DocumentUI, TestFilesDir.GetTestPathIntl(REPORT_EXPECTED), CultureInfo.GetCultureInfo("fr-FR"));
                }
                AssertEx.FileEquals(docNewActual, docNewExpected);
            });

            // Moving a peak, then reintegrating causes peak to return, but only if manual override is checked
            double?      startNew = 41.0;
            double?      endNew = 42.0;
            double?      startOld, endOld;
            string       nameSet   = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms[0].Name;
            IdentityPath groupPath = SkylineWindow.Document.GetPathTo((int)SrmDocument.Level.TransitionGroups, 0);
            var          filePath  = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms[0].MSDataFileInfos[0].FilePath;

            CheckTimes(groupPath, 0, 0, out startOld, out endOld);
            RunUI(() =>
                  SkylineWindow.ModifyDocument(null,
                                               doc => doc.ChangePeak(groupPath, nameSet, filePath,
                                                                     null, startNew, endNew, UserSet.TRUE, null, false)));
            var reintegrateDlgManual = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() =>
            {
                reintegrateDlgManual.ReintegrateAll  = true;
                reintegrateDlgManual.OverwriteManual = false;
            });
            OkDialog(reintegrateDlgManual, reintegrateDlgManual.OkDialog);
            // No annotations
            Assert.IsFalse(SkylineWindow.Document.Settings.DataSettings.AnnotationDefs.Any());
            var pass = 0;

            CheckRoundTrip(pass++); // Verify that this all serializes properly

            // Peak Boundaries stay where they are when manual override is off
            double?startTime, endTime;

            CheckTimes(groupPath, 0, 0, out startTime, out endTime);
            AssertEx.AreEqualNullable(startNew, startTime, 1e-2);
            AssertEx.AreEqualNullable(endNew, endTime, 1e-2);

            var reintegrateDlgOverride = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() =>
            {
                reintegrateDlgOverride.ReintegrateAll  = true;
                reintegrateDlgOverride.OverwriteManual = true;
            });
            OkDialog(reintegrateDlgOverride, reintegrateDlgOverride.OkDialog);
            // No annotations
            Assert.IsFalse(SkylineWindow.Document.Settings.DataSettings.AnnotationDefs.Any());
            CheckRoundTrip(pass++); // Verify that this all serializes properly

            // Peak Boundaries move back when manual override is turned on
            CheckTimes(groupPath, 0, 0, out startTime, out endTime);
            AssertEx.AreEqualNullable(startOld, startTime, 1e-3);
            AssertEx.AreEqualNullable(endOld, endTime, 1e-3);

            // Checking "Reintegrate All" radio button has same effect as choosing q=1.1
            var reintegrateDlgAll = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() =>
            {
                reintegrateDlgAll.ReintegrateAll  = true;
                reintegrateDlgAll.OverwriteManual = true;
            });
            OkDialog(reintegrateDlgAll, reintegrateDlgAll.OkDialog);
            RunUI(() =>
            {
                ReportToCsv(reportSpec, SkylineWindow.DocumentUI, docNewActual, CultureInfo.CurrentCulture);
                if (IsSaveAll)
                {
                    // For regenerating expected files if things change
                    ReportToCsv(reportSpec, SkylineWindow.DocumentUI, TestFilesDir.GetTestPath(REPORT_EXPECTED_ALL), CultureInfo.GetCultureInfo("en-US"));
                    ReportToCsv(reportSpec, SkylineWindow.DocumentUI, TestFilesDir.GetTestPathIntl(REPORT_EXPECTED_ALL), CultureInfo.GetCultureInfo("fr-FR"));
                }
                AssertEx.FileEquals(docNewActual, docNewExpectedAll);
            });
            // No annotations
            Assert.IsFalse(SkylineWindow.Document.Settings.DataSettings.AnnotationDefs.Any());
            CheckRoundTrip(pass++); // Verify that this all serializes properly
            var reintegrateDlgCutoff = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() =>
            {
                reintegrateDlgCutoff.ReintegrateAll  = false;
                reintegrateDlgCutoff.Cutoff          = 1.0;
                reintegrateDlgCutoff.OverwriteManual = true;
                reintegrateDlgCutoff.OkDialog();
            });
            WaitForClosedForm(reintegrateDlgCutoff);
            RunUI(() =>
            {
                ReportToCsv(reportSpec, SkylineWindow.DocumentUI, docNewActual, CultureInfo.CurrentCulture);
                AssertEx.FileEquals(docNewActual, docNewExpectedAll);
            });
            CheckRoundTrip(pass++); // Verify that this all serializes properly

            // This time annotations are added
            var reintegrateDlgAnnotations = ShowDialog <ReintegrateDlg>(SkylineWindow.ShowReintegrateDialog);

            RunUI(() =>
            {
                reintegrateDlgAnnotations.ReintegrateAll = true;
            });
            OkDialog(reintegrateDlgAnnotations, reintegrateDlgAnnotations.OkDialog);
            CheckRoundTrip(pass++); // Verify that this all serializes properly
            WaitForDocumentLoaded();
            // Check annotations are added
            foreach (var nodeGroup in SkylineWindow.Document.MoleculeTransitionGroups)
            {
                foreach (var chromInfo in nodeGroup.ChromInfos)
                {
                    if (nodeGroup.IsDecoy)
                    {
                        Assert.IsNull(chromInfo.QValue);
                        Assert.IsNotNull(chromInfo.ZScore);
                    }
                    else
                    {
                        Assert.IsNotNull(chromInfo.QValue);
                        Assert.IsNotNull(chromInfo.ZScore);
                    }
                }
            }
        }
        public void TestMProphetResultsHandler()
        {
            var         testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            var         documentFile = testFilesDir.GetTestPath("MProphetGold-trained.sky");
            SrmDocument doc          = ResultsUtil.DeserializeDocument(documentFile);

            // Load libraries
            doc = doc.ChangeSettings(doc.Settings.ChangePeptideLibraries(libraries =>
            {
                var lib = libraries.Libraries[0];
                return(libraries.ChangeLibrarySpecs(new LibrarySpec[]
                {
                    new BiblioSpecLiteSpec(lib.Name, testFilesDir.GetTestPath(lib.FileNameHint))
                }));
            }));
            // Load an empty doc, so that we can make a change and
            // cause the .skyd to be loaded
            var docContainer = new ResultsTestDocumentContainer(null, documentFile);

            docContainer.SetDocument(doc, null, true);
            docContainer.AssertComplete();
            SrmDocument docOriginal      = docContainer.Document;
            var         peakScoringModel = docOriginal.Settings.PeptideSettings.Integration.PeakScoringModel;
            var         resultsHandler   = new MProphetResultsHandler(docOriginal, peakScoringModel)
            {
                QValueCutoff = Q_CUTOFF
            };

            // 1. Reintegrate and export report produces expected file
            resultsHandler.ScoreFeatures();
            var docNew     = resultsHandler.ChangePeaks();
            var reportSpec = MakeReportSpec();

            if (IsSaveAll)
            {
                // For regenerating expected files if things change
                ReportToCsv(reportSpec, docNew, testFilesDir.GetTestPath(REPORT_EXPECTED), CultureInfo.GetCultureInfo("en-US"));
                ReportToCsv(reportSpec, docNew, testFilesDir.GetTestPathIntl(REPORT_EXPECTED), CultureInfo.GetCultureInfo("fr-FR"));
            }
            string docNewActual   = testFilesDir.GetTestPath(REPORT_ACTUAL);
            string docNewExpected = testFilesDir.GetTestPathLocale(REPORT_EXPECTED);

            ReportToCsv(reportSpec, docNew, docNewActual, CultureInfo.CurrentCulture);
            AssertEx.FileEquals(docNewExpected, docNewActual);

            // 2. Reintegrating again gives no change in document
            var resultsHandlerRepeat = new MProphetResultsHandler(docNew, peakScoringModel)
            {
                QValueCutoff = Q_CUTOFF
            };

            resultsHandlerRepeat.ScoreFeatures();
            var docRepeat = resultsHandlerRepeat.ChangePeaks();

            Assert.AreSame(docRepeat, docNew);
            Assert.AreNotSame(docOriginal, docNew);

            // 3. Export mProphet results gives expected file
            var calcs            = peakScoringModel.PeakFeatureCalculators;
            var mProphetActual   = testFilesDir.GetTestPath(MPROPHET_ACTUAL);
            var mProphetExpected = testFilesDir.GetTestPathLocale(MPROPHET_EXPECTED);

            if (IsSaveAll)
            {
                // For regenerating files
                SaveMProphetFeatures(resultsHandler, testFilesDir.GetTestPath(MPROPHET_EXPECTED), CultureInfo.GetCultureInfo("en-US"), calcs);
                SaveMProphetFeatures(resultsHandler, testFilesDir.GetTestPathIntl(MPROPHET_EXPECTED), CultureInfo.GetCultureInfo("fr-FR"), calcs);
            }
            SaveMProphetFeatures(resultsHandler, mProphetActual, CultureInfo.CurrentCulture, calcs);
            AssertEx.FileEquals(mProphetExpected, mProphetActual);

            // 4. Export mProphet -> Import Peak Boundaries leads to same result as reintegrate
            var resultsHandlerQAll = new MProphetResultsHandler(docOriginal, peakScoringModel)
            {
                QValueCutoff = 1.0
            };

            resultsHandlerQAll.ScoreFeatures();
            var  docNewQAll           = resultsHandlerQAll.ChangePeaks();
            var  peakBoundaryImporter = new PeakBoundaryImporter(docNewQAll);
            long lineCount            = Helpers.CountLinesInFile(mProphetActual);

            peakBoundaryImporter.Import(mProphetActual, null, lineCount);
            var docImport = peakBoundaryImporter.Document;
            // Serialized documents are easier to debug when something is different
            string strDocNew    = SerializeDoc(docNewQAll);
            string strDocImport = SerializeDoc(docImport);

            AssertEx.NoDiff(strDocNew, strDocImport);
            Assert.AreSame(docNewQAll, docImport);

            // 5. Reintegration with q value cutoff of <0 causes all peaks set to null
            var handlerAllNull = new MProphetResultsHandler(docOriginal, peakScoringModel)
            {
                QValueCutoff = -0.001
            };

            handlerAllNull.ScoreFeatures();
            var docNull = handlerAllNull.ChangePeaks();

            foreach (var transitionNode in docNull.PeptideTransitions)
            {
                foreach (var chromInfo in transitionNode.ChromInfos)
                {
                    Assert.IsTrue(chromInfo.IsEmpty || transitionNode.IsDecoy);
                }
            }

            // 6. Reintegration adjusts example peak to null at q=0.005 cutoff, but adjusts it to a non-null peak at q=0.20
            const int groupNum = 11;
            var       midQNode = resultsHandler.Document.PeptideTransitionGroups.ToList()[groupNum];

            foreach (var chromInfo in midQNode.Transitions.SelectMany(transition => transition.ChromInfos))
            {
                Assert.IsTrue(chromInfo.IsEmpty);
            }
            resultsHandler.QValueCutoff = Q_CUTOFF_HIGH;
            resultsHandler.ChangePeaks();
            var midQNodeNew = resultsHandler.Document.PeptideTransitionGroups.ToList()[groupNum];

            foreach (var chromInfo in midQNodeNew.Transitions.SelectMany(transition => transition.ChromInfos))
            {
                Assert.IsFalse(chromInfo.IsEmpty);
            }

            // 7. Labeled peptide pairs still have matching peaks
            foreach (var peptideNode in resultsHandler.Document.Peptides)
            {
                Assert.AreEqual(2, peptideNode.TransitionGroupCount);
                var groupList      = peptideNode.TransitionGroups.ToList();
                var lightGroup     = groupList[0];
                var heavyGroup     = groupList[0];
                var lightChromInfo = lightGroup.ChromInfos.ToList()[0];
                var heavyChromInfo = heavyGroup.ChromInfos.ToList()[0];
                Assert.AreEqual(lightChromInfo.StartRetentionTime, heavyChromInfo.StartRetentionTime);
                Assert.AreEqual(lightChromInfo.EndRetentionTime, heavyChromInfo.EndRetentionTime);
                Assert.AreEqual(lightChromInfo.RetentionTime, heavyChromInfo.RetentionTime);
            }

            // 8. Verify that chosen peaks and q values are the same as those in mProphet paper:
            // http://www.nature.com/nmeth/journal/v8/n5/full/nmeth.1584.html#/supplementary-information
            // TODO: Grab this data from the mProphet paper

            // Release open streams
            docContainer.Release();
        }