예제 #1
0
        public void MinimizeToFile(string targetFile, CacheFormat cacheFormat)
        {
            var targetSkydFile = ChromatogramCache.FinalPathForName(targetFile, null);

            using (var skydSaver = new FileSaver(targetSkydFile, true))
                using (var scansSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCANS_EXT, true))
                    using (var peaksSaver = new FileSaver(targetSkydFile + ChromatogramCache.PEAKS_EXT, true))
                        using (var scoreSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCORES_EXT, true))
                        {
                            var minimizer  = Document.Settings.MeasuredResults.GetChromCacheMinimizer(Document);
                            var settings   = new ChromCacheMinimizer.Settings().ChangeCacheFormat(cacheFormat);
                            var lockObject = new object();
                            ProgressMonitor.UpdateProgress(_progressStatus = _progressStatus.ChangeMessage(Resources.SrmDocumentSharing_MinimizeToFile_Writing_chromatograms));
                            minimizer.Minimize(settings, stats =>
                            {
                                if (ProgressMonitor.IsCanceled)
                                {
                                    throw new OperationCanceledException();
                                }
                                lock (lockObject)
                                {
                                    ProgressMonitor.UpdateProgress(_progressStatus = _progressStatus.ChangePercentComplete(stats.PercentComplete));
                                }
                            }, skydSaver.FileStream, scansSaver.FileStream, peaksSaver.FileStream, scoreSaver.FileStream);
                            skydSaver.Commit();
                        }
        }
예제 #2
0
        private string[] FindMissingFiles(IEnumerable <ChromatogramSet> chromatogramSets)
        {
            string documentPath = DocumentUIContainer.DocumentFilePath;
            string cachePath    = ChromatogramCache.FinalPathForName(documentPath, null);

            // Collect all missing paths
            var listPathsMissing = new List <string>();
            // Avoid checking paths multiple times for existence
            var setPaths = new HashSet <string>();

            foreach (var filePath in chromatogramSets.SelectMany(set => set.MSDataFilePaths))
            {
                MsDataFilePath msDataFilePath = filePath as MsDataFilePath;
                if (null == msDataFilePath)
                {
                    continue;
                }
                string filePathPart = msDataFilePath.FilePath;
                if (setPaths.Contains(filePathPart))
                {
                    continue;
                }
                setPaths.Add(filePathPart);
                if (ChromatogramSet.GetExistingDataFilePath(cachePath, msDataFilePath) != null)
                {
                    continue;
                }
                listPathsMissing.Add(filePathPart);
            }
            listPathsMissing.Sort();
            return(listPathsMissing.ToArray());
        }
예제 #3
0
        private TemporaryDirectory ShareSkydFile(ZipFileShare zip, TemporaryDirectory tempDir)
        {
            string pathCache = ChromatogramCache.FinalPathForName(DocumentPath, null);

            if (!File.Exists(pathCache))
            {
                return(tempDir);
            }
            if (ShareType.SkylineVersion != null && Document.Settings.HasResults)
            {
                var measuredResults = Document.Settings.MeasuredResults;
                if (measuredResults.CacheVersion.HasValue &&
                    !measuredResults.CacheVersion.Equals(ShareType.SkylineVersion.CacheFormatVersion))
                {
                    String cacheFileName = Path.GetFileName(pathCache);
                    if (cacheFileName != null)
                    {
                        if (tempDir == null)
                        {
                            tempDir = new TemporaryDirectory();
                        }
                        String newCachePath = Path.Combine(tempDir.DirPath, cacheFileName);
                        MinimizeToFile(newCachePath, CacheFormat.FromVersion(ShareType.SkylineVersion.CacheFormatVersion));
                        zip.AddFile(newCachePath);
                        return(tempDir);
                    }
                }
            }
            zip.AddFile(pathCache);
            return(tempDir);
        }
예제 #4
0
        private void DoTestImportSim(bool asSmallMolecules)
        {
            if (asSmallMolecules && !RunSmallMoleculeTestVersions)
            {
                System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                return;
            }

            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath(DOCUMENT_NAME);
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            var pepdoc = doc;

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(pepdoc, TestContext.ResultsDirectory);
            }

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the mzML file and verify Mz range
                Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512);
                Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557);
            }
        }
예제 #5
0
        private void ShareDataAndView(ZipFile zip)
        {
            string pathCache = ChromatogramCache.FinalPathForName(DocumentPath, null);

            if (File.Exists(pathCache))
            {
                zip.AddFile(pathCache, string.Empty);
            }
            string viewPath = SkylineWindow.GetViewFile(DocumentPath);

            if (File.Exists(viewPath))
            {
                zip.AddFile(viewPath, string.Empty);
            }
        }
예제 #6
0
        private void DoTestAgilentCEOpt()
        {
            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath(DOCUMENT_NAME);
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the .wiff file
                ExportImport(docContainer, testFilesDir.GetTestPath(RESULTS_NAME));
            }
        }
예제 #7
0
        public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions)
            {
                Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                return;
            }

            TestSmallMolecules = false;      // We test small molecules explicitly in this test

            LocalizationHelper.InitThread(); // TODO: All unit tests should be correctly initialized

            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath("TROUBLED_File.sky");
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc    = ResultsUtil.DeserializeDocument(docPath);
            var         refine = new RefinementSettings();

            doc = refine.ConvertToSmallMolecules(doc, testFilesDir.FullPath, asSmallMolecules);
            const int expectedMoleculeCount = 1;   // At first small molecules did not support multiple label types

            AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 6);

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the first RAW file (or mzML for international)
                string rawPath         = testFilesDir.GetTestPath("Rush_p3_96_21May16_Smeagol.mzML");
                var    measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) });

                {
                    // Import with symmetric isolation window
                    var docResults =
                        docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 3, 3);
                    var    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    double ratio     = nodeGroup.Results[0][0].Ratio ?? 0;
                    // The expected ratio is 1.0, but the symmetric isolation window should produce poor results
                    if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula
                    {
                        Assert.AreEqual(0.008, ratio, 0.001);
                    }
                }
            }

            testFilesDir.Dispose();
        }
예제 #8
0
        private void DoTestAgilentCEOpt()
        {
            // The special mode for exercising non-proteomic molecules just doesn't make sense with this test
            TestSmallMolecules = false;

            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath(DOCUMENT_NAME);
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the .wiff file
                ExportImport(docContainer, testFilesDir.GetTestPath(RESULTS_NAME));
            }
        }
예제 #9
0
        public void DoTestDemux(bool asSmallMolecules)
        {
            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPathMsx   = testFilesDir.GetTestPath("MsxTest.sky");
            string dataPathMsx  = testFilesDir.GetTestPath("MsxTest.mzML");
            string cachePathMsx = ChromatogramCache.FinalPathForName(docPathMsx, null);

            FileEx.SafeDelete(cachePathMsx);
            SrmDocument docMsx = ResultsUtil.DeserializeDocument(docPathMsx);

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                docMsx = refine.ConvertToSmallMolecules(docMsx);
            }
            var fullScanInitialMsx = docMsx.Settings.TransitionSettings.FullScan;

            Assert.IsTrue(fullScanInitialMsx.IsEnabledMsMs);

            TestMsx(docMsx, dataPathMsx);

            string docPathOverlap   = testFilesDir.GetTestPath("OverlapTest.sky");
            string dataPathOverlap  = testFilesDir.GetTestPath("OverlapTest.mzML");
            string cachePathOverlap = ChromatogramCache.FinalPathForName(docPathOverlap, null);

            FileEx.SafeDelete(cachePathOverlap);
            SrmDocument docOverlap = ResultsUtil.DeserializeDocument(docPathOverlap);

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                docOverlap = refine.ConvertToSmallMolecules(docOverlap);
            }
            var fullScanInitialOverlap = docMsx.Settings.TransitionSettings.FullScan;

            Assert.IsTrue(fullScanInitialOverlap.IsEnabledMsMs);
            TestOverlap(docOverlap, dataPathOverlap);
        }
예제 #10
0
        private void DoTestImportSim(bool asSmallMolecules)
        {
            TestSmallMolecules = false; // Don't need that magic extra node
            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath(DOCUMENT_NAME);
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            var pepdoc = doc;

            if (asSmallMolecules)
            {
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(pepdoc);
            }

            var docContainer = new ResultsTestDocumentContainer(doc, docPath);

            // Import the mzML file and verify Mz range
            Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512);
            Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557);
        }
예제 #11
0
        public bool TryMinimizeToFile(string targetFile)
        {
            var targetSkydFile = ChromatogramCache.FinalPathForName(targetFile, null);

            using (var skydSaver = new FileSaver(targetSkydFile))
                using (var scansSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCANS_EXT, true))
                    using (var peaksSaver = new FileSaver(targetSkydFile + ChromatogramCache.PEAKS_EXT, true))
                        using (var scoreSaver = new FileSaver(targetSkydFile + ChromatogramCache.SCORES_EXT, true))
                        {
                            skydSaver.Stream = File.OpenWrite(skydSaver.SafeName);
                            using (var longWaitDlg = new LongWaitDlg(DocumentUIContainer))
                            {
                                longWaitDlg.PerformWork(this, 1000,
                                                        longWaitBroker =>
                                {
                                    longWaitBroker.Message = Resources.MinimizeResultsDlg_MinimizeToFile_Saving_new_cache_file;
                                    try
                                    {
                                        using (var backgroundWorker =
                                                   new BackgroundWorker(this, longWaitBroker))
                                        {
                                            backgroundWorker.RunBackground(skydSaver.Stream,
                                                                           scansSaver.FileStream, peaksSaver.FileStream, scoreSaver.FileStream);
                                        }
                                    }
                                    catch (ObjectDisposedException)
                                    {
                                        if (!longWaitBroker.IsCanceled)
                                        {
                                            throw;
                                        }
                                    }
                                });

                                if (longWaitDlg.IsCanceled)
                                {
                                    return(false);
                                }
                            }

                            var skylineWindow = (SkylineWindow)DocumentUIContainer;
                            if (!skylineWindow.SaveDocument(targetFile, false))
                            {
                                return(false);
                            }
                            try
                            {
                                var measuredResults =
                                    DocumentUIContainer.Document.Settings.MeasuredResults.CommitCacheFile(skydSaver);
                                SrmDocument docOrig, docNew;
                                do
                                {
                                    docOrig = DocumentUIContainer.Document;
                                    docNew  = docOrig.ChangeMeasuredResults(measuredResults);
                                } while (!DocumentUIContainer.SetDocument(docNew, docOrig));
                            }
                            catch (Exception x)
                            {
                                var message = TextUtil.LineSeparate(
                                    string.Format(
                                        Resources
                                        .MinimizeResultsDlg_MinimizeToFile_An_unexpected_error_occurred_while_saving_the_data_cache_file__0__,
                                        targetFile),
                                    x.Message);
                                MessageDlg.ShowWithException(this, message, x);
                                return(false);
                            }
                            skylineWindow.InvalidateChromatogramGraphs();
                        }
            return(true);
        }
예제 #12
0
        /// <summary>
        /// Test CE optimization.  Creates optimization transition lists,
        /// imports optimization data, shows graphs, recalculates linear equations,
        /// and exports optimized method.
        /// </summary>
        protected override void DoTest()
        {
            // Open the .sky file
            string documentPath = TestFilesDir.GetTestPath("160109_Mix1_calcurve.sky");

            RunUI(() => SkylineWindow.OpenFile(documentPath));

            var listGraphChroms = new List <GraphChromatogram>(SkylineWindow.GraphChromatograms);

            Assert.AreEqual(4, listGraphChroms.Count);
            var dictGraphPositions = new Dictionary <Point, GraphChromatogram>();
            var dictChromPositions = new Dictionary <Point, int>();
            var docLoading         = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            foreach (var graphChrom in listGraphChroms)
            {
                // Graphs should all be showing in panes
                Point ptLeftTop = GetTopLeft(graphChrom.Parent);
                Assert.IsFalse(dictGraphPositions.ContainsKey(ptLeftTop));
                Assert.IsTrue(graphChrom.Visible);
                Assert.IsTrue(graphChrom.VisibleState == DockState.Document);

                dictGraphPositions.Add(ptLeftTop, graphChrom);

                int             index;
                ChromatogramSet chromSet;
                Assert.IsTrue(docLoading.Settings.MeasuredResults.TryGetChromatogramSet(
                                  graphChrom.NameSet, out chromSet, out index));
                dictChromPositions.Add(ptLeftTop, index);
            }
            WaitForConditionUI(() => SkylineWindow.DocumentUI.Settings.MeasuredResults.IsLoaded);

            var docOrig = WaitForProteinMetadataBackgroundLoaderCompletedUI();   // 70, 73, 75, 78

            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                dlg.MoveDown();
                dlg.MoveDown();
                dlg.OkDialog();
            });

            CheckResultsEquivalent(docOrig, false);

            var docMove1 = WaitForProteinMetadataBackgroundLoaderCompletedUI();  // 73, 75, 70, 78

            // Make sure the moved chromatogram set ended up in the right place.
            Assert.AreSame(docOrig.Settings.MeasuredResults.Chromatograms[0],
                           docMove1.Settings.MeasuredResults.Chromatograms[2]);

            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                var chromatograms         = docMove1.Settings.MeasuredResults.Chromatograms;
                dlg.SelectedChromatograms = new[] { chromatograms[1], chromatograms[3] };
                dlg.MoveUp();
                dlg.OkDialog();
            });

            CheckResultsEquivalent(docMove1, false);

            var docMove2 = WaitForProteinMetadataBackgroundLoaderCompletedUI();  // 75, 78, 73, 70

            // Make sure the moved chromatogram sets ended up in the right place.
            Assert.AreSame(docMove1.Settings.MeasuredResults.Chromatograms[1],
                           docMove2.Settings.MeasuredResults.Chromatograms[0]);
            Assert.AreSame(docMove1.Settings.MeasuredResults.Chromatograms[3],
                           docMove2.Settings.MeasuredResults.Chromatograms[1]);

            // Rename a chromatogram set
            var manageResultsDlg = ShowDialog <ManageResultsDlg>(SkylineWindow.ManageResults);

            RunUI(() =>
            {
                var chromatograms = docMove2.Settings.MeasuredResults.Chromatograms;
                manageResultsDlg.SelectedChromatograms = new[] { chromatograms[2] };
                manageResultsDlg.MoveUp();
            });

            var          renameDlg = ShowDialog <RenameResultDlg>(manageResultsDlg.RenameResult);
            const string newName   = "Test this name";

            RunUI(() =>
            {
                renameDlg.ReplicateName = newName;
                renameDlg.OkDialog();
            });
            WaitForClosedForm(renameDlg);

            RunUI(manageResultsDlg.OkDialog);
            WaitForClosedForm(manageResultsDlg);

            CheckResultsEquivalent(docMove2, true);

            // Make sure the desired rename happened
            var docRename = WaitForProteinMetadataBackgroundLoaderCompletedUI(); // 75, Test this name, 78, 70

            Assert.AreEqual(newName, docRename.Settings.MeasuredResults.Chromatograms[1].Name);
            Assert.AreEqual(docMove2.Settings.MeasuredResults.Chromatograms[2].Id.GlobalIndex,
                            docRename.Settings.MeasuredResults.Chromatograms[1].Id.GlobalIndex);

            // Make sure the tab text of one of the graphs changed
            Assert.IsTrue(SkylineWindow.GraphChromatograms.Contains(graph =>
                                                                    graph.TabText == newName && graph.NameSet == newName));
            // Graphs should not have moved
            listGraphChroms = new List <GraphChromatogram>(SkylineWindow.GraphChromatograms);
            Assert.AreEqual(4, listGraphChroms.Count);
            WaitForGraphPositioning(listGraphChroms, dictGraphPositions);
            foreach (var graphChrom in listGraphChroms)
            {
                Point ptLeftTop = GetTopLeft(graphChrom.Parent);
                Assert.AreEqual(graphChrom.NameSet, dictGraphPositions[ptLeftTop].NameSet);
            }

            var   firstGraphChrom = listGraphChroms[3];
            Point ptLeftTopFirst  = GetTopLeft(firstGraphChrom.Parent);

            RunDlg <ArrangeGraphsGroupedDlg>(SkylineWindow.ArrangeGraphsGrouped, dlg =>
            {
                dlg.Groups     = 4;
                dlg.GroupType  = GroupGraphsType.distributed;
                dlg.GroupOrder = GroupGraphsOrder.Document;
                dlg.OkDialog();
            });

            WaitForConditionUI(() => !Equals(ptLeftTopFirst, GetTopLeft(firstGraphChrom.Parent)));

            // Check that graphs were rearranged correctly
            var dictGraphPositionsNew = new Dictionary <Point, GraphChromatogram>();

            listGraphChroms = new List <GraphChromatogram>(SkylineWindow.GraphChromatograms);
            WaitForGraphPositioning(listGraphChroms, dictChromPositions);
            foreach (var graphChrom in listGraphChroms)
            {
                int             index;
                ChromatogramSet chromSet;
                Assert.IsTrue(docRename.Settings.MeasuredResults.TryGetChromatogramSet(
                                  graphChrom.NameSet, out chromSet, out index));

                Point ptLeftTop = GetTopLeft(graphChrom.Parent);
                // Pane order started out in reversed document order
                Assert.AreEqual(listGraphChroms.Count - 1 - dictChromPositions[ptLeftTop], index);

                dictGraphPositionsNew.Add(ptLeftTop, graphChrom);
            }

            // Test Reimport error message with missing file
            var manageResultsDlg2  = ShowDialog <ManageResultsDlg>(SkylineWindow.ManageResults);
            var missingFileMessage = ShowDialog <MessageDlg>(manageResultsDlg2.ReimportResults);

            Assert.IsTrue(missingFileMessage.Message.Contains(
                              docRename.Settings.MeasuredResults.Chromatograms[0].MSDataFilePaths.ToArray()[0].ToString()));
            RunUI(() =>
            {
                missingFileMessage.OkDialog();
                manageResultsDlg2.OkDialog();
            });
            WaitForClosedForm(manageResultsDlg2);

            // Reimport data for a replicate
            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                var chromatograms         = docRename.Settings.MeasuredResults.Chromatograms;
                dlg.SelectedChromatograms = new[] { chromatograms[1] };
                dlg.ReimportResults();
                dlg.OkDialog();
            });

            var docReimport = WaitForDocumentChange(docRename);

            Assert.IsFalse(docReimport.Settings.MeasuredResults.IsLoaded);

            WaitForConditionUI(() => SkylineWindow.DocumentUI.Settings.MeasuredResults.IsLoaded);
            docReimport = WaitForProteinMetadataBackgroundLoaderCompletedUI();
            Assert.AreNotSame(docRename.Settings.MeasuredResults, docReimport.Settings.MeasuredResults);
            Assert.IsFalse(ArrayUtil.ReferencesEqual(docRename.Settings.MeasuredResults.Chromatograms,
                                                     docReimport.Settings.MeasuredResults.Chromatograms));
            Assert.AreSame(docRename.Settings.MeasuredResults.Chromatograms[0],
                           docReimport.Settings.MeasuredResults.Chromatograms[0]);
            Assert.AreSame(docRename.Settings.MeasuredResults.Chromatograms[2],
                           docReimport.Settings.MeasuredResults.Chromatograms[2]);
            Assert.AreSame(docRename.Settings.MeasuredResults.Chromatograms[3],
                           docReimport.Settings.MeasuredResults.Chromatograms[3]);
            Assert.AreEqual(new MsDataFilePath(TestFilesDir.GetTestPath("160109_Mix1_calcurve_073.mzML")),
                            docReimport.Settings.MeasuredResults.Chromatograms[1].MSDataFilePaths.ToArray()[0]);

            // Remove the last 2 replicates
            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                var chromatograms         = docRename.Settings.MeasuredResults.Chromatograms;
                dlg.SelectedChromatograms = new[] { chromatograms[2], chromatograms[3] };
                dlg.RemoveReplicates();
                dlg.OkDialog();
            });

            CheckResultsEquivalent(docReimport, false);

            var docRemoved = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            Assert.AreEqual(2, docRemoved.Settings.MeasuredResults.Chromatograms.Count);

            // First two graphs should not have moved
            listGraphChroms = new List <GraphChromatogram>(SkylineWindow.GraphChromatograms);
            Assert.AreEqual(4, listGraphChroms.Count);
            WaitForGraphPositioning(listGraphChroms, dictGraphPositionsNew);
            int countVisible = 0;

            foreach (var graphChrom in listGraphChroms)
            {
                if (!graphChrom.Visible)
                {
                    continue;
                }

                Point ptLeftTop = GetTopLeft(graphChrom.Parent);
                Assert.AreEqual(graphChrom.NameSet, dictGraphPositionsNew[ptLeftTop].NameSet);
                countVisible++;
            }
            Assert.AreEqual(2, countVisible);

            // Remove all but the replicate that was reimported
            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                var chromatograms         = docRename.Settings.MeasuredResults.Chromatograms;
                dlg.SelectedChromatograms = new[] { chromatograms[0] };
                dlg.RemoveReplicates();
                dlg.OkDialog();
            });

            long   cacheLen  = 0;
            string cachePath = ChromatogramCache.FinalPathForName(documentPath, null);

            RunUI(() =>
            {
                SkylineWindow.SaveDocument();
                cacheLen = new FileInfo(cachePath).Length;
            });

            // Now rescore the remaining replicate.
            docRemoved = WaitForProteinMetadataBackgroundLoaderCompletedUI();
            var manageResultsDlg3 = ShowDialog <ManageResultsDlg>(SkylineWindow.ManageResults);

            RunDlg <RescoreResultsDlg>(manageResultsDlg3.Rescore, dlg => dlg.Rescore(false));
            WaitForDocumentLoaded();
            WaitForClosedForm <AllChromatogramsGraph>();
            var docRescore = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            // Roundtrip to get rid of different revision indexes
            AssertEx.DocumentCloned(AssertEx.RoundTrip(docRemoved), AssertEx.RoundTrip(docRescore));
            if (ChromatogramCache.FORMAT_VERSION_CACHE > ChromatogramCache.FORMAT_VERSION_CACHE_4)
            {
                // Rescoring may cause new calculator scores to be stored in the cache
                Assert.IsTrue(cacheLen < new FileInfo(cachePath).Length);
            }
            else
            {
                // Older cache versions do not store scores
                Assert.AreEqual(cacheLen, new FileInfo(cachePath).Length);
            }

            // Remove the last replicate
            RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg =>
            {
                dlg.RemoveAllReplicates();
                dlg.OkDialog();
            });

            // Wait for the document to be different from what it was before
            WaitForDocumentChange(docRescore);

            var docClear = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            Assert.IsFalse(docClear.Settings.HasResults);
        }
예제 #13
0
        public void WiffResultsTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            SrmDocument doc = InitWiffDocument(testFilesDir);

            using (var docContainer = new ResultsTestDocumentContainer(doc,
                                                                       testFilesDir.GetTestPath("SimpleWiffTest.sky")))
            {
                FileEx.SafeDelete(ChromatogramCache.FinalPathForName(docContainer.DocumentFilePath, null));

                var listChromatograms = new List <ChromatogramSet>();

                if (ExtensionTestContext.CanImportAbWiff)
                {
                    string   pathWiff = testFilesDir.GetTestPath("051309_digestion.wiff");
                    string[] dataIds  = MsDataFileImpl.ReadIds(pathWiff);

                    for (int i = 0; i < dataIds.Length; i++)
                    {
                        string nameSample = dataIds[i];
                        if (!Equals(nameSample, "test") && listChromatograms.Count == 0)
                        {
                            continue;
                        }
                        string pathSample = SampleHelp.EncodePath(pathWiff, nameSample, i, LockMassParameters.EMPTY, false, false);
                        listChromatograms.Add(new ChromatogramSet(nameSample, new[] { MsDataFileUri.Parse(pathSample) }));
                    }
                }
                else
                {
                    listChromatograms.Add(new ChromatogramSet("test",
                                                              new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("051309_digestion-test.mzML")) }));
                    listChromatograms.Add(new ChromatogramSet("rfp9,before,h,1",
                                                              new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("051309_digestion-rfp9,before,h,1.mzML")) }));
                }

                // Should have added test and one after
                Assert.AreEqual(2, listChromatograms.Count);

                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
                Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
                docContainer.AssertComplete();

                docResults = docContainer.Document;

                AssertEx.IsDocumentState(docResults, 6, 9, 9, 18, 54);
                Assert.IsTrue(docResults.Settings.MeasuredResults.IsLoaded);

                foreach (var nodeTran in docResults.PeptideTransitions)
                {
                    Assert.IsTrue(nodeTran.HasResults);
                    Assert.AreEqual(2, nodeTran.Results.Count);
                }

                // Remove the last chromatogram
                listChromatograms.RemoveAt(1);

                var docResultsSingle = docResults.ChangeMeasuredResults(new MeasuredResults(listChromatograms));

                AssertResult.IsDocumentResultsState(docResultsSingle, "test", 9, 2, 9, 8, 27);

                // Add mzXML version of test sample
                listChromatograms.Add(new ChromatogramSet("test-mzXML", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("051309_digestion-s3.mzXML")) }));

                var docMzxml = docResults.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
                Assert.IsTrue(docContainer.SetDocument(docMzxml, docResults, true));
                docContainer.AssertComplete();
                docMzxml = docContainer.Document;
                // Verify mzXML and native contained same results
                // Unfortunately mzWiff produces chromatograms with now zeros, which
                // need to be interpolated into place.  This means a .wiff file and
                // its mzWiff mzXML file will never be the same.
                AssertResult.MatchChromatograms(docMzxml, 0, 1, -1, 0);
            }

            // TODO: Switch to a using clause when PWiz is fixed, and this assertion fails
//            AssertEx.ThrowsException<IOException>(() => testFilesDir.Dispose());
        }
예제 #14
0
        /// <summary>
        /// Test import document functionality with results importing
        /// </summary>
        protected override void DoTest()
        {
            _documentPaths = new[]
            {
                TestFilesDir.GetTestPath("document1.sky"),                              // subject1, subject2, buffer (waters calcurv - annotations, manual integration, removed peak)
                TestFilesDir.GetTestPath("document2.sky"),                              // subject1, buffer (waters calcurve - annotations + custom, manual integration)
                TestFilesDir.GetTestPath("document3.sky"),                              // subject2 (waters calcurve - node notes, manual integration)
                TestFilesDir.GetTestPath("document4.sky"),                              // subject2 (agilent bovine1 - manual integration)
                TestFilesDir.GetTestPath("document5.sky"),                              // opt1, opt2 (thermo bovine2 optimization data)
            };
            _groupCounts = new[] { 36, 24, 12, 6, 10 };
            _tranCounts  = new[] { 72, 48, 24, 23, 440 };

            _cachePaths = new string[_documentPaths.Length];
            _cacheSizes = new long[_documentPaths.Length];
            for (int i = 0; i < _documentPaths.Length; i++)
            {
                _cachePaths[i] = ChromatogramCache.FinalPathForName(_documentPaths[i], null);
                _cacheSizes[i] = new FileInfo(_cachePaths[i]).Length;  // Actual length of the file
            }

            var docEmpty = SkylineWindow.Document;
            var state    = new DocResultsState(docEmpty);
            // Import a document into the empty document attempt to keep the results and fail
            var importDlg = ShowDialog <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[1]));

            RunUI(() => importDlg.Action = MeasuredResults.MergeAction.merge_names);
            var messageDlg = ShowDialog <MessageDlg>(importDlg.OkDialog);

            // Allow results to be removed
            RunUI(messageDlg.OkDialog);
            WaitForClosedForm(messageDlg);
            RunUI(importDlg.OkDialog);
            WaitForClosedForm(importDlg);
            var docFirstAttempt = WaitForDocumentChange(docEmpty);

            // Results state should not have changed
            state.AreEqual(docFirstAttempt);

            // Undo and save
            string docPersistPath   = TestFilesDir.GetTestPath("out_document.sky");
            string cachePersistPath = ChromatogramCache.FinalPathForName(docPersistPath, null);

            RunUI(() =>
            {
                SkylineWindow.Undo();
                SkylineWindow.SaveDocument(docPersistPath);
            });
            // Document now changes because of document GUID
            Assert.AreNotSame(docEmpty, SkylineWindow.Document);
            Assert.AreNotSame(docEmpty.Settings.DataSettings, SkylineWindow.Document.Settings.DataSettings);
            Assert.AreSame(docEmpty.Children, SkylineWindow.Document.Children);
            Assert.AreSame(docEmpty.Settings.PeptideSettings, SkylineWindow.Document.Settings.PeptideSettings);
            Assert.AreSame(docEmpty.Settings.TransitionSettings, SkylineWindow.Document.Settings.TransitionSettings);
            Assert.IsTrue(File.Exists(docPersistPath));
            Assert.IsFalse(File.Exists(cachePersistPath));

            // Try again
            const int firstIndex = 1;

            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[firstIndex]), dlg =>
            {
                dlg.Action = MeasuredResults.MergeAction.merge_names;
                dlg.OkDialog();
            });

            var docInitial = WaitForDocumentChangeLoaded(docEmpty);

            state = new DocResultsState(docInitial);
            Assert.IsTrue(state.HasResults);
            // Make sure cache is where it is expected to be
            Assert.AreEqual(cachePersistPath, docInitial.Settings.MeasuredResults.CachePaths.ToArray()[0]);
            // Make sure original cache file is still on disk
            Assert.IsTrue(File.Exists(_cachePaths[firstIndex]));
            Assert.IsTrue(File.Exists(cachePersistPath));

            // The cache version of the original test file is 3.
            // The cache file just created is version 4 or higher.
            long startCacheLen  = GetCacheSize(firstIndex, docInitial);
            long singleCacheLen = new FileInfo(cachePersistPath).Length;

            Assert.AreEqual(startCacheLen, singleCacheLen);

            RunUI(() =>
            {
                SkylineWindow.SelectedPath = new IdentityPath(SequenceTree.NODE_INSERT_ID);
            });

            // Import a document removing the results
            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[3]), dlg =>
            {
                dlg.Action = MeasuredResults.MergeAction.remove;
                dlg.OkDialog();
            });
            var docRemove = WaitForDocumentChange(docInitial);

            // Results state should not have changed
            state.AreEqual(docRemove);

            RunUI(SkylineWindow.Undo);

            Assert.AreSame(docInitial, SkylineWindow.Document);

            // Import a document adding all replicates
            const int nextIndex = 0;

            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[nextIndex]), dlg =>
            {
                dlg.Action = MeasuredResults.MergeAction.add;
                dlg.OkDialog();
            });
            var  docAdd         = WaitForDocumentChangeLoaded(docInitial);
            var  docAdded       = ResultsUtil.DeserializeDocument(_documentPaths[nextIndex]);
            long expectCacheLen = startCacheLen
                                  + GetCacheSize(nextIndex, docAdded)
                                  - ChromatogramCache.HeaderSize; // Only one header between the two caches

            // No peptide merging should have happened
            AssertEx.IsDocumentState(docAdd, null,
                                     docInitial.PeptideGroupCount + docAdded.PeptideGroupCount,
                                     docInitial.PeptideCount + docAdded.PeptideCount,
                                     docInitial.PeptideTransitionCount + docAdded.PeptideTransitionCount);

            Assert.AreEqual(3, docAdded.Settings.MeasuredResults.Chromatograms.Count);
            var chromatograms        = docAdd.Settings.MeasuredResults.Chromatograms;
            var chromatogramsInitial = docInitial.Settings.MeasuredResults.Chromatograms;
            int chromCount           = chromatograms.Count;

            Assert.AreEqual(chromatogramsInitial.Count + 3, chromatograms.Count);
            Assert.AreEqual("buffer1", chromatograms[chromCount - 1].Name);
            Assert.AreEqual("subject3", chromatograms[chromCount - 2].Name);
            Assert.AreEqual("subject2", chromatograms[chromCount - 3].Name);

            // Make sure annotations and user set peaks were added and not lost
            var stateAdd   = new DocResultsState(docAdd);
            var stateAdded = new DocResultsState(docAdded);

            Assert.IsTrue(stateAdd.HasResults && stateAdded.HasResults);
            Assert.AreEqual(stateAdd.NoteCount, state.NoteCount + stateAdded.NoteCount);
            Assert.AreEqual(stateAdd.AnnotationCount, state.AnnotationCount + stateAdded.AnnotationCount);
            Assert.AreEqual(stateAdd.UserSetCount, state.UserSetCount + stateAdded.UserSetCount);
            // Because the data in the two documents actually cover the same results,
            // some calculation is required to determine the number of chromInfo objects
            // expected.
            double fOld   = chromCount / (double)chromatogramsInitial.Count;
            double fAdded = chromCount / (double)docAdded.Settings.MeasuredResults.Chromatograms.Count;

            Assert.AreEqual(stateAdd.PeptideResults,
                            (int)(state.PeptideResults * fOld + stateAdded.PeptideResults * fAdded));
            Assert.AreEqual(stateAdd.TransitionGroupResults,
                            (int)(state.TransitionGroupResults * fOld + stateAdded.TransitionGroupResults * fAdded));
            Assert.AreEqual(stateAdd.TransitionResults,
                            (int)(state.TransitionResults * fOld + stateAdded.TransitionResults * fAdded));
            foreach (var nodeGroup in docAdd.PeptideTransitionGroups)
            {
                for (int i = 0; i < 5; i++)
                {
                    Assert.AreEqual(1, nodeGroup.Results[i].Count);
                }
            }

            // Cache should now contain results for both documents
            long newCacheLen = new FileInfo(cachePersistPath).Length;

            Assert.AreEqual(expectCacheLen, newCacheLen);

            // An undo followed by a redo should not change that
            Assert.AreEqual(9, SkylineWindow.Document.RevisionIndex);
            RunUI(SkylineWindow.Undo);
            WaitForDocumentLoaded(5000);
            Assert.AreEqual(6, SkylineWindow.Document.RevisionIndex);
            Assert.AreEqual(newCacheLen, new FileInfo(cachePersistPath).Length);
            RunUI(SkylineWindow.Redo);
            WaitForDocumentLoaded(5000);    // Necessary? Have seen intermittent failures in this area
            Assert.AreEqual(9, SkylineWindow.Document.RevisionIndex);
            Assert.AreEqual(newCacheLen, new FileInfo(cachePersistPath).Length);
            // Undo followed by a save, should reduce cache to previous size
            RunUI(SkylineWindow.Undo);
            WaitForDocumentLoaded(5000);    // Necessary? Have seen intermittent failures in this area
            Assert.AreEqual(6, SkylineWindow.Document.RevisionIndex);
            RunUI(() => SkylineWindow.SaveDocument());
            Assert.AreEqual(startCacheLen, new FileInfo(cachePersistPath).Length);
            Assert.AreEqual(7, SkylineWindow.Document.RevisionIndex);
            Thread.Sleep(1000);  // Wait 10 ms to make sure the cache change in Redo registers as a cache modification
            // After which, a redo should return the document to the add state and
            // restore the cache
            RunUI(SkylineWindow.Redo);
            var docRedo = WaitForDocumentLoaded();

            Assert.AreEqual(10, docRedo.RevisionIndex);
            stateAdd.AreEqual(docRedo);
            Assert.AreEqual(newCacheLen, new FileInfo(cachePersistPath).Length);

            // Import matching replicates by name
            var docPreUndo = SkylineWindow.Document;

            RunUI(SkylineWindow.Undo);
            var docUndoLoaded = WaitForDocumentChangeLoaded(docPreUndo);

            Assert.AreEqual(8, docUndoLoaded.RevisionIndex);
            Assert.AreNotSame(docInitial, docUndoLoaded);
            Assert.AreEqual(docInitial, docUndoLoaded);    // Cache optimization changes document
            docInitial = docUndoLoaded;
            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[0]), dlg =>
            {
                dlg.Action = MeasuredResults.MergeAction.merge_names;
                dlg.OkDialog();
            });
            var docNames = WaitForDocumentChangeLoaded(docInitial);

            // Should have the same impact on state as adding all replicates.  The information
            // just gets stored differently.
            chromatograms = docNames.Settings.MeasuredResults.Chromatograms;
            Assert.AreEqual(3, chromatograms.Count);
            Assert.AreEqual(chromatogramsInitial[0].Name, chromatograms[0].Name);
            Assert.AreEqual(2, chromatograms[0].MSDataFileInfos.Count);
            Assert.AreEqual(chromatogramsInitial[1].Name, chromatograms[1].Name);
            Assert.AreEqual(2, chromatograms[1].MSDataFileInfos.Count);
            var missingNames = (from chromatogramSet in docAdded.Settings.MeasuredResults.Chromatograms
                                where !chromatogramsInitial.Any(cs => Equals(cs.Name, chromatogramSet.Name))
                                select chromatogramSet.Name).ToArray();

            Assert.AreEqual(missingNames[0], chromatograms[2].Name);
            Assert.AreEqual(1, chromatograms[2].MSDataFileInfos.Count);
            stateAdd.AreEqual(docNames);
            foreach (var nodeGroup in docNames.PeptideTransitionGroups)
            {
                Assert.AreEqual(2, nodeGroup.Results[0].Count);
                Assert.AreEqual(2, nodeGroup.Results[1].Count);
                Assert.AreEqual(1, nodeGroup.Results[2].Count);
            }

            // Import merging by order
            RunUI(() =>
            {
                SkylineWindow.Undo();
                var docCurrent = SkylineWindow.DocumentUI;
                if (ReferenceEquals(docInitial, docCurrent))
                {
                    Assert.AreEqual(8, docInitial.RevisionIndex);
                }
                else
                {
                    // Attempt to report more information when the test fails here
                    AssertEx.DocsEqual(docInitial, docCurrent);
                    Assert.AreEqual(docInitial.Id.GlobalIndex, docCurrent.Id.GlobalIndex);
                    Assert.AreEqual(docInitial.UserRevisionIndex, docCurrent.UserRevisionIndex);
                    Assert.AreEqual(docInitial.RevisionIndex, docCurrent.RevisionIndex);
                    Assert.AreSame(docInitial, docCurrent);
                }
            });
            Assert.AreSame(docInitial, SkylineWindow.Document);
            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[3]), dlg =>
            {
                dlg.Action = MeasuredResults.MergeAction.merge_indices;
                dlg.OkDialog();
            });
            var docOrder      = WaitForDocumentChangeLoaded(docInitial);
            var docOrderAdded = ResultsUtil.DeserializeDocument(_documentPaths[3]);

            chromatograms = docOrder.Settings.MeasuredResults.Chromatograms;
            Assert.AreEqual(2, chromatograms.Count);
            AssertEx.AreEqualDeep(chromatogramsInitial.Select(chrom => chrom.Name).ToArray(),
                                  chromatogramsInitial.Select(chrom => chrom.Name).ToArray());

            var stateOrder      = new DocResultsState(docOrder);
            var stateOrderAdded = new DocResultsState(docOrderAdded);

            Assert.AreEqual(stateOrder.NoteCount, state.NoteCount + stateOrderAdded.NoteCount);
            Assert.AreEqual(stateOrder.AnnotationCount, state.AnnotationCount + stateOrderAdded.AnnotationCount);
            Assert.AreEqual(stateOrder.UserSetCount, state.UserSetCount + stateOrderAdded.UserSetCount);
            Assert.AreEqual(stateOrder.PeptideResults, state.PeptideResults + stateOrderAdded.PeptideResults);
            Assert.AreEqual(stateOrder.TransitionGroupResults,
                            state.TransitionGroupResults + stateOrderAdded.TransitionGroupResults);
            Assert.AreEqual(stateOrder.TransitionResults,
                            state.TransitionResults + stateOrderAdded.TransitionResults);
            foreach (var nodeGroup in docOrder.PeptideTransitionGroups)
            {
                Assert.AreEqual(1, nodeGroup.Results[0].Count);
            }

            // Import merging by order with overflow and multiple files
            RunUI(SkylineWindow.Undo);
            Assert.AreEqual(docInitial, SkylineWindow.Document);
            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[0], _documentPaths[2]), dlg =>
            {
                dlg.Action = MeasuredResults.MergeAction.merge_indices;
                dlg.OkDialog();
            });
            WaitForCondition(() => SkylineWindow.Document.Settings.MeasuredResults.Chromatograms.Count > 2);
            var docOrder2 = WaitForDocumentLoaded();
            var docAdded2 = ResultsUtil.DeserializeDocument(_documentPaths[2]);

            // No peptide merging should have happened
            AssertEx.IsDocumentState(docOrder2, null,
                                     docInitial.PeptideGroupCount + docAdded.PeptideGroupCount + docAdded2.PeptideGroupCount,
                                     docInitial.PeptideCount + docAdded.PeptideCount + docAdded2.PeptideCount,
                                     docInitial.PeptideTransitionCount + docAdded.PeptideTransitionCount + docAdded2.PeptideTransitionCount);

            chromatograms = docOrder2.Settings.MeasuredResults.Chromatograms;
            Assert.AreEqual(3, chromatograms.Count);
            Assert.AreEqual(chromatogramsInitial[0].Name, chromatograms[0].Name);
            Assert.AreEqual(chromatogramsInitial[1].Name, chromatograms[1].Name);
            Assert.AreEqual("buffer1", chromatograms[2].Name);

            var stateOrder2 = new DocResultsState(docOrder2);
            var stateAdded2 = new DocResultsState(docAdded2);

            Assert.AreEqual(stateOrder2.NoteCount, stateAdd.NoteCount + stateAdded2.NoteCount);
            Assert.AreEqual(stateOrder2.AnnotationCount, stateAdd.AnnotationCount + stateAdded2.AnnotationCount);
            Assert.AreEqual(stateOrder2.UserSetCount, stateAdd.UserSetCount + stateAdded2.UserSetCount);
            // Because the data all 3 documents actually cover the same results,
            // some calculation is required to determine the number of chromInfo objects
            // expected.
            int fileCount = docOrder2.Settings.MeasuredResults.Chromatograms.SelectMany(chrom => chrom.MSDataFileInfos).Count();

            fOld   = fileCount / (double)chromatogramsInitial.Count;
            fAdded = fileCount / (double)docAdded.Settings.MeasuredResults.Chromatograms.Count;
            double fAdded2 = fileCount / (double)docAdded2.Settings.MeasuredResults.Chromatograms.Count;

            Assert.AreEqual(stateOrder2.PeptideResults,
                            (int)(state.PeptideResults * fOld + stateAdded.PeptideResults * fAdded + stateAdded2.PeptideResults * fAdded2));
            Assert.AreEqual(stateOrder2.TransitionGroupResults,
                            (int)(state.TransitionGroupResults * fOld + stateAdded.TransitionGroupResults * fAdded + stateAdded2.TransitionGroupResults * fAdded2));
            Assert.AreEqual(stateOrder2.TransitionResults,
                            (int)(state.TransitionResults * fOld + stateAdded.TransitionResults * fAdded + stateAdded2.TransitionResults * fAdded2));
            foreach (var nodeGroup in docOrder2.PeptideTransitionGroups)
            {
                Assert.AreEqual(3, nodeGroup.Results[0].Count);
                Assert.AreEqual(2, nodeGroup.Results[1].Count);
                Assert.AreEqual(1, nodeGroup.Results[2].Count);

                // Make sure files are ordered as expected
                Assert.AreEqual(docInitial.Settings.MeasuredResults.Chromatograms[0].MSDataFileInfos[0].FilePath,
                                chromatograms[0].GetFileInfo(nodeGroup.Results[0][0].FileId).FilePath);
                Assert.AreEqual(docAdded.Settings.MeasuredResults.Chromatograms[0].MSDataFileInfos[0].FilePath,
                                chromatograms[0].GetFileInfo(nodeGroup.Results[0][1].FileId).FilePath);
                Assert.AreEqual(docAdded2.Settings.MeasuredResults.Chromatograms[0].MSDataFileInfos[0].FilePath,
                                chromatograms[0].GetFileInfo(nodeGroup.Results[0][2].FileId).FilePath);
            }

            // Now import allowing matching peptides to be merged
            RunUI(SkylineWindow.Undo);
            Assert.AreEqual(docInitial, SkylineWindow.Document);
            RunDlg <ImportDocResultsDlg>(() => SkylineWindow.ImportFiles(_documentPaths[0], _documentPaths[2]), dlg =>
            {
                dlg.Action          = MeasuredResults.MergeAction.add;
                dlg.IsMergePeptides = true;
                dlg.OkDialog();
            });
            WaitForCondition(() => SkylineWindow.Document.Settings.MeasuredResults.Chromatograms.Count > 2);
            var docMerged = WaitForDocumentLoaded();

            chromatograms = docMerged.Settings.MeasuredResults.Chromatograms;
            Assert.AreEqual(6, chromatograms.Count);

            var dictPeptides = docInitial.Peptides.ToDictionary(nodePep => nodePep.Key);

            foreach (var nodePep in docAdded.Peptides.Where(p => !dictPeptides.ContainsKey(p.Key)))
            {
                dictPeptides.Add(nodePep.Key, nodePep);
            }
            foreach (var nodePep in docAdded2.Peptides.Where(p => !dictPeptides.ContainsKey(p.Key)))
            {
                dictPeptides.Add(nodePep.Key, nodePep);
            }
            AssertEx.IsDocumentState(docMerged, null, 3, dictPeptides.Count,
                                     dictPeptides.Values.Sum(nodePep => nodePep.TransitionCount));

            var stateMerged = new DocResultsState(docMerged);

            Assert.AreEqual(stateMerged.NoteCount, stateAdd.NoteCount + stateAdded2.NoteCount);
            Assert.AreEqual(stateMerged.AnnotationCount, stateAdd.AnnotationCount + stateAdded2.AnnotationCount);
            Assert.AreEqual(stateMerged.UserSetCount, stateAdd.UserSetCount + stateAdded2.UserSetCount);

            var setColors = new HashSet <int>();

            foreach (var nodePep in docMerged.Peptides.Take(4))
            {
                setColors.Add(nodePep.Annotations.ColorIndex);
            }
            Assert.AreEqual(4, setColors.Count);
            Assert.IsFalse(setColors.Contains(-1));

            // TODO: Import optimization data

            // Check cache sizes
            // At this point, the main cache should be about the size of the sum of
            // the caches it has incorporated.
            Assert.AreEqual(newCacheLen + GetCacheSize(2) + GetCacheSize(3) - 2 * ChromatogramCache.HeaderSize,
                            new FileInfo(cachePersistPath).Length, 200);
            // Undo and save should have set the main cache back to the initial state
            RunUI(SkylineWindow.Undo);
            Assert.AreEqual(docInitial, SkylineWindow.Document);
            WaitForDocumentLoaded();
            RunUI(() => SkylineWindow.SaveDocument());
            Assert.AreEqual(startCacheLen, new FileInfo(cachePersistPath).Length);
            // And the original caches should remain unchanged
            for (int i = 0; i < _cachePaths.Length; i++)
            {
                Assert.AreEqual(_cacheSizes[i], new FileInfo(_cachePaths[i]).Length);
            }
            // Another undo and save should remove the results cache for the active document
            RunUI(() =>
            {
                SkylineWindow.Undo();
                SkylineWindow.SaveDocument();
            });
            Assert.IsFalse(File.Exists(cachePersistPath));
        }
예제 #15
0
        /* TODO bspratt drift time libs for small molecules
         *
         * [TestMethod]
         * public void WatersImsMsePredictedDriftTimesChromatogramTestAsSmallMolecules()
         * {
         *  WatersImsMseChromatogramTest(DriftFilterType.predictor, true);
         * }
         *
         * [TestMethod]
         * public void WatersImsMseLibraryDriftTimesChromatogramTestAsSmallMolecules()
         * {
         *  WatersImsMseChromatogramTest(DriftFilterType.library, true);
         * }
         *
         */

        private void WatersImsMseChromatogramTest(DriftFilterType mode,
                                                  RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules = RefinementSettings.ConvertToSmallMoleculesMode.none)
        {
            string subdir       = (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.none) ? null : asSmallMolecules.ToString();
            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE, subdir);

            TestSmallMolecules = false;                                               // Don't need that extra magic node

            bool        withDriftTimePredictor = (mode == DriftFilterType.predictor); // Load the doc that has a drift time predictor?
            bool        withDriftTimeFilter    = (mode != DriftFilterType.none);      // Perform drift time filtering?  (either with predictor, or with bare times in blib file)
            string      docPath;
            SrmDocument document = InitWatersImsMseDocument(testFilesDir, withDriftTimePredictor ? "single_with_driftinfo.sky" : "single_no_driftinfo.sky", asSmallMolecules, out docPath);

            AssertEx.IsDocumentState(document, (withDriftTimePredictor || (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)) ? 1 : 0, 1, 1, 1, 8); // Drift time lib load bumps the doc version
            var docContainer = new ResultsTestDocumentContainer(document, docPath);
            var doc          = docContainer.Document;
            var docOriginal  = doc;

            string testModeStr = withDriftTimePredictor ? "with drift time predictor" : "without drift time info";

            if (withDriftTimeFilter && !withDriftTimePredictor)
            {
                // Use the bare drift times in the spectral library
                var librarySpec = new BiblioSpecLiteSpec("drift test",
                                                         testFilesDir.GetTestPath("mse-mobility.filtered-scaled.blib"));
                doc = doc.ChangeSettings(
                    doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })).
                    ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesResolvingPower(100)).
                    ChangePeptidePrediction(p => p.ChangeUseLibraryDriftTimes(true))
                    );
                testModeStr = "with drift times from spectral library";
            }

            var listChromatograms = new List <ChromatogramSet>();
            // A small subset of the QC_HDMSE_02_UCA168_3495_082213 data set (RT 21.5-22.5) from Will Thompson
            const string path = @"waters-mobility.mz5";

            listChromatograms.Add(AssertResult.FindChromatogramSet(doc, new MsDataFilePath(path)) ??
                                  new ChromatogramSet(Path.GetFileName(path).Replace('.', '_'), new[] { path }));
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));

            Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true));
            docContainer.AssertComplete();
            document = docContainer.Document;

            float  tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
            double maxHeight = 0;
            var    results   = document.Settings.MeasuredResults;

            Assert.AreEqual(1, document.MoleculePrecursorPairs.Count());
            foreach (var pair in document.MoleculePrecursorPairs)
            {
                ChromatogramGroupInfo[] chromGroupInfo;
                Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup,
                                                          tolerance, true, out chromGroupInfo));
                Assert.AreEqual(1, chromGroupInfo.Length, testModeStr);
                var chromGroup    = chromGroupInfo[0];
                var expectedPeaks = ((asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only) ? 6 : 5);
                Assert.AreEqual(withDriftTimeFilter ? 3 : expectedPeaks, chromGroup.NumPeaks, testModeStr); // This will be higher if we don't filter on DT
                foreach (var tranInfo in chromGroup.TransitionPointSets)
                {
                    maxHeight = Math.Max(maxHeight, tranInfo.MaxIntensity);
                }
            }
            Assert.AreEqual(withDriftTimeFilter? 5226 : 20075, maxHeight, 1, testModeStr);   // Without DT filtering, this will be much greater

            // now drill down for specific values
            int nPeptides = 0;

            foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null))
            {
                // expecting just one peptide result in this small data set
                if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0)
                {
                    Assert.AreEqual(21.94865, (double)nodePep.GetMeasuredRetentionTime(0), .0001, testModeStr);
                    Assert.AreEqual(1.0, (double)nodePep.GetPeakCountRatio(0), 0.0001, testModeStr);
                    nPeptides++;
                }
            }
            Assert.AreEqual(1, nPeptides);

            if (withDriftTimePredictor || withDriftTimeFilter)
            {
                // Verify that the .imdb pr .blib file goes out in the share zipfile
                for (int complete = 0; complete <= 1; complete++)
                {
                    var sharePath = testFilesDir.GetTestPath(complete == 1?"share_complete.zip":"share_minimized.zip");
                    var share     = new SrmDocumentSharing(document, docPath, sharePath, complete == 1);
                    using (var longWaitDlg = new LongWaitDlg
                    {
                        // ReSharper disable once LocalizableElement
                        Text = "unit test WatersImsTest -- sharing document",
                    })
                    {
                        longWaitDlg.PerformWork(null, 1000, share.Share);
                        Assert.IsFalse(longWaitDlg.IsCanceled);
                    }

                    var files = share.ListEntries().ToArray();
                    Assert.IsTrue(files.Contains(withDriftTimePredictor ? "scaled.imdb" : "mse-mobility.filtered-scaled.blib"));
                    // And round trip it to make sure we haven't left out any new features in minimized imdb or blib files
                    using (var longWaitDlg = new LongWaitDlg
                    {
                        // ReSharper disable once LocalizableElement
                        Text = "unit test WatersImsTest",
                    })
                    {
                        longWaitDlg.PerformWork(null, 1000, share.Extract);
                        Assert.IsFalse(longWaitDlg.IsCanceled);
                    }
                    using (TextReader reader = new StreamReader(share.DocumentPath))
                    {
                        XmlSerializer documentSerializer = new XmlSerializer(typeof(SrmDocument));
                        var           document2          = (SrmDocument)documentSerializer.Deserialize(reader);
                        Assert.IsNotNull(document2);
                        var im  = document.Settings.GetIonMobilities(new MsDataFilePath(path));
                        var pep = document2.Molecules.First();
                        foreach (TransitionGroupDocNode nodeGroup in pep.Children)
                        {
                            double windowDT;
                            var    centerDriftTime = document.Settings.PeptideSettings.Prediction.GetDriftTime(
                                pep, nodeGroup, im, out windowDT);
                            Assert.AreEqual(3.86124, centerDriftTime.DriftTimeMsec(false) ?? 0, .0001, testModeStr);
                            Assert.AreEqual(0.077224865797235934, windowDT, .0001, testModeStr);
                        }
                    }
                }
            }

            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
            string cachePath = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
        }
예제 #16
0
        public void ConsoleImportDocTest()
        {
            TestFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string[] documentPaths =
            {
                TestFilesDir.GetTestPath("document1.sky"), // subject1, subject2, buffer (waters calcurv - annotations, manual integration, removed peak)
                TestFilesDir.GetTestPath("document2.sky"), // subject1, buffer (waters calcurve - annotations + custom, manual integration)
                TestFilesDir.GetTestPath("document3.sky"), // subject2 (waters calcurve - node notes, manual integration)
                TestFilesDir.GetTestPath("document4.sky"), // subject2 (agilent bovine1 - manual integration)
                TestFilesDir.GetTestPath("document5.sky"), // opt1, opt2 (thermo bovine2 optimization data)
            };

            int[]    groupCounts = { 36, 24, 12, 6, 10 };
            int[]    tranCounts  = { 72, 48, 24, 23, 440 };
            int[]    peakCounts  = { 518, 310, 162, 52, 3608 };
            string[] cachePaths  = new string[documentPaths.Length];
            long[]   cacheSizes  = new long[documentPaths.Length];
            for (int i = 0; i < documentPaths.Length; i++)
            {
                cachePaths[i] = ChromatogramCache.FinalPathForName(documentPaths[i], null);
                cacheSizes[i] = new FileInfo(cachePaths[i]).Length;  // Actual length of the file
            }

            const int firstIndex   = 1;
            string    firstDocPath = documentPaths[firstIndex];
            string    emptyDocPath = TestFilesDir.GetTestPath("in_document.sky");
            var       docEmpty     = new SrmDocument(SrmSettingsList.GetDefault());

            docEmpty.SerializeToFile(emptyDocPath, emptyDocPath, SkylineVersion.CURRENT, null);

            string docPersistPath   = TestFilesDir.GetTestPath("out_document.sky");
            string cachePersistPath = ChromatogramCache.FinalPathForName(docPersistPath, null);
            string msg = RunCommand("--in=" + emptyDocPath,
                                    "--import-document=" + firstDocPath,
                                    "--import-document-results=" + MeasuredResults.MergeAction.merge_names,
                                    "--out=" + docPersistPath);

            CheckRunCommandOutputContains(string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(firstDocPath)), msg);

            var doc         = ResultsUtil.DeserializeDocument(docPersistPath);
            var docImported = ResultsUtil.DeserializeDocument(documentPaths[firstIndex]);

            Assert.IsTrue(doc.Settings.HasResults);
            // Make sure original cache file is still on disk
            Assert.IsTrue(File.Exists(cachePaths[firstIndex]));
            Assert.IsTrue(File.Exists(cachePersistPath));

            // The cache version of the original test file is 3.
            // The cache file just created is version 4 or higher.
            long startCacheLen = ResultsUtil.CacheSize(doc, cacheSizes[firstIndex],
                                                       groupCounts[firstIndex], tranCounts[firstIndex], peakCounts[firstIndex]);

            AssertEx.IsDocumentState(doc, null, docImported.MoleculeGroupCount, docImported.MoleculeCount,
                                     docImported.MoleculeTransitionGroupCount, docImported.MoleculeTransitionCount);

            long singleCacheLen = new FileInfo(cachePersistPath).Length;

            Assert.AreEqual(startCacheLen, singleCacheLen);

            // Import a document removing the results
            string docPersistPath2 = TestFilesDir.GetTestPath("out_document2.sky");
            string lastDocPath     = documentPaths[3];

            msg = RunCommand("--in=" + docPersistPath,
                             "--import-document=" + lastDocPath,
                             "--import-document-results=" + MeasuredResults.MergeAction.remove,
                             "--out=" + docPersistPath2);

            CheckRunCommandOutputContains(string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(lastDocPath)), msg);

            // Skyd file should not have changed, but new molecules should have been added
            var doc2         = ResultsUtil.DeserializeDocument(docPersistPath2);
            var docImported2 = ResultsUtil.DeserializeDocument(lastDocPath);
            // One protein should get merged
            int groups2 = docImported.MoleculeGroupCount + docImported2.MoleculeTransitionGroupCount - 1;
            int mols    = docImported.MoleculeCount + docImported2.MoleculeCount;
            int trans   = docImported.MoleculeTransitionCount + docImported2.MoleculeTransitionCount;

            AssertEx.IsDocumentState(doc2, null, groups2, mols, trans);
            Assert.AreEqual(doc.MeasuredResults, doc2.MeasuredResults);
            Assert.AreEqual(startCacheLen, new FileInfo(cachePersistPath).Length);

            // Try again importing both at the same time without any results
            string docPersistPath3   = TestFilesDir.GetTestPath("out_document3.sky");
            string cachePersistPath3 = ChromatogramCache.FinalPathForName(docPersistPath3, null);

            msg = RunCommand("--in=" + emptyDocPath,
                             "--import-document=" + firstDocPath,
                             "--import-document=" + lastDocPath,
                             "--import-document-results=" + MeasuredResults.MergeAction.remove,
                             "--out=" + docPersistPath3);

            CheckRunCommandOutputContains(string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(firstDocPath)), msg);
            CheckRunCommandOutputContains(string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(lastDocPath)), msg);

            // Skyd file should not have changed, but new molecules should have been added
            var doc3 = ResultsUtil.DeserializeDocument(docPersistPath3);

            AssertEx.IsDocumentState(doc2, null, groups2, mols, trans);
            Assert.IsFalse(doc3.Settings.HasResults);
            Assert.IsFalse(File.Exists(cachePersistPath3));
            var moleculeGroups2 = doc2.MoleculeGroups.ToArray();
            var moleculeGroups3 = doc3.MoleculeGroups.ToArray();

            // Make sure the order is the same
            for (int i = 0; i < groups2; i++)
            {
                Assert.AreEqual(moleculeGroups2[i].Id, moleculeGroups3[i].Id);
            }

            // Import a document adding all replicates
            const int nextIndex         = 0;
            string    nextDocPath       = documentPaths[nextIndex];
            string    docPersistPath4   = TestFilesDir.GetTestPath("out_document4.sky");
            string    cachePersistPath4 = ChromatogramCache.FinalPathForName(docPersistPath4, null);

            msg = RunCommand("--in=" + docPersistPath,
                             "--import-document=" + nextDocPath,
                             "--import-document-results=" + MeasuredResults.MergeAction.add,
                             "--out=" + docPersistPath4);

            CheckRunCommandOutputContains(string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(nextDocPath)), msg);

            var  docAdd         = ResultsUtil.DeserializeDocument(docPersistPath4);
            var  docAdded       = ResultsUtil.DeserializeDocument(nextDocPath);
            long expectCacheLen = startCacheLen
                                  + ResultsUtil.CacheSize(docAdded, cacheSizes[nextIndex], groupCounts[nextIndex], tranCounts[nextIndex], peakCounts[nextIndex])
                                  - ChromatogramCache.HeaderSize; // Only one header between the two caches

            // No peptide merging should have happened
            AssertEx.IsDocumentState(docAdd, null,
                                     doc.PeptideGroupCount + docAdded.PeptideGroupCount,
                                     doc.PeptideCount + docAdded.PeptideCount,
                                     doc.PeptideTransitionCount + docAdded.PeptideTransitionCount);

            Assert.AreEqual(3, docAdded.Settings.MeasuredResults.Chromatograms.Count);
            var chromatograms        = docAdd.Settings.MeasuredResults.Chromatograms;
            var chromatogramsInitial = doc.Settings.MeasuredResults.Chromatograms;
            int chromCount           = chromatograms.Count;

            Assert.AreEqual(chromatogramsInitial.Count + 3, chromatograms.Count);
            Assert.AreEqual("buffer1", chromatograms[chromCount - 1].Name);
            Assert.AreEqual("subject3", chromatograms[chromCount - 2].Name);
            Assert.AreEqual("subject2", chromatograms[chromCount - 3].Name);

            // Make sure annotations and user set peaks were added and not lost
            var stateAdd   = new DocResultsState(docAdd);
            var stateAdded = new DocResultsState(docAdded);
            var state      = new DocResultsState(doc);

            Assert.IsTrue(stateAdd.HasResults && stateAdded.HasResults);
            Assert.AreEqual(stateAdd.NoteCount, state.NoteCount + stateAdded.NoteCount);
            Assert.AreEqual(stateAdd.AnnotationCount, state.AnnotationCount + stateAdded.AnnotationCount);
            Assert.AreEqual(stateAdd.UserSetCount, state.UserSetCount + stateAdded.UserSetCount);
            // Because the data in the two documents actually cover the same results,
            // some calculation is required to determine the number of chromInfo objects
            // expected.
            double fOld   = chromCount / (double)chromatogramsInitial.Count;
            double fAdded = chromCount / (double)docAdded.Settings.MeasuredResults.Chromatograms.Count;

            Assert.AreEqual(stateAdd.PeptideResults,
                            (int)(state.PeptideResults * fOld + stateAdded.PeptideResults * fAdded));
            Assert.AreEqual(stateAdd.TransitionGroupResults,
                            (int)(state.TransitionGroupResults * fOld + stateAdded.TransitionGroupResults * fAdded));
            Assert.AreEqual(stateAdd.TransitionResults,
                            (int)(state.TransitionResults * fOld + stateAdded.TransitionResults * fAdded));
            foreach (var nodeGroup in docAdd.PeptideTransitionGroups)
            {
                for (int i = 0; i < 5; i++)
                {
                    Assert.AreEqual(1, nodeGroup.Results[i].Count);
                }
            }

            // Cache should now contain results for both documents
            long newCacheLen = new FileInfo(cachePersistPath4).Length;

            Assert.AreEqual(expectCacheLen, newCacheLen);
        }
예제 #17
0
        public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions)
            {
                Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION);
                return;
            }

            LocalizationHelper.InitThread();    // TODO: All unit tests should be correctly initialized

            var    testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath      = testFilesDir.GetTestPath("Asym_DIA.sky");
            string cachePath    = ChromatogramCache.FinalPathForName(docPath, null);

            FileEx.SafeDelete(cachePath);
            SrmDocument doc    = ResultsUtil.DeserializeDocument(docPath);
            var         refine = new RefinementSettings();

            doc = refine.ConvertToSmallMolecules(doc, testFilesDir.FullPath, asSmallMolecules);
            const int expectedMoleculeCount = 1;   // At first small molecules did not support multiple charge states, and this was 2 for that test mode

            AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 4);
            var fullScanInitial = doc.Settings.TransitionSettings.FullScan;

            Assert.IsTrue(fullScanInitial.IsEnabledMsMs);
            Assert.AreEqual(FullScanAcquisitionMethod.DIA, fullScanInitial.AcquisitionMethod);
            Assert.AreEqual(25, fullScanInitial.PrecursorFilter);
            AssertEx.Serializable(doc);
            using (var docContainer = new ResultsTestDocumentContainer(doc, docPath))
            {
                // Import the first RAW file (or mzML for international)
                string rawPath         = testFilesDir.GetTestPath("Asym_DIA_data.mzML");
                var    measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) });
                TransitionGroupDocNode nodeGroup;
                double ratio;

                const double poorRatio  = 0.25;
                const double fixedRatio = 1.05;
                {
                    // Import with symmetric isolation window
                    SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    ratio     = nodeGroup.Results[0][0].Ratio ?? 0;
                    // The expected ratio is 1.0, but the symmetric isolation window should produce poor results
                    if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    {
                        Assert.AreEqual(poorRatio, ratio, 0.05);
                    }

                    // Revert to original document, and get rid of results cache
                    Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                    FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
                }

                {
                    // Import with asymmetric isolation window
                    SrmDocument docAsym = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                                                                                                   fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test asym", 5, 20))));
                    AssertEx.Serializable(docAsym);
                    Assert.IsTrue(docContainer.SetDocument(docAsym, doc, false));

                    SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    ratio     = nodeGroup.Results[0][0].Ratio ?? 0;
                    // Asymmetric should be a lot closer to 1.0
                    if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    {
                        Assert.AreEqual(fixedRatio, ratio, 0.05);
                    }

                    // Revert to original document, and get rid of results cache
                    Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                    FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
                }

                {
                    // Import with prespecified isolation windows
                    var windowList = new List <IsolationWindow>
                    {
                        new IsolationWindow(999.2702214, 1024.270221),
                        new IsolationWindow(1024.27267, 1049.27267)
                    };
                    SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                                                                                                           fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test prespecified", windowList))));
                    AssertEx.Serializable(docPrespecified);
                    Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false));

                    SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    ratio     = nodeGroup.Results[0][0].Ratio ?? 0;
                    // Asymmetric should be a lot closer to 1.0
                    if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    {
                        Assert.AreEqual(fixedRatio, ratio, 0.05);
                    }

                    // Revert to original document, and get rid of results cache
                    Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                    FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
                }

                {
                    // Import with prespecified targets
                    var windowList = new List <IsolationWindow>
                    {
                        new IsolationWindow(999.2702214, 1024.270221, 1004.27),
                        new IsolationWindow(1024.27267, 1049.27267, 1029.27)
                    };
                    SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                                                                                                           fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test target", windowList))));
                    AssertEx.Serializable(docPrespecified);
                    Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false));

                    SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    ratio     = nodeGroup.Results[0][0].Ratio ?? 0;
                    // Asymmetric should be a lot closer to 1.0
                    if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only)  // Can't use labels without a formula
                    {
                        Assert.AreEqual(fixedRatio, ratio, 0.05);
                    }

                    // Revert to original document, and get rid of results cache
                    Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                    FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
                }

                {
                    // Import with ambiguous prespecified targets
                    var windowList = new List <IsolationWindow>
                    {
                        new IsolationWindow(999.2702214, 1024.270221, 1004.27),
                        new IsolationWindow(1000.0, 1049.27267, 1004.28)
                    };
                    SrmDocument docAmbiguous = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                                                                                                        fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test ambiguous", windowList))));
                    AssertEx.Serializable(docAmbiguous);
                    Assert.IsTrue(docContainer.SetDocument(docAmbiguous, doc, false));

                    try
                    {
                        docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2);
                        Assert.Fail("Expected ambiguous isolation targets.");
                    }
                    catch (Exception x)
                    {
                        AssertEx.AreComparableStrings(Resources.SpectrumFilter_FindFilterPairs_Two_isolation_windows_contain_targets_which_match_the_isolation_target__0__, x.Message, 1);
                    }

                    // Revert to original document, and get rid of results cache
                    Assert.IsTrue(docContainer.SetDocument(doc, docContainer.Document, false));
                    FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
                }

                {
                    // Import with one isolation window, so one result is discarded.
                    var windowList = new List <IsolationWindow>
                    {
                        new IsolationWindow(999.2702214, 1024.270221),
                    };
                    SrmDocument docOneWindow = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan =>
                                                                                                        fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test one window", windowList))));
                    AssertEx.Serializable(docOneWindow);
                    Assert.IsTrue(docContainer.SetDocument(docOneWindow, doc, false));

                    SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 0, 2, 0);
                    nodeGroup = docResults.MoleculeTransitionGroups.First();
                    Assert.IsNull(nodeGroup.Results[0][0].Ratio);

                    // Revert to original document, and get rid of results cache
                    Assert.IsTrue(docContainer.SetDocument(doc, docResults, false));
                    FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd"));
                }
            }

            testFilesDir.Dispose();
        }