예제 #1
0
        public void AgilentFormatsTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string docPath;
            SrmDocument doc = InitAgilentDocument(testFilesDir, out docPath);

            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            const string replicateName = "AgilentTest";
            string extRaw = ExtensionTestContext.ExtAgilentRaw;
            var chromSets = new[]
                                {
                                    new ChromatogramSet(replicateName, new[]
                                        { new MsDataFilePath(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + extRaw)),  }),
                                };
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets));
            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            docResults = docContainer.Document;
            AssertResult.IsDocumentResultsState(docResults, replicateName,
                doc.PeptideCount, doc.PeptideTransitionGroupCount, 0, doc.PeptideTransitionCount, 0);

            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
예제 #2
0
        public void RefineDocumentTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");

            var document = InitRefineDocument(testFilesDir);
            AssertEx.Serializable(document);  // This checks a longstanding schema error

            // First check a few refinements which should not change the document
            var refineSettings = new RefinementSettings();
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinPeptidesPerProtein = (TestSmallMolecules ? 1 : 3); // That magic small molecule node has just one child
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinTransitionsPepPrecursor = (TestSmallMolecules ? 1 : 2);
            Assert.AreSame(document, refineSettings.Refine(document));

            // Remove the protein with only 3 peptides
            refineSettings.MinPeptidesPerProtein = 4;
            Assert.AreEqual(document.PeptideGroupCount - 1, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein = 1;
            // Remove the precursor with only 2 transitions
            refineSettings.MinTransitionsPepPrecursor = 3;
            Assert.AreEqual(document.PeptideTransitionGroupCount - 1, refineSettings.Refine(document).PeptideTransitionGroupCount);
            refineSettings.MinTransitionsPepPrecursor = null;
            // Remove the heavy precursor
            refineSettings.RefineLabelType = IsotopeLabelType.heavy;
            Assert.AreEqual(document.PeptideTransitionGroupCount - 1, refineSettings.Refine(document).PeptideTransitionGroupCount);
            // Remove everything but the heavy precursor
            refineSettings.RefineLabelType = IsotopeLabelType.light;
            var docRefined = refineSettings.Refine(document);
            AssertEx.IsDocumentState(docRefined, 1, 1, 1, 1, 4);
            // Perform the operation again without protein removal
            refineSettings.MinPeptidesPerProtein = null;
            docRefined = refineSettings.Refine(document);
            AssertEx.IsDocumentState(docRefined, 1, 4, 1, 1, 4);
            refineSettings.RefineLabelType = null;
            // Remove repeated peptides
            refineSettings.RemoveRepeatedPeptides = true;
            Assert.AreEqual(document.PeptideCount - 2, refineSettings.Refine(document).PeptideCount);
            // Remove duplicate peptides
            refineSettings.RemoveDuplicatePeptides = true;
            Assert.AreEqual(document.PeptideCount - 3, refineSettings.Refine(document).PeptideCount);

            // Try settings that remove everything from the document
            refineSettings = new RefinementSettings { MinPeptidesPerProtein = 20 };
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);
            refineSettings.MinPeptidesPerProtein = 1;
            refineSettings.MinTransitionsPepPrecursor = 20;
            Assert.AreEqual(0, refineSettings.Refine(document).PeptideGroupCount);

            testFilesDir.Dispose();
        }
예제 #3
0
        public void RefineResultsTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\Refine.zip");
            Settings.Default.RTCalculatorName = Settings.Default.RTScoreCalculatorList.GetDefaults().First().Name;

            var document = InitRefineDocument(testFilesDir);

            // First check a few refinements which should not change the document
            var refineSettings = new RefinementSettings {RTRegressionThreshold = 0.3};
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.RTRegressionThreshold = null;
            refineSettings.DotProductThreshold = Statistics.AngleToNormalizedContrastAngle(0.1);    // Convert form original cos(angle) dot-product
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.DotProductThreshold = null;
            refineSettings.MinPeakFoundRatio = 0;
            refineSettings.MaxPeakFoundRatio = 1.0;
            Assert.AreSame(document, refineSettings.Refine(document));
            refineSettings.MinPeakFoundRatio = refineSettings.MaxPeakFoundRatio = null;
            // refineSettings.MaxPeakRank = 15;  This will remove unmeasured transitions
            Assert.AreSame(document, refineSettings.Refine(document));

            // Remove nodes without results
            refineSettings.MinPeptidesPerProtein = 1;
            refineSettings.RemoveMissingResults = true;
            var docRefined = refineSettings.Refine(document);
            Assert.AreEqual(document.PeptideGroupCount, docRefined.PeptideGroupCount);
            // First three children should be unchanged
            for (int i = 0; i < 3; i++)
                Assert.AreSame(document.Children[i], docRefined.Children[i]);
            var nodePepGroupRefined = (PeptideGroupDocNode) docRefined.Children[3];
            Assert.AreEqual(1, nodePepGroupRefined.MoleculeCount);
            Assert.AreEqual(1, nodePepGroupRefined.TransitionGroupCount);
            Assert.AreEqual(5, nodePepGroupRefined.TransitionCount);

            // Filter for dot product, ignoring nodes without results
            refineSettings.RemoveMissingResults = false;
            double dotProductThreshold = Statistics.AngleToNormalizedContrastAngle(0.9);    // Convert form original cos(angle) dot-product
            refineSettings.DotProductThreshold = dotProductThreshold;
            docRefined = refineSettings.Refine(document);
            int missingResults = 0;
            foreach (var nodeGroup in docRefined.PeptideTransitionGroups)
            {
                if (!nodeGroup.HasResults || nodeGroup.Results[0] == null)
                    missingResults++;
                else
                    Assert.IsTrue(nodeGroup.Results[0][0].LibraryDotProduct >= dotProductThreshold);
            }
            Assert.AreNotEqual(0, missingResults);
            Assert.IsTrue(missingResults < docRefined.PeptideTransitionGroupCount);

            // Further refine with retention time refinement
            refineSettings.RTRegressionThreshold = 0.95;
            refineSettings.RTRegressionPrecision = 2;   // Backward compatibility
            var docRefinedRT = refineSettings.Refine(document);
            Assert.AreNotEqual(docRefined.PeptideCount, docRefinedRT.PeptideCount);
            // And peak count ratio
            refineSettings.MinPeakFoundRatio = 1.0;
            var docRefinedRatio = refineSettings.Refine(document);
            Assert.AreNotEqual(docRefinedRT.PeptideCount, docRefinedRatio.PeptideCount);
            Assert.IsTrue(ArrayUtil.EqualsDeep(docRefinedRatio.Children,
                refineSettings.Refine(docRefinedRT).Children));
            foreach (var nodeGroup in docRefinedRatio.PeptideTransitionGroups)
            {
                Assert.IsTrue(nodeGroup.HasResults);
                Assert.IsTrue(nodeGroup.HasLibInfo);
                Assert.AreEqual(1.0, nodeGroup.Results[0][0].PeakCountRatio);
            }
            Assert.AreEqual(2, docRefinedRatio.PeptideGroupCount);
            Assert.AreEqual(7, docRefinedRatio.PeptideTransitionGroupCount);

            // Pick only most intense transtions
            refineSettings.MaxPeakRank = 4;
            var docRefineMaxPeaks = refineSettings.Refine(document);
            Assert.AreEqual(28, docRefineMaxPeaks.PeptideTransitionCount);
            // Make sure the remaining peaks really started as the right rank,
            // and did not change.
            var dictIdTran = new Dictionary<int, TransitionDocNode>();
            foreach (var nodeTran in document.PeptideTransitions)
                dictIdTran.Add(nodeTran.Id.GlobalIndex, nodeTran);
            foreach (var nodeGroup in docRefineMaxPeaks.PeptideTransitionGroups)
            {
                Assert.AreEqual(refineSettings.MaxPeakRank, nodeGroup.TransitionCount);
                foreach (TransitionDocNode nodeTran in nodeGroup.Children)
                {
                    int rank = nodeTran.Results[0][0].Rank;
                    Assert.IsTrue(rank <= refineSettings.MaxPeakRank);

                    var nodeTranOld = dictIdTran[nodeTran.Id.GlobalIndex];
                    Assert.AreEqual(nodeTranOld.Results[0][0].Rank, nodeTran.Results[0][0].Rank);
                }
            }

            // Pick only most intenst peptides
            refineSettings = new RefinementSettings { MaxPepPeakRank = 5 };
            var docRefinePepMaxPeaks = refineSettings.Refine(document);
            // 4 groups, one unmeasured and one with only 3 peptides
            Assert.AreEqual(13, docRefinePepMaxPeaks.PeptideCount);
            Assert.AreEqual(docRefinePepMaxPeaks.PeptideCount, docRefinePepMaxPeaks.PeptideTransitionGroupCount);

            // Add heavy labeled precursors for everything
            var settingsNew = docRefineMaxPeaks.Settings.ChangeTransitionFilter(f => f.ChangeAutoSelect(false));
            settingsNew = settingsNew.ChangePeptideModifications(m => m.ChangeHeavyModifications(new[]
                {
                    new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null),
                    new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null),
                }));
            var docPrepareAdd = docRefineMaxPeaks.ChangeSettings(settingsNew);
            refineSettings = new RefinementSettings {RefineLabelType = IsotopeLabelType.heavy, AddLabelType = true};
            var docHeavy = refineSettings.Refine(docPrepareAdd);
            Assert.AreEqual(docRefineMaxPeaks.PeptideTransitionCount*2, docHeavy.PeptideTransitionCount);
            // Verify that the precursors were added with the right transitions
            foreach (var nodePep in docHeavy.Peptides)
            {
                Assert.AreEqual(2, nodePep.Children.Count);
                var lightGroup = (TransitionGroupDocNode) nodePep.Children[0];
                Assert.AreEqual(IsotopeLabelType.light, lightGroup.TransitionGroup.LabelType);
                var heavyGroup = (TransitionGroupDocNode)nodePep.Children[1];
                Assert.AreEqual(IsotopeLabelType.heavy, heavyGroup.TransitionGroup.LabelType);
                Assert.AreEqual(lightGroup.TransitionGroup.PrecursorCharge,
                    heavyGroup.TransitionGroup.PrecursorCharge);
                Assert.AreEqual(lightGroup.Children.Count, heavyGroup.Children.Count);
                for (int i = 0; i < lightGroup.Children.Count; i++)
                {
                    var lightTran = (TransitionDocNode) lightGroup.Children[i];
                    var heavyTran = (TransitionDocNode) heavyGroup.Children[i];
                    Assert.AreEqual(lightTran.Transition.FragmentIonName, heavyTran.Transition.FragmentIonName);
                }
            }
            testFilesDir.Dispose();
        }
예제 #4
0
        public void FullScanPrecursorTransitionsTest()
        {
            TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"TestA\FullScanPrecursor.zip");

            string docPath = testFilesDir.GetTestPath("FullScanPrecursor.sky");
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);
            AssertEx.IsDocumentState(doc, 0, 1, 4, 5, 52);
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            var mitoLibSpec = new BiblioSpecLiteSpec("mito2", testFilesDir.GetTestPath("mito2.blib"));
            doc = docContainer.ChangeLibSpecs(new [] { mitoLibSpec });
            Assert.IsTrue(doc.IsLoaded);

            // Switch to only precursor ions
            var docPrecOnly = doc.ChangeSettings(doc.Settings.ChangeTransitionFilter(filter =>
                filter.ChangeIonTypes(new[] { IonType.precursor })));
            // All precursors should have 3 precursor transitions (M, M+1 and M+2)
            AssertEx.IsDocumentState(docPrecOnly, 3, 1, 4, 5, 15);
            Assert.IsFalse(docPrecOnly.PeptideTransitions.Any(nodeTran => nodeTran.Transition.IonType != IonType.precursor));

            // Use low resolution MS1 filtering
            var docLowMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, null)
                  .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, 0.5, null)));
            // All precursors should have one precursor transition
            AssertEx.IsDocumentState(docLowMs1, 4, 1, 4, 5, 5);

            // Add y-ions to low resolution filtering
            var docLowMs1Y = docLowMs1.ChangeSettings(docLowMs1.Settings.ChangeTransitionFilter(filter =>
                filter.ChangeIonTypes(new[] { IonType.precursor, IonType.y })));
            AssertEx.IsDocumentState(docLowMs1Y, 5, 1, 4, 5, 33);

            // Turn off MS1 filtering
            var docNoMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs =>
                fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.None, null, null)));
            // One of the precursors should have no transitions, since its spectrum has no precursor match
            AssertEx.IsDocumentState(docNoMs1, 4, 1, 4, 5, 4);

            // Turn off MS/MS library matching
            var docNoLibMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib =>
                lib.ChangePick(TransitionLibraryPick.none)));
            // All precursors should have a single precursor transition
            AssertEx.IsDocumentState(docNoLibMatch, 5, 1, 4, 5, 5);

            // Use library plus filter matching
            var docLibPlusMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib =>
                lib.ChangePick(TransitionLibraryPick.all_plus)));
            // All precursors should have a single precursor transition
            AssertEx.IsDocumentState(docLibPlusMatch, 5, 1, 4, 5, 5);

            // Release the library stream, and dispose of the directory
            docContainer.ChangeLibSpecs(new LibrarySpec[0]);
            testFilesDir.Dispose();
        }
예제 #5
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);
        }
예제 #6
0
        public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            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("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, 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);
            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;

            {
                // 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(0.25, 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(1.05, 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(1.05, 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(1.05, 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();
        }
        private void RunMultiplePeptidesSameMz(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
                TestDirectoryName = asSmallMolecules.ToString();

            TestSmallMolecules = false;  // Don't need the magic test node, we have an explicit test

            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string docPath;
            SrmDocument document = InitMultiplePeptidesSameMzDocument(testFilesDir, out docPath);
            document = (new RefinementSettings()).ConvertToSmallMolecules(document, asSmallMolecules);
            var docContainer = new ResultsTestDocumentContainer(document, docPath);

            var doc = docContainer.Document;
            var listChromatograms = new List<ChromatogramSet>();
            var path = MsDataFileUri.Parse(@"AMultiplePeptidesSameMz\ljz_20131201k_Newvariant_standards_braf.mzML");
            listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ??
                    new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path }));
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            document = docContainer.Document;

            float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
            var results = document.Settings.MeasuredResults;
            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);  // without the fix, only the first pair will have a chromatogram
            }
            // now drill down for specific values
            int nPeptides = 0;
            foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null))
            {
                // expecting three peptide result in this small data set
                if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0)
                {
                    Assert.AreEqual(34.2441024780273,(double)nodePep.GetMeasuredRetentionTime(0), .0001);
                    nPeptides++;
                }
            }
            Assert.AreEqual(3, nPeptides); // without the fix this will give just one result
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
예제 #8
0
        public void DoThermoRatioTest(RefinementSettings.ConvertToSmallMoleculesMode smallMoleculesTestMode)
        {
            TestSmallMolecules = false;  // We do this explicitly

            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath;
            SrmDocument doc = InitThermoDocument(testFilesDir, out docPath);
            SrmSettings settings = doc.Settings.ChangePeptideModifications(mods =>
                mods.ChangeInternalStandardTypes(new[]{IsotopeLabelType.light}));
            doc = doc.ChangeSettings(settings);
            if (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                var docOrig = doc;
                var refine = new RefinementSettings();
                doc = refine.ConvertToSmallMolecules(doc, smallMoleculesTestMode);
                // This is our first example of a converted label doc - check roundtripping
                AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(docOrig, doc);
                AssertEx.Serializable(doc);
            }
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            string extRaw = ExtensionTestContext.ExtThermoRaw;
            var listChromatograms = new List<ChromatogramSet>
                                        {
                                            new ChromatogramSet("rep03", new[]
                                                                             {
                                                                                 MsDataFileUri.Parse(testFilesDir.GetTestPath(
                                                                                     "Site20_STUDY9P_PHASEII_QC_03" + extRaw))
                                                                             }),
                                            new ChromatogramSet("rep05", new[]
                                                                             {
                                                                                 MsDataFileUri.Parse(testFilesDir.GetTestPath(
                                                                                     "Site20_STUDY9P_PHASEII_QC_05" + extRaw))
                                                                             })
                                        };
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            docResults = docContainer.Document;
            // Make sure all groups have at least 5 transitions (of 6) with ratios
            int ratioGroupMissingCount = 0;
            foreach (var nodeGroup in docResults.MoleculeTransitionGroups)
            {
                if (nodeGroup.TransitionGroup.LabelType.IsLight)
                {
                    foreach (var result in nodeGroup.Results)
                        Assert.IsFalse(result[0].Ratio.HasValue, "Light group found with a ratio");
                    foreach (TransitionDocNode nodeTran in nodeGroup.Children)
                    {
                        foreach (var resultTran in nodeTran.Results)
                            Assert.IsFalse(resultTran[0].Ratio.HasValue, "Light transition found with a ratio");
                    }
                }
                else
                {
                    bool missingRatio = false;
                    foreach (ChromInfoList<TransitionGroupChromInfo> chromInfoList in nodeGroup.Results)
                    {
                        var ratioHeavy = chromInfoList[0].Ratio;
                        if (!ratioHeavy.HasValue)
                            missingRatio = true;
                    }
                    int ratioCount1 = 0;
                    int ratioCount2 = 0;
                    foreach (TransitionDocNode nodeTranHeavy in nodeGroup.Children)
                    {
                        float? ratioHeavy = nodeTranHeavy.Results[0][0].Ratio;
                        if (ratioHeavy.HasValue)
                        {
                            Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value));
                            ratioCount1++;
                        }
                        ratioHeavy = nodeTranHeavy.Results[1][0].Ratio;
                        if (ratioHeavy.HasValue)
                        {
                            Assert.IsFalse(float.IsNaN(ratioHeavy.Value) || float.IsInfinity(ratioHeavy.Value));
                            ratioCount2++;
                        }
                    }
                    Assert.AreEqual(3, ratioCount1);
                    if (ratioCount2 < 2)
                        ratioGroupMissingCount++;
                    else
                        Assert.IsFalse(missingRatio, "Precursor missing ratio when transitions have ratios");
                }
            }
            // 3 groups with less than 2 transition ratios
            Assert.AreEqual(3, ratioGroupMissingCount);

            // Remove the first light transition, checking that this removes the ratio
            // from the corresponding heavy transition, but not the entire group, until
            // after all light transitions have been removed.
            IdentityPath pathFirstPep = docResults.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep);
            Assert.AreEqual(2, nodePep.Children.Count);
            var nodeGroupLight = (TransitionGroupDocNode) nodePep.Children[0];
            IdentityPath pathGroupLight = new IdentityPath(pathFirstPep, nodeGroupLight.TransitionGroup);
            Assert.IsNull(nodeGroupLight.Results[0][0].Ratio, "Light group has ratio");
            var nodeGroupHeavy = (TransitionGroupDocNode) nodePep.Children[1];
            IdentityPath pathGroupHeavy = new IdentityPath(pathFirstPep, nodeGroupHeavy.TransitionGroup);
            float? ratioStart = nodeGroupHeavy.Results[0][0].Ratio;
            Assert.IsTrue(ratioStart.HasValue, "No starting heavy group ratio");
            var expectedValues = new[] { 1.403414, 1.38697791, 1.34598482 };
            for (int i = 0; i < 3; i++)
            {
                var pathLight = docResults.GetPathTo((int) SrmDocument.Level.Transitions, 0);
                var pathHeavy = docResults.GetPathTo((int) SrmDocument.Level.Transitions, 3);
                TransitionDocNode nodeTran = (TransitionDocNode) docResults.FindNode(pathHeavy);
                float? ratioTran = nodeTran.Results[0][0].Ratio;
                Assert.IsTrue(ratioTran.HasValue, "Expected transition ratio not found");
                Assert.AreEqual(ratioTran.Value, expectedValues[i], 1.0e-5);
                docResults = (SrmDocument) docResults.RemoveChild(pathLight.Parent, docResults.FindNode(pathLight));
                nodeTran = (TransitionDocNode) docResults.FindNode(pathHeavy);
                Assert.IsFalse(nodeTran.Results[0][0].Ratio.HasValue, "Unexpected transiton ratio found");
                Assert.AreEqual(pathGroupHeavy, pathHeavy.Parent, "Transition found outside expected group");
            //                nodePep = (PeptideDocNode) docResults.FindNode(pathFirstPep);
                nodeGroupHeavy = (TransitionGroupDocNode) docResults.FindNode(pathGroupHeavy);
            //                Assert.AreEqual(nodePep.Results[0][0].RatioToStandard, nodeGroupHeavy.Results[0][0].Ratio,
            //                                "Peptide and group ratios not equal");
                if (i < 2)
                {
                    float? ratioGroup = nodeGroupHeavy.Results[0][0].Ratio;
                    Assert.IsTrue(ratioGroup.HasValue, "Group ratio removed with transition ratios");
                    Assert.AreEqual(ratioStart.Value, ratioGroup.Value, 0.1,
                                    "Unexpected group ratio change by more than 0.1");
                }
                else
                {
                    Assert.IsFalse(nodeGroupHeavy.Results[0][0].Ratio.HasValue,
                                   "Group ratio still present with no transition ratios");
                }
            }
            bool asSmallMolecules = (smallMoleculesTestMode != RefinementSettings.ConvertToSmallMoleculesMode.none);
            if (!asSmallMolecules) // GetTransitions() doesn't work the same way for small molecules - it only lists existing ones
            {
                bool firstAdd = true;
                var nodeGroupLightOrig = (TransitionGroupDocNode) doc.FindNode(pathGroupLight);
                DocNode[] lightChildrenOrig = nodeGroupLightOrig.Children.ToArray();
                foreach (var nodeTran in nodeGroupLightOrig.GetTransitions(docResults.Settings,
                    null, nodeGroupLightOrig.PrecursorMz, null, null, null, false))
                {
                    var transition = nodeTran.Transition;
                    if (!firstAdd && lightChildrenOrig.IndexOf(node => Equals(node.Id, transition)) == -1)
                        continue;
                    // Add the first transition, and then the original transitions
                    docResults = (SrmDocument) docResults.Add(pathGroupLight, nodeTran);
                    nodeGroupHeavy = (TransitionGroupDocNode) docResults.FindNode(pathGroupHeavy);
                    if (firstAdd)
                        Assert.IsNull(nodeGroupHeavy.Results[0][0].Ratio, "Unexpected heavy ratio found");
                    else
                        Assert.IsNotNull(nodeGroupHeavy.Results[0][0].Ratio,
                            "Heavy ratio null after adding light children");
                    firstAdd = false;
                }
                Assert.AreEqual(ratioStart, nodeGroupHeavy.Results[0][0].Ratio);
            }
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
예제 #9
0
 public void ThermoFormatsTest()
 {
     var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
     string docPath;
     SrmDocument doc = InitThermoDocument(testFilesDir, out docPath);
     var docContainer = new ResultsTestDocumentContainer(doc, docPath);
     // Verify mzML and RAW contain same results
     string extRaw = ExtensionTestContext.ExtThermoRaw;
     AssertResult.MatchChromatograms(docContainer,
                                 testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + extRaw),
                                 testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03.mzML"),
                                 0, 0);
     // Verify mzXML and RAW contain same results (some small peaks are different)
     AssertResult.MatchChromatograms(docContainer,
                                 testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + extRaw),
                                 testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03.mzXML"),
                                 2, 0);
     // Release file handles
     docContainer.Release();
     testFilesDir.Dispose();
 }
예제 #10
0
        public void ThermoCancelImportTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath;
            SrmDocument doc = InitThermoDocument(testFilesDir, out docPath);
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            string resultsPath = testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" +
                ExtensionTestContext.ExtThermoRaw);
            string dirPath = Path.GetDirectoryName(resultsPath) ?? "";
            // Remove any existing temp and cache files
            foreach (var path in Directory.GetFiles(dirPath))
            {
                if (IsCacheOrTempFile(path))
                    FileEx.SafeDelete(path);
            }
            string name = Path.GetFileNameWithoutExtension(resultsPath);
            var listChromatograms = new List<ChromatogramSet> {new ChromatogramSet(name, new[] {MsDataFileUri.Parse(resultsPath)})};
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            // Start cache load, but don't wait for completion
            Assert.IsTrue(docContainer.SetDocument(docResults, doc));

            // Wait up to 1 second for the cache to start being written
            for (int i = 0; i < 100; i++)
            {
                if (Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) != -1)
                    break;
                Thread.Sleep(10);
            }

            Assert.IsTrue(Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) != -1, "Failed to create cache file");

            // Cancel by reverting to the original document
            Assert.IsTrue(docContainer.SetDocument(doc, docResults));
            // Wait up to 5 seconds for cancel to occur
            for (int i = 0; i < 50; i++)
            {
                if (docContainer.LastProgress.IsCanceled)
                    break;
                Thread.Sleep(100);
            }
            if (!docContainer.LastProgress.IsCanceled)
            {
                Assert.Fail("Attempt to cancel results load failed. {0}", docContainer.LastProgress.ErrorException != null
                    ? docContainer.LastProgress.ErrorException.Message : string.Empty);
            }

            // Wait up to 20 seconds for the cache to be removed
            for (int i = 0; i < 200; i++)
            {
                if (Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) == -1)
                    break;
                Thread.Sleep(100);
            }
            // Cache file has been removed
            Assert.IsTrue(Directory.GetFiles(dirPath).IndexOf(IsCacheOrTempFile) == -1, "Failed to remove cache file");
            testFilesDir.Dispose();
        }
예제 #11
0
        public void DoAgilentMseChromatogramTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules)
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            TestSmallMolecules = false; // We have an explicit test for that here

            string docPath;
            SrmDocument document = InitAgilentMseDocument(testFilesDir, out docPath);
            if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none)
            {
                var refine = new RefinementSettings();
                document = refine.ConvertToSmallMolecules(document, asSmallMolecules);
            }
            var docContainer = new ResultsTestDocumentContainer(document, docPath);
            var doc = docContainer.Document;
            var listChromatograms = new List<ChromatogramSet>();
            var path = MsDataFileUri.Parse(@"AgilentMse\BSA-AI-0-10-25-41_first_100_scans.mzML");
            listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ??
                    new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path }));
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            document = docContainer.Document;

            float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
            var results = document.Settings.MeasuredResults;
            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);
            }

            // 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(0.2462, (double)nodePep.GetMeasuredRetentionTime(0), .0001, "averaged retention time differs in node "+nodePep.RawTextId);
                    Assert.AreEqual(0.3333, (double)nodePep.GetPeakCountRatio(0), 0.0001);
                    nPeptides++;
                }
            }
            Assert.AreEqual(1, nPeptides);
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
예제 #12
0
        public void WatersMzXmlTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string docPath;
            SrmDocument doc = InitWatersDocument(testFilesDir, out docPath);
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            // Verify mzXML and mzML contained same results
            // TODO: Figure out why these don't match well enough to use strict compare
            AssertResult.MatchChromatograms(docContainer,
                                            testFilesDir.GetTestPath("160109_Mix1_calcurve_070.mzML"),
                                            testFilesDir.GetTestPath("160109_Mix1_calcurve_070.mzXML"),
                                            -1, 0);
            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
예제 #13
0
        public void WatersCacheTest()
        {
            // First test transition from per-replicate caching strategy to
            // single cache per document strategy.
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            // Open the replicate document, and let it reload the data from mzML
            // showing the document can find data files by name in its own directory,
            // since the document paths will not match those on disk.
            string docPath;
            var doc = InitWatersDocument(testFilesDir, out docPath);
            var docReload = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_rep.sky", out docPath);
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            var streamManager = docContainer.ChromatogramManager.StreamManager;
            Assert.IsTrue(docContainer.SetDocument(docReload, doc, true));
            docContainer.AssertComplete();
            docReload = docContainer.Document;
            // Release file handles to cache files created during load
            Assert.IsTrue(docContainer.SetDocument(doc, docReload));
            // Delete the cache
            string cachePath = Path.ChangeExtension(docPath, ".skyd");
            FileEx.SafeDelete(cachePath);

            // Then try using cached replicate files
            // Move per-replicate cache files into place
            var replicateCacheNames = new[]
                {
                    "160109_Mix1_calcurve_rep_calcurve_070.skyd",
                    "160109_Mix1_calcurve_rep_calcurve_073.skyd"
                };
            GetCacheFiles(testFilesDir, replicateCacheNames);
            // Delete the files these cache
            DeleteFiles(testFilesDir,
                new[]
                {
                    "160109_Mix1_calcurve_070.mzML",
                    "160109_Mix1_calcurve_073.mzML",
                });
            var docCached = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_rep.sky", out docPath);
            Assert.IsTrue(docContainer.SetDocument(docCached, doc, true));
            docContainer.AssertComplete();
            docCached = docContainer.Document;

            // The document with data from the .mzML files should be the same as
            // the one loaded from the .skyd files.
            // Unfortunately, this is to hard to maintain when cache changes are made.
            // AssertEx.Cloned(docCached, docReload);

            // The one cache should be present
            Assert.IsTrue(File.Exists(cachePath));
            // And the replicate cache files should have been removed
            foreach (var cacheName in replicateCacheNames)
                Assert.IsFalse(File.Exists(testFilesDir.GetTestPath(cacheName)));

            // Save the cache file time stamp
            var cacheInfo = new FileInfo(cachePath);
            long cacheSize = cacheInfo.Length;

            // Adding files already in the document should have no impact on the cache.
            string extRaw = ExtensionTestContext.ExtWatersRaw;
            var listChromatograms = new List<ChromatogramSet>(docCached.Settings.MeasuredResults.Chromatograms)
                {
                    new ChromatogramSet("extra1",
                                        new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + extRaw)) }),
                    new ChromatogramSet("extra2",
                                        new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML")) })
                };

            // Adding a new file should cause the cache to grow.
            var settings = docCached.Settings.MeasuredResults.ChangeChromatograms(listChromatograms);
            var docGrow = docCached.ChangeMeasuredResults(settings);
            Assert.IsTrue(docContainer.SetDocument(docGrow, docCached, true));
            docContainer.AssertComplete();
            docGrow = docContainer.Document;

            cacheInfo = new FileInfo(cachePath);
            Assert.IsTrue(cacheSize < cacheInfo.Length);

            cacheSize = cacheInfo.Length;
            var writeTime = cacheInfo.LastWriteTime;

            listChromatograms.Add(
                    new ChromatogramSet("double",
                        new[]
                            {
                                testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + extRaw),
                                testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML")
                            }));

            settings = docGrow.Settings.MeasuredResults.ChangeChromatograms(listChromatograms);
            var docNoCacheChange1 = docGrow.ChangeMeasuredResults(settings);
            Assert.IsTrue(docContainer.SetDocument(docNoCacheChange1, docGrow, true));
            docContainer.AssertComplete();
            docNoCacheChange1 = docContainer.Document;

            Assert.AreEqual(writeTime, File.GetLastWriteTime(cachePath));

            // Removing files should have no impact, until optimized
            listChromatograms.RemoveRange(listChromatograms.Count - 2, 2);
            listChromatograms.RemoveAt(1);

            settings = docNoCacheChange1.Settings.MeasuredResults.ChangeChromatograms(listChromatograms);
            var docNoCacheChange2 = docNoCacheChange1.ChangeMeasuredResults(settings);
            Assert.IsTrue(docContainer.SetDocument(docNoCacheChange2, docNoCacheChange1, true));
            docContainer.AssertComplete();
            docNoCacheChange2 = docContainer.Document;

            Assert.AreEqual(writeTime, File.GetLastWriteTime(cachePath));

            // Optimizing should shrink the cache
            var results = docNoCacheChange2.Settings.MeasuredResults.OptimizeCache(docPath, streamManager);
            var docOptimized = new SrmDocument(docNoCacheChange2,
                                               docNoCacheChange2.Settings.ChangeMeasuredResults(results),
                                               docNoCacheChange2.Children);
            // This should not cause a reload
            Assert.IsTrue(docContainer.SetDocument(docOptimized, docNoCacheChange2, false));

            cacheInfo = new FileInfo(cachePath);
            Assert.IsTrue(cacheSize > cacheInfo.Length);

            // Test file caches
            // First reload the files from .mzML
            docReload = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_file.sky", out docPath);
            // Change the path to use the right .skyd file
            docContainer.DocumentFilePath = docPath;
            Assert.IsTrue(docContainer.SetDocument(docReload, docOptimized, true));
            docContainer.AssertComplete();
            docReload = docContainer.Document;
            // Release file handles to cache files created during load
            Assert.IsTrue(docContainer.SetDocument(doc, docReload));
            // Delete the cache
            cachePath = Path.ChangeExtension(docPath, ".skyd");
            FileEx.SafeDelete(cachePath);

            // Then try using cached files
            // Move per-file cache files into place
            var fileCacheNames = new[]
                {
                    "160109_Mix1_calcurve_075.mzML.skyd",
                    "160109_Mix1_calcurve_078.mzML.skyd"
                };
            GetCacheFiles(testFilesDir, fileCacheNames);
            // Swap the mzML files, so the test will fail, if not reading from the cache
            // CONSIDER: Should this really work, since they have different time stamps?
            string file075 = testFilesDir.GetTestPath("160109_Mix1_calcurve_075.mzML");
            string file078 = testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML");
            string fileTemp = file075 + ".tmp";
            File.Move(file075, fileTemp);
            File.Move(file078, file075);
            File.Move(fileTemp, file078);

            docCached = InitWatersDocument(testFilesDir, "160109_Mix1_calcurve_file.sky", out docPath);
            // Make sure cache files exactly match the names the loader will look for
            var listResultsFiles = new List<MsDataFileUri>();
            foreach (var chromatogram in docCached.Settings.MeasuredResults.Chromatograms)
                listResultsFiles.AddRange(chromatogram.MSDataFilePaths);
            for (int i = 0; i < fileCacheNames.Length; i++)
            {
                string partPath = ChromatogramCache.PartPathForName(docPath, listResultsFiles[i]);
                File.Move(testFilesDir.GetTestPath(fileCacheNames[i]), partPath);
            }

            Assert.IsTrue(docContainer.SetDocument(docCached, doc, true));
            docContainer.AssertComplete();
            // docCached = docContainer.Document;

            // The document with data from the .mzML files should be the same as
            // the one loaded from the .skyd files.
            // Unfortunately, this is to hard to maintain when cache changes are made.
            // AssertEx.Cloned(docCached, docReload);

            // The one cache should be present
            Assert.IsTrue(File.Exists(Path.ChangeExtension(docPath, ".skyd")));
            // And the replicate cache files should have been removed
            foreach (var cacheName in fileCacheNames)
                Assert.IsFalse(File.Exists(testFilesDir.GetTestPath(cacheName)));

            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }
예제 #14
0
        public void WatersMultiReplicateTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string docPath;
            SrmDocument docOriginal = InitWatersDocument(testFilesDir, out docPath);
            SrmDocument doc = docOriginal;
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            string extRaw = ExtensionTestContext.ExtWatersRaw;

            string[] replicatePaths =
            {
                testFilesDir.GetTestPath("160109_Mix1_calcurve_070.mzML"),
                testFilesDir.GetTestPath("160109_Mix1_calcurve_073.mzML"),
                testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + extRaw),
                testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML")
            };
            // Count peaks where higher concentration replicates show less area
            int outOfOrder = 0;
            foreach (string path in replicatePaths)
            {
                var listChromatograms = new List<ChromatogramSet>();
                if (doc.Settings.HasResults)
                    listChromatograms.AddRange(doc.Settings.MeasuredResults.Chromatograms);

                string name = Path.GetFileNameWithoutExtension(path);
                if (name != null)
                    name = name.Substring(name.Length - 12);
                listChromatograms.Add(new ChromatogramSet(name, new[] {MsDataFileUri.Parse(path)}));
                int len = listChromatograms.Count;

                var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
                // Adding unloaded results should add a new null result.
                foreach (var nodeTran in docResults.PeptideTransitions)
                {
                    Assert.IsTrue(nodeTran.HasResults);
                    Assert.AreEqual(listChromatograms.Count, nodeTran.Results.Count);
                    Assert.IsNull(nodeTran.Results[len - 1]);
                }

                Assert.IsTrue(docContainer.SetDocument(docResults, doc, true),
                    string.Format("Failed adding results for {0}.", path));
                docContainer.AssertComplete();
                docResults = docContainer.Document;

                Assert.IsTrue(docResults.Settings.MeasuredResults.IsLoaded);

                var transOld = doc.PeptideTransitions.ToArray();
                var transNew = docResults.PeptideTransitions.ToArray();
                Assert.AreEqual(transOld.Length, transNew.Length);
                int countPeaks = 0;
                for (int i = 0; i < transNew.Length; i++)
                {
                    // Make sure new peak was added to each transition
                    var nodeTranNew = transNew[i];
                    Assert.IsTrue(nodeTranNew.HasResults);
                    Assert.AreEqual(len, nodeTranNew.Results.Count);
                    var chromInfo = nodeTranNew.Results[len - 1][0];
                    Assert.IsNotNull(chromInfo);

                    if (!chromInfo.IsEmpty)
                        countPeaks++;

                    // Make sure previously loaded peaks did not change
                    for (int j = 0; j < len - 1; j++)
                    {
                        var chromInfoPrevious = transOld[i].Results[j][0];
                        Assert.AreSame(chromInfoPrevious, nodeTranNew.Results[j][0]);
                        if ((chromInfo.IsEmpty && !chromInfoPrevious.IsEmpty) ||
                                (!chromInfo.IsEmpty && chromInfoPrevious.Area >= chromInfo.Area))
                            outOfOrder++;
                    }
                }
                // Allow 2 missed peaks
                Assert.IsTrue(countPeaks >= transNew.Length - (TestSmallMolecules ? 1 : 0) - 2);

                // Check results calculations for peptides and groups
                foreach (var nodePep in docResults.Peptides)
                {
                    Assert.AreEqual(len, nodePep.Results.Count);
                    Assert.IsTrue(nodePep.HasResults);
                    var chromInfo = nodePep.Results[len - 1][0];
                    Assert.AreEqual(1, nodePep.Children.Count);
                    var nodeGroup = (TransitionGroupDocNode) nodePep.Children[0];
                    Assert.IsTrue(nodeGroup.HasResults);
                    Assert.AreEqual(len, nodeGroup.Results.Count);
                    var chromInfoGroup = nodeGroup.Results[len - 1][0];
                    Assert.IsTrue(chromInfoGroup.PeakCountRatio >= 0.5);
                    Assert.IsTrue(chromInfoGroup.RetentionTime.HasValue);
                    Assert.IsTrue(chromInfoGroup.Area.HasValue && chromInfoGroup.Area > 290);

                    Assert.AreEqual(chromInfo.RetentionTime, chromInfoGroup.RetentionTime);
                    Assert.AreEqual(chromInfo.PeakCountRatio, chromInfoGroup.PeakCountRatio);
                }

                doc = docResults;
            }

            Assert.AreEqual(13, outOfOrder, 1);

            // Remove the original data
            foreach (string path in replicatePaths)
            {
                if (File.Exists(path))
                    FileEx.SafeDelete(path);
                else
                    DirectoryEx.SafeDelete(path);
            }
            FileEx.SafeDelete(docPath);

            // Save the document
            string xmlSaved = null;
            var docPersisted = AssertEx.RoundTrip(doc, ref xmlSaved);
            Assert.IsTrue(!docPersisted.Settings.MeasuredResults.IsLoaded);
            // Make sure the persisted document round-trips.
            // The orginal doesn't because of changing precision in the results info.
            AssertEx.Serializable(docPersisted, AssertEx.DocumentCloned);

            // Make sure the loaded document has reasonable results info
            // before the cache files are loaded
            for (int i = 0; i < doc.Children.Count; i++)
            {
                PeptideGroupDocNode nodePepGroup1 = (PeptideGroupDocNode) doc.Children[i];
                if (TestSmallMolecules && nodePepGroup1.Name.Equals(SrmDocument.TestingNonProteomicMoleculeGroupName))
                    continue;
                PeptideGroupDocNode nodePepGroup2 = (PeptideGroupDocNode) docPersisted.Children[i];
                Assert.AreNotSame(nodePepGroup1, nodePepGroup2);
                for (int j = 0; j < nodePepGroup1.Children.Count; j++)
                {
                    PeptideDocNode nodePep1 = (PeptideDocNode) nodePepGroup1.Children[j];
                    PeptideDocNode nodePep2 = (PeptideDocNode) nodePepGroup2.Children[j];
                    Assert.AreNotSame(nodePep1, nodePep2);
                    Assert.AreEqual(nodePep1.Results.Count, nodePep2.Results.Count);
                    for (int k = 0; k < nodePep1.Results.Count; k++)
                        Assert.AreEqual(nodePep1.Results[k][0].PeakCountRatio, nodePep2.Results[k][0].PeakCountRatio);
                    for (int k = 0; k < nodePep1.Children.Count; k++)
                    {
                        TransitionGroupDocNode nodeGroup1 = (TransitionGroupDocNode) nodePep1.Children[k];
                        TransitionGroupDocNode nodeGroup2 = (TransitionGroupDocNode) nodePep2.Children[k];
                        Assert.AreNotSame(nodeGroup1, nodeGroup2);
                        Assert.AreEqual(nodeGroup1.Results.Count, nodeGroup2.Results.Count);
                        for (int l = 0; l < nodeGroup1.Results.Count; l++)
                            Assert.AreEqual(nodeGroup1.Results[l][0].PeakCountRatio,
                                            nodeGroup2.Results[l][0].PeakCountRatio);
                        for (int l = 0; l < nodeGroup1.Children.Count; l++)
                        {
                            TransitionDocNode nodeTran1 = (TransitionDocNode) nodeGroup1.Children[l];
                            TransitionDocNode nodeTran2 = (TransitionDocNode) nodeGroup2.Children[l];
                            Assert.AreNotSame(nodeTran1, nodeTran2);
                            Assert.AreEqual(nodeTran1.Results.Count, nodeTran2.Results.Count);
                            for (int m = 0; m < nodeTran1.Results.Count; m++)
                            {
                                if (nodeTran1.Results[m] != null && nodeTran2.Results[m] != null)
                                    Assert.AreEqual(nodeTran1.Results[m][0].IsEmpty, nodeTran2.Results[m][0].IsEmpty);
                                else
                                    Assert.AreEqual(nodeTran1.Results[m], nodeTran2.Results[m]); // both null
                            }
                        }
                    }
                }
            }

            // Reload data from .skyd files
            Assert.IsTrue(docContainer.SetDocument(docPersisted, doc, true));
            docContainer.AssertComplete();
            doc = docContainer.Document;

            var results = doc.Settings.MeasuredResults;
            const float tolerance = (float) TransitionInstrument.DEFAULT_MZ_MATCH_TOLERANCE;
            foreach (var pair in doc.PeptidePrecursorPairs)
            {
                foreach (var chromSet in results.Chromatograms)
                {
                    ChromatogramGroupInfo[] chromGroupInfo;
                    Assert.IsTrue(results.TryLoadChromatogram(chromSet, pair.NodePep, pair.NodeGroup,
                                                              tolerance, true, out chromGroupInfo));
                }
            }

            // The single final cache path should be open now
            var listCachePaths = new List<string>(doc.Settings.MeasuredResults.CachePaths);
            // Should only have one cache file at this point
            Assert.AreEqual(1, listCachePaths.Count);
            foreach (var cachePath in listCachePaths)
            {
                // Attempting to delete should throw
                string path = cachePath;
                AssertEx.ThrowsException<IOException>(() => FileEx.SafeDelete(path));
            }

            // Release the .skyd file
            docContainer.Release();
            foreach (var cachePath in listCachePaths)
            {
                // Cache files should be closed now, and delete successfully.
                FileEx.SafeDelete(cachePath);
            }
            testFilesDir.Dispose();
        }
예제 #15
0
        public void WatersMultiFileTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);

            string docPath;
            SrmDocument docOriginal = InitWatersDocument(testFilesDir, out docPath);
            SrmDocument doc = docOriginal;
            var docContainer = new ResultsTestDocumentContainer(doc, docPath);
            string extRaw = ExtensionTestContext.ExtWatersRaw;

            var listChromatograms = new List<ChromatogramSet>
            {
                new ChromatogramSet("double", new[]
                    {
                        MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_070.mzML")),
                        MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_073.mzML"))
                    }),
                new ChromatogramSet("trouble", new[]
                    {
                        MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_075" + extRaw)),
                        MsDataFileUri.Parse(testFilesDir.GetTestPath("160109_Mix1_calcurve_078.mzML"))
                    })
            };
            var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms));
            Assert.IsTrue(docContainer.SetDocument(docResults, doc, true));
            docContainer.AssertComplete();
            docResults = docContainer.Document;
            Assert.IsTrue(docResults.Settings.HasResults);
            var measuredResults = docResults.Settings.MeasuredResults;
            var chromatograms = measuredResults.Chromatograms;
            Assert.AreEqual(2, chromatograms.Count);

            const float tolerance = (float)TransitionInstrument.DEFAULT_MZ_MATCH_TOLERANCE;

            foreach (var pair in docResults.PeptidePrecursorPairs)
            {
                var nodePep = pair.NodePep;
                var nodeGroup = pair.NodeGroup;
                Assert.IsTrue(nodeGroup.HasResults);
                Assert.AreEqual(2, nodeGroup.Results.Count);
                foreach (var result in nodeGroup.Results)
                    Assert.AreEqual(2, result.Count);
                for (int i = 0; i < 2; i++)
                {
                    ChromatogramGroupInfo[] chromInfos;
                    Assert.IsTrue(measuredResults.TryLoadChromatogram(i, nodePep, nodeGroup, tolerance, true, out chromInfos));
                    Assert.AreEqual(2, chromInfos.Length);
                    double[] peakAreas = new double[2];
                    for (int j = 0; j < 2; j++)
                    {
                        var chromInfo = chromInfos[j];
                        Assert.IsTrue(chromInfo.BestPeakIndex != -1);
                        foreach (var tranInfo in chromInfo.TransitionPointSets)
                        {
                            var peakInfo = tranInfo.GetPeak(chromInfo.BestPeakIndex);
                            if (peakInfo.IsEmpty || peakInfo.IsForcedIntegration)
                                continue;

                            // Check times
                            var times = tranInfo.Times;
                            int iStart = Array.BinarySearch(times, peakInfo.StartTime);
                            Assert.IsTrue(iStart >= 0);
                            int iEnd = Array.BinarySearch(times, peakInfo.EndTime);
                            Assert.IsTrue(iEnd >= 0);
                            int iPeak = Array.BinarySearch(times, iStart, iEnd - iStart, peakInfo.RetentionTime);
                            // Check intensities at times
                            var intensities = tranInfo.Intensities;
                            Assert.IsTrue(intensities[iStart] < intensities[iPeak]);
                            Assert.IsTrue(intensities[iEnd] < intensities[iPeak]);
                            // Sum peak area
                            peakAreas[j] += peakInfo.Area;
                        }
                    }
                    Assert.IsTrue(peakAreas[0] < peakAreas[1]);
                }
            }

            // Release file handles
            docContainer.Release();
            testFilesDir.Dispose();
        }