Пример #1
0
        public void TestCollectStatistics()
        {
            var         testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string      docPath      = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky");
            SrmDocument doc          = ResultsUtil.DeserializeDocument(docPath);
            var         docContainer = new ResultsTestDocumentContainer(doc, docPath);

            // Import the first RAW file (or mzML for international)
            string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" +
                                                      ExtensionTestContext.ExtThermoRaw);
            var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { MsDataFileUri.Parse(rawPath) }) });

            SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21);

            ChromCacheMinimizer chromCacheMinimizer =
                docResults.Settings.MeasuredResults.GetChromCacheMinimizer(docResults);

            ChromCacheMinimizer.Settings settings =
                new ChromCacheMinimizer.Settings().SetDiscardUnmatchedChromatograms(true);
            ChromCacheMinimizer.MinStatistics minStatistics = null;
            chromCacheMinimizer.Minimize(settings, s => minStatistics = s, null);
            Assert.AreEqual(100, minStatistics.PercentComplete);
            Assert.AreEqual(1.0, minStatistics.MinimizedRatio);

            var docMissingFirstPeptide =
                (SrmDocument)
                docResults.ReplaceChild(
                    docResults.PeptideGroups.First().RemoveChild(docResults.PeptideGroups.First().Children[0]));
            var docWithOnlyFirstPeptide =
                (SrmDocument)
                docResults.ReplaceChild(
                    docResults.PeptideGroups.First().ChangeChildren(new[] { docResults.PeptideGroups.First().Children[0] }));

            ChromCacheMinimizer.MinStatistics statsMissingFirstProtein  = null;
            ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProtein = null;

            settings = settings.SetDiscardUnmatchedChromatograms(true);
            ChromCacheMinimizer minimizerMissingFirstProtein =
                docMissingFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docMissingFirstPeptide);
            ChromCacheMinimizer minimizerWithOnlyFirstProtein =
                docWithOnlyFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docWithOnlyFirstPeptide);

            minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProtein   = s, null);
            minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProtein = s, null);
            Assert.AreEqual(100, statsMissingFirstProtein.PercentComplete);
            Assert.AreEqual(100, statsWithOnlyFirstProtein.PercentComplete);
            Assert.AreEqual(1.0, statsMissingFirstProtein.MinimizedRatio + statsWithOnlyFirstProtein.MinimizedRatio,
                            .00001);
            settings = settings.SetDiscardUnmatchedChromatograms(false);
            ChromCacheMinimizer.MinStatistics statsMissingFirstProteinKeepAll  = null;
            ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProteinKeepAll = null;
            minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProteinKeepAll   = s, null);
            minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProteinKeepAll = s, null);
            Assert.AreEqual(100, statsMissingFirstProteinKeepAll.PercentComplete);
            Assert.AreEqual(1.0, statsMissingFirstProteinKeepAll.MinimizedRatio);
            Assert.AreEqual(100, statsWithOnlyFirstProteinKeepAll.PercentComplete);
            Assert.AreEqual(1.0, statsWithOnlyFirstProteinKeepAll.MinimizedRatio);
            docContainer.Release();
        }
Пример #2
0
        private static ResultsTestDocumentContainer MinimizeCacheFile(SrmDocument document,
                                                                      ChromCacheMinimizer.Settings settings, string skyFilePath)
        {
            Assert.IsNotNull(skyFilePath);  // For ReSharper
            string skydFilePath = Path.ChangeExtension(skyFilePath, ChromatogramCache.EXT);
            ChromCacheMinimizer chromCacheMinimizer = document.Settings.MeasuredResults.GetChromCacheMinimizer(document);

            using (var fs = new FileSaver(skydFilePath))
                using (var fsScans = new FileSaver(skydFilePath + ChromatogramCache.SCANS_EXT, true))
                    using (var fsPeaks = new FileSaver(skydFilePath + ChromatogramCache.PEAKS_EXT, true))
                        using (var fsScores = new FileSaver(skydFilePath + ChromatogramCache.SCORES_EXT, true))
                        {
                            fs.Stream = File.OpenWrite(fs.SafeName);
                            chromCacheMinimizer.Minimize(settings, null, fs.Stream,
                                                         fsScans.FileStream, fsPeaks.FileStream, fsScores.FileStream);
                            fs.Commit();
                        }
            using (var writer = new XmlTextWriter(skyFilePath, Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            })
            {
                var ser = new XmlSerializer(typeof(SrmDocument));
                ser.Serialize(writer, document);

                writer.Flush();
                writer.Close();
            }
            var container = new ResultsTestDocumentContainer(document, skyFilePath, false);

            Assert.IsTrue(container.SetDocument(ResultsUtil.DeserializeDocument(skyFilePath), document, true));
            return(container);
        }