/// <summary> /// Run Monocle on the files indicated in the Processor /// </summary> public async void Run() { tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; await Task.Run(() => { token.ThrowIfCancellationRequested(); try { int filesCompleted = 0; foreach (string newFile in files.FileList) { CurrentProgress = CalculateProgress(1, filesCompleted, files.FileList.Count); TrackProcess(newFile, CurrentProgress, RunStatus.Started); token.ThrowIfCancellationRequested(); IScanReader reader = ScanReaderFactory.GetReader(newFile); reader.Open(newFile); ScanFileHeader header = reader.GetHeader(); header.FileName = Path.GetFileName(newFile); var Scans = new List <Monocle.Data.Scan>(); foreach (Scan scan in reader) { token.ThrowIfCancellationRequested(); Scans.Add(scan); } reader.Close(); CurrentProgress = CalculateProgress(2, filesCompleted, files.FileList.Count); TrackProcess(newFile, CurrentProgress, RunStatus.Read); token.ThrowIfCancellationRequested(); if (!ConvertOnly) { // Start Run across Scans Monocle.Monocle.Run(ref Scans, monocleOptions); CurrentProgress = CalculateProgress(3, filesCompleted, files.FileList.Count); TrackProcess(newFile, CurrentProgress, RunStatus.Processed); token.ThrowIfCancellationRequested(); } string outputFilePath = Path.Combine(Path.GetDirectoryName(newFile), Path.GetFileNameWithoutExtension(newFile) + "_monocle." + monocleOptions.OutputFileType.ToString()); ScanWriterFactory.MakeTargetFileName(newFile, monocleOptions.OutputFileType); IScanWriter writer = ScanWriterFactory.GetWriter(monocleOptions.OutputFileType); writer.Open(outputFilePath); writer.WriteHeader(header); foreach (Scan scan in Scans) { token.ThrowIfCancellationRequested(); writer.WriteScan(scan); } writer.Close(); CurrentProgress = CalculateProgress(4, filesCompleted, files.FileList.Count); TrackProcess(outputFilePath, CurrentProgress, RunStatus.Written); token.ThrowIfCancellationRequested(); // Clear data EmptyScans(Scans); filesCompleted++; CurrentProgress = CalculateProgress(4, filesCompleted, files.FileList.Count); TrackProcess(outputFilePath, CurrentProgress, RunStatus.Finished); } AllFilesFinished(true); } catch (Exception ex) { Debug.WriteLine("File processing failed: " + ex); } }); }
static void Main(string[] args) { var parser = new CliOptionsParser(); MakeMonoOptions options = parser.Parse(args); MonocleOptions monocleOptions = new MonocleOptions { AveragingVector = options.AveragingVector, Charge_Detection = options.ChargeDetection, Charge_Range = new ChargeRange(options.ChargeRange), MS_Level = options.MS_Level, Number_Of_Scans_To_Average = options.NumOfScans, WriteDebugString = options.WriteDebug, OutputFileType = options.OutputFileType, ConvertOnly = options.ConvertOnly, SkipMono = options.SkipMono, ChargeRangeUnknown = new ChargeRange(options.ChargeRangeUnknown), ForceCharges = options.ForceCharges, UseMostIntense = options.UseMostIntense }; SetupLogger(options.RunQuiet, options.WriteDebug); try { log.Info("Starting Processing."); string file = options.InputFilePath; IScanReader reader = ScanReaderFactory.GetReader(file); reader.Open(file); var header = reader.GetHeader(); header.FileName = Path.GetFileName(file); log.Info("Reading scans: " + file); List <Scan> Scans = new List <Scan>(); foreach (Scan scan in reader) { Scans.Add(scan); } if (!monocleOptions.ConvertOnly) { log.Info("Starting monoisotopic assignment."); Monocle.Monocle.Run(ref Scans, monocleOptions); } string outputFilePath = options.OutputFilePath.Trim(); if (outputFilePath.Length == 0) { outputFilePath = ScanWriterFactory.MakeTargetFileName(file, monocleOptions.OutputFileType); } log.Info("Writing output: " + outputFilePath); IScanWriter writer = ScanWriterFactory.GetWriter(monocleOptions.OutputFileType); writer.Open(outputFilePath); writer.WriteHeader(header); foreach (Scan scan in Scans) { writer.WriteScan(scan); } writer.Close(); log.Info("Done."); } catch (Exception e) { log.Error("An error occurred."); log.Debug(e.GetType().ToString()); log.Debug(e.Message); log.Debug(e.ToString()); } }