Ejemplo n.º 1
0
        public bool ImportResultsInDir(string sourceDir, Regex namingPattern, 
            LockMassParameters lockMassParameters,
            DateTime? importBefore, DateTime? importOnOrAfter,
            OptimizableRegression optimize, bool disableJoining)
        {
            var listNamedPaths = GetDataSources(sourceDir, namingPattern);
            if (listNamedPaths == null)
            {
                return false;
            }

            bool hasMultiple = listNamedPaths.SelectMany(pair => pair.Key).Count() > 1;
            if (hasMultiple || disableJoining)
            {
                // Join at the end
                _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(true));
            }

            // Import files one at a time
            foreach (var namedPaths in listNamedPaths)
            {
                string replicateName = namedPaths.Key;
                var files = namedPaths.Value;
                foreach (var file in files)
                {
                    if (!ImportResultsFile(file.ChangeParameters(_doc, lockMassParameters), replicateName, importBefore, importOnOrAfter, optimize))
                        return false;
                }
            }

            if (hasMultiple && !disableJoining)
            {
                // Allow joining to happen
                var progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(string.Empty));
                using (var docContainer = new ResultsMemoryDocumentContainer(null, _skylineFile) { ProgressMonitor = progressMonitor })
                {
                    _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(false));
                    if (!_doc.IsLoaded)
                    {
                        docContainer.SetDocument(_doc, null, true);
                        _doc = docContainer.Document;
                        // If not fully loaded now, there must have been an error.
                        if (!_doc.IsLoaded)
                            return false;
                    }
                }
            }

            return true;
        }
Ejemplo n.º 2
0
        public void Run(string[] args)
        {
            var commandArgs = new CommandArgs(_out, _doc != null);

            if(!commandArgs.ParseArgs(args))
            {
                _out.WriteLine(Resources.CommandLine_Run_Exiting___);
                return;
            }

            // First come the commands that do not depend on an --in command to run.
            // These commands modify Settings.Default instead of working with an open skyline document.
            if (commandArgs.InstallingToolsFromZip)
            {
                ImportToolsFromZip(commandArgs.ZippedToolsPath, commandArgs.ResolveZipToolConflictsBySkipping, commandArgs.ResolveZipToolAnotationConflictsBySkipping,
                                   commandArgs.ZippedToolsProgramPathContainer, commandArgs.ZippedToolsProgramPathValue, commandArgs.ZippedToolsPackagesHandled );
            }
            if (commandArgs.ImportingTool)
            {
                ImportTool(commandArgs.ToolName, commandArgs.ToolCommand, commandArgs.ToolArguments,
                    commandArgs.ToolInitialDirectory, commandArgs.ToolReportTitle, commandArgs.ToolOutputToImmediateWindow, commandArgs.ResolveToolConflictsBySkipping);
            }
            if (commandArgs.RunningBatchCommands)
            {
                RunBatchCommands(commandArgs.BatchCommandsPath);
            }
            if (commandArgs.ImportingSkyr)
            {
                ImportSkyr(commandArgs.SkyrPath, commandArgs.ResolveSkyrConflictsBySkipping);
            }
            if (!commandArgs.RequiresSkylineDocument)
            {
                // Exit quietly because Run(args[]) ran sucessfully. No work with a skyline document was called for.
                return;
            }

            string skylineFile = commandArgs.SkylineFile;
            if ((skylineFile != null && !OpenSkyFile(skylineFile)) ||
                (skylineFile == null && _doc == null))
            {
                _out.WriteLine(Resources.CommandLine_Run_Exiting___);
                return;
            }

            if (commandArgs.FullScanSetting)
            {
                if (!SetFullScanSettings(commandArgs))
                    return;
            }

            if (commandArgs.SettingLibraryPath)
            {
                if (!SetLibrary(commandArgs.LibraryName, commandArgs.LibraryPath))
                    _out.WriteLine(Resources.CommandLine_Run_Not_setting_library_);
            }

            if (commandArgs.ImportingFasta && !commandArgs.ImportingSearch)
            {
                try
                {
                    ImportFasta(commandArgs.FastaPath, commandArgs.KeepEmptyProteins);
                }
                catch (Exception x)
                {
                    _out.WriteLine(Resources.CommandLine_Run_Error__Failed_importing_the_file__0____1_, commandArgs.FastaPath, x.Message);
                    return;
                }
            }

            if (commandArgs.ImportingTransitionList)
            {
                try
                {
                    if (!ImportTransitionList(commandArgs))
                        return;
                }
                catch (Exception x)
                {
                    _out.WriteLine(Resources.CommandLine_Run_Error__Failed_importing_the_file__0____1_, commandArgs.TransitionListPath, x.Message);
                    return;
                }
            }

            if (commandArgs.ImportingSearch)
            {
                if (!ImportSearch(commandArgs))
                {
                    return;
                }
            }

            if (commandArgs.RemovingResults && !commandArgs.RemoveBeforeDate.HasValue)
            {
                RemoveResults(null);
            }

            if (commandArgs.ImportingResults)
            {
                OptimizableRegression optimize = null;
                try
                {
                    if (_doc != null)
                        optimize = _doc.Settings.TransitionSettings.Prediction.GetOptimizeFunction(commandArgs.ImportOptimizeType);
                }
                catch (Exception x)
                {
                    _out.WriteLine(Resources.CommandLine_Run_Error__Failed_to_get_optimization_function__0____1_, commandArgs.ImportOptimizeType, x.Message);
                }

                if (commandArgs.ImportingReplicateFile)
                {
                    // If expected results are not imported successfully, terminate
                    if (!ImportResultsFile(commandArgs.ReplicateFile.ChangeParameters(_doc, commandArgs.LockMassParameters),
                                           commandArgs.ReplicateName,
                                           commandArgs.ImportBeforeDate,
                                           commandArgs.ImportOnOrAfterDate,
                                           optimize,
                                           commandArgs.ImportAppend,
                                           commandArgs.ImportDisableJoining))
                        return;
                }
                else if(commandArgs.ImportingSourceDirectory)
                {
                    // If expected results are not imported successfully, terminate
                    if(!ImportResultsInDir(commandArgs.ImportSourceDirectory,
                                           commandArgs.ImportNamingPattern,
                                           commandArgs.LockMassParameters,
                                           commandArgs.ImportBeforeDate,
                                           commandArgs.ImportOnOrAfterDate,
                                           optimize,
                                           commandArgs.ImportDisableJoining))
                        return;
                }
            }

            if (_doc != null && !_doc.IsLoaded)
            {
                IProgressMonitor progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(string.Empty));
                using (var docContainer = new ResultsMemoryDocumentContainer(null, _skylineFile) { ProgressMonitor = progressMonitor })
                {
                    docContainer.SetDocument(_doc, null, true);
                    _doc = docContainer.Document;
                }
            }

            if (commandArgs.RemovingResults && commandArgs.RemoveBeforeDate.HasValue)
            {
                RemoveResults(commandArgs.RemoveBeforeDate);
            }

            if (commandArgs.Reintegrating)
            {
                if (!ReintegratePeaks(commandArgs))
                    return;
            }

            if (commandArgs.Saving)
            {
                var saveFile = commandArgs.SaveFile ?? _skylineFile;
                if (!SaveFile(saveFile))
                    return;

                _skylineFile = saveFile;
            }

            if (commandArgs.ExportingReport)
            {
                ExportReport(commandArgs.ReportName, commandArgs.ReportFile,
                    commandArgs.ReportColumnSeparator, commandArgs.IsReportInvariant);
            }

            if (commandArgs.ExportingChromatograms)
            {
                ExportChromatograms(commandArgs.ChromatogramsFile, commandArgs.ChromatogramsPrecursors, commandArgs.ChromatogramsProducts,
                    commandArgs.ChromatogramsBasePeaks, commandArgs.ChromatogramsTics);
            }

            if (!string.IsNullOrEmpty(commandArgs.TransListInstrumentType) &&
                !string.IsNullOrEmpty(commandArgs.MethodInstrumentType))
            {
                _out.WriteLine(Resources.CommandLine_Run_Error__You_cannot_simultaneously_export_a_transition_list_and_a_method___Neither_will_be_exported__);
            }
            else
            {
                if (commandArgs.ExportingTransitionList)
                {
                    ExportInstrumentFile(ExportFileType.List, commandArgs);
                }

                if (commandArgs.ExportingMethod)
                {
                    ExportInstrumentFile(ExportFileType.Method, commandArgs);
                }
            }

            if (Document != null && Document.Settings.HasResults)
            {
                Document.Settings.MeasuredResults.ReadStreams.ForEach(s => s.CloseStream());
            }
            if (commandArgs.SharingZipFile)
            {
                string sharedFileName;
                var sharedFileDir = Path.GetDirectoryName(_skylineFile) ?? string.Empty;
                if (!string.IsNullOrWhiteSpace(commandArgs.SharedFile))
                {
                    sharedFileName = Path.GetFileName(commandArgs.SharedFile.Trim());
                    if (!PathEx.HasExtension(sharedFileName, SrmDocumentSharing.EXT_SKY_ZIP))
                    {
                        sharedFileName = Path.GetFileNameWithoutExtension(sharedFileName) + SrmDocumentSharing.EXT_SKY_ZIP;
                    }
                    var dir = Path.GetDirectoryName(commandArgs.SharedFile);
                    sharedFileDir = string.IsNullOrEmpty(dir) ? sharedFileDir : dir;
                }
                else
                {
                    sharedFileName = FileEx.GetTimeStampedFileName(_skylineFile);
                }
                var sharedFilePath = Path.Combine(sharedFileDir, sharedFileName);
                ShareDocument(_doc, _skylineFile, sharedFilePath, _out);
            }
            if (commandArgs.PublishingToPanorama)
            {
                // Publish the document to the given Panorama server if new results were added to the document
                // OR no results files were given on the command-line for importing to the document.
                if (_importCount > 0 || !commandArgs.ImportingResults)
                {
                    // Publish document to the given folder on the Panorama Server
                    var panoramaHelper = new PanoramaPublishHelper(_out);
                    panoramaHelper.PublishToPanorama(commandArgs.PanoramaServer, _doc, _skylineFile,
                        commandArgs.PanoramaFolder);
                }
                else
                {
                    _out.WriteLine(Resources.CommandLine_Run_No_new_results_added__Skipping_Panorama_import_);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function will add the given replicate, from dataFile, to the given document. If the replicate
        /// does not exist, it will be added. If it does exist, it will be appended to.
        /// </summary>
        public static SrmDocument ImportResults(SrmDocument doc, string docPath, string replicate, MsDataFileUri dataFile,
            OptimizableRegression optimize, IProgressMonitor progressMonitor, out ProgressStatus status)
        {
            using (var docContainer = new ResultsMemoryDocumentContainer(null, docPath) {ProgressMonitor = progressMonitor})
            {
                // Make sure library loading happens, which may not happen, if the doc
                // parameter is used as the baseline document.
                docContainer.SetDocument(doc, null);

                SrmDocument docAdded;
                do
                {
                    doc = docContainer.Document;

                    var listChromatograms = new List<ChromatogramSet>();

                    if (doc.Settings.HasResults)
                        listChromatograms.AddRange(doc.Settings.MeasuredResults.Chromatograms);

                    int indexChrom = listChromatograms.IndexOf(chrom => chrom.Name.Equals(replicate));
                    if (indexChrom != -1)
                    {
                        var chromatogram = listChromatograms[indexChrom];
                        var paths = chromatogram.MSDataFilePaths;
                        var listFilePaths = paths.ToList();
                        listFilePaths.Add(dataFile);
                        listChromatograms[indexChrom] = chromatogram.ChangeMSDataFilePaths(listFilePaths);
                    }
                    else
                    {
                        listChromatograms.Add(new ChromatogramSet(replicate, new[] {dataFile.Normalize()},
                            Annotations.EMPTY, optimize));
                    }

                    var results = doc.Settings.HasResults
                                      ? doc.Settings.MeasuredResults.ChangeChromatograms(listChromatograms)
                                      : new MeasuredResults(listChromatograms, doc.Settings.IsResultsJoiningDisabled);

                    docAdded = doc.ChangeMeasuredResults(results);
                }
                while (!docContainer.SetDocument(docAdded, doc, true));

                status = docContainer.LastProgress;

                return docContainer.Document;
            }
        }