Esempio n. 1
0
        public void ExportChromatograms(string chromatogramsFile, bool precursors, bool products, bool basePeaks, bool tics)
        {
            _out.WriteLine(Resources.CommandLine_ExportChromatograms_Exporting_chromatograms_file__0____, chromatogramsFile);

            var chromExtractors = new List<ChromExtractor>();
            if (tics)
                chromExtractors.Add(ChromExtractor.summed);
            if (basePeaks)
                chromExtractors.Add(ChromExtractor.base_peak);

            var chromSources = new List<ChromSource>();
            if (precursors)
                chromSources.Add(ChromSource.ms1);
            if (products)
                chromSources.Add(ChromSource.fragment);

            if (chromExtractors.Count == 0 && chromSources.Count == 0)
            {
                _out.WriteLine(Resources.CommandLine_ExportChromatograms_Error__At_least_one_chromatogram_type_must_be_selected);
                return;
            }

            var filesToExport = Document.Settings.HasResults
                ? Document.Settings.MeasuredResults.MSDataFilePaths.Select(f => f.GetFileName()).ToList()
                : new List<string>();
            if (filesToExport.Count == 0)
            {
                _out.WriteLine(Resources.CommandLine_ExportChromatograms_Error__The_document_must_have_imported_results);
                return;
            }

            try
            {
                var chromExporter = new ChromatogramExporter(Document);
                using (var saver = new FileSaver(chromatogramsFile))
                using (var writer = new StreamWriter(saver.SafeName))
                {
                    var status = new ProgressStatus(string.Empty);
                    IProgressMonitor broker = new CommandProgressMonitor(_out, status);
                    chromExporter.Export(writer, broker, filesToExport, LocalizationHelper.CurrentCulture, chromExtractors, chromSources);
                    writer.Close();
                    broker.UpdateProgress(status.Complete());
                    saver.Commit();
                    _out.WriteLine(Resources.CommandLine_ExportChromatograms_Chromatograms_file__0__exported_successfully_, chromatogramsFile);
                }
            }
            catch (Exception x)
            {
                _out.WriteLine(Resources.CommandLine_ExportChromatograms_Error__Failure_attempting_to_save_chromatograms_file__0_, chromatogramsFile);
                _out.WriteLine(x.Message);
            }
        }
Esempio n. 2
0
        public void ConsoleChromatogramExportTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky");
            string outPath = testFilesDir.GetTestPath("Exported_chromatograms.csv");

            // Import the first RAW file (or mzML for international)
            string rawFile = "ah_20101011y_BSA_MS-MS_only_5-2" + ExtensionTestContext.ExtThermoRaw;
            string rawPath = testFilesDir.GetTestPath(rawFile);
            const string replicate = "Single";

            //Attach replicate
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);
            ProgressStatus status;
            doc = CommandLine.ImportResults(doc, docPath, replicate, MsDataFileUri.Parse(rawPath), null, null, out status);
            Assert.IsNull(status);

            //First, programmatically generate the report
            var chromFiles = new[] { rawFile };
            var chromExporter = new ChromatogramExporter(doc);
            var chromExtractors = new[] { ChromExtractor.summed, ChromExtractor.base_peak };
            var chromSources = new[] { ChromSource.ms1, ChromSource.fragment };
            var chromBuffer = new StringBuilder();
            using (var chromWriter = new StringWriter(chromBuffer))
            {
                chromExporter.Export(chromWriter, null, chromFiles, LocalizationHelper.CurrentCulture, chromExtractors,
                    chromSources);
            }
            doc.Settings.MeasuredResults.ReadStreams.ForEach(s => s.CloseStream());
            string programmaticReport = chromBuffer.ToString();

            RunCommand("--in=" + docPath,
                       "--import-file=" + rawPath,
                       "--import-replicate-name=" + replicate,
                       "--chromatogram-file=" + outPath,
                       "--chromatogram-precursors",
                       "--chromatogram-products",
                       "--chromatogram-base-peaks",
                       "--chromatogram-tics");

            string chromLines = File.ReadAllText(outPath);
            AssertEx.NoDiff(chromLines, programmaticReport);
        }
 public void WriteChromatograms(string filePath, 
     IProgressMonitor progressMonitor,
     IList<string> filesToExport,
     CultureInfo cultureInfo,
     IList<ChromExtractor> chromExtractors,
     IList<ChromSource> chromSources)
 {
     var chromExporter = new ChromatogramExporter(Document);
     using (var saver = new FileSaver(filePath))
     using (var writer = new StreamWriter(saver.SafeName))
     {
         chromExporter.Export(writer, progressMonitor, filesToExport, cultureInfo, chromExtractors, chromSources);
         writer.Close();
         saver.Commit();
     }
 }
 private static void SaveChrom(SrmDocument docResults,
     string fileToSave,
     IList<string> fileNames,
     CultureInfo cultureInfo,
     IList<ChromExtractor> extractors,
     IList<ChromSource> sources)
 {
     var chromExporter = new ChromatogramExporter(docResults);
     using (var saver = new FileSaver(fileToSave))
     using (var writer = new StreamWriter(saver.SafeName))
     {
         chromExporter.Export(writer, null, fileNames, cultureInfo, extractors, sources);
         writer.Flush();
         writer.Close();
         saver.Commit();
     }
 }