//wrapper should now handle all throwing and catching.. protected override void ProgramExecution() { var optionsUsed = _appOptionParser.ParsingResult.OptionsUsed; var doNotPassToSubprocess = new List <string>() { "outFolder", "numProcesses", "exePath", "intermediateDir", "multiprocess", "chromosomes" }; var cmdLineList = MultiProcessHelpers.GetCommandLineWithoutIgnoredArguments(optionsUsed, doNotPassToSubprocess); var refNameMapping = new Dictionary <string, int>(); using (var bamReader = new BamReader(_options.InputBam)) { var chroms = bamReader.GetReferenceNames(); foreach (var referenceName in chroms) { if (_options.Chromosomes != null && !_options.Chromosomes.ToList().Contains(referenceName)) { continue; } refNameMapping.Add(referenceName, bamReader.GetReferenceIndex(referenceName)); } } var taskManager = new CliTaskManager(_options.NumProcesses); var geminiProcessor = new GeminiMultiProcessor(_options, new CliTaskCreator()); var samtoolsWrapper = new SamtoolsWrapper(_options.GeminiOptions.SamtoolsPath, _options.GeminiOptions.IsWeirdSamtools); geminiProcessor.Execute(taskManager, refNameMapping, cmdLineList, samtoolsWrapper); }
private List <string> ExecuteChromosomeJobs(Dictionary <string, int> chromRefIds, string outMultiPath, List <string> taskDirectories) { var orderedChroms = MultiProcessHelpers.GetOrderedChromosomes(chromRefIds).ToList(); ConcurrentQueue <string> input = new ConcurrentQueue <string>(orderedChroms); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var tasks = new List <Task>(); var pathsArray = new string[chromRefIds.Max(x => x.Value) + 1]; using (var concurrencySemaphore = new SemaphoreSlim(_options.NumProcesses)) { foreach (var chrom in orderedChroms) { { var options = new GeminiMultiOptions() { StitcherOptions = (_options.StitcherOptions.DeepCopy()), GeminiSampleOptions = (_options.GeminiSampleOptions.DeepCopy()), IndelFilteringOptions = (_options.IndelFilteringOptions.DeepCopy()), RealignmentAssessmentOptions = (_options.RealignmentAssessmentOptions.DeepCopy()), RealignmentOptions = (_options.RealignmentOptions.DeepCopy()), GeminiOptions = (_options.GeminiOptions.DeepCopy()), InputBam = _options.InputBam, OutputDirectory = _options.OutputDirectory }; Console.WriteLine($"Waiting to launch job for chrom {chrom}"); Console.WriteLine($"Launching job for chrom {chrom}"); concurrencySemaphore.Wait(); tasks.Add(Task.Factory.StartNew(() => { try { pathsArray[chromRefIds[chrom]] = ProcessChromosome(chromRefIds, outMultiPath, taskDirectories, chrom, options); } finally { concurrencySemaphore.Release(); } })); } } Logger.WriteToLog("Launched all tasks."); Task.WaitAll(tasks.ToArray()); return(pathsArray.Where(x => x != null).ToList()); } }
private List <string> ExecuteChromosomeJobs(ICliTaskManager cliTaskManager, Dictionary <string, int> chromRefIds, List <string> cmdLineList, string outMultiPath, string taskLogDir, string exePath, List <string> taskDirectories) { var tasks = new List <ICliTask>(); var paths = new List <string>(); //var loggers = new List<Illumina.CG.Common.Logging.Logger>(); foreach (var chrom in MultiProcessHelpers.GetOrderedChromosomes(chromRefIds)) { var outdir = Path.Combine(outMultiPath, chrom); //var logger = new Illumina.CG.Common.Logging.Logger(taskLogDir, $"GeminiTaskLog_{chrom}.txt"); //loggers.Add(logger); var task = _taskCreator.GetCliTask(cmdLineList.ToArray(), chrom, exePath, outdir, chromRefIds[chrom]); tasks.Add(task); paths.Add(Path.Combine(outdir, "merged.bam.sorted.bam")); taskDirectories.Add(outdir); } cliTaskManager.Process(tasks); foreach (var task in tasks) { Logger.WriteToLog($"Completed task {task.Name} with exit code {task.ExitCode}."); } if (tasks.Any(x => x.ExitCode != 0)) { foreach (var failedTask in tasks.Where(x => x.ExitCode != 0)) { Logger.WriteWarningToLog($"Processing failed for {failedTask.Name}. See error log for details."); } throw new Exception($"Application failed: {tasks.Count(x => x.ExitCode != 0)} tasks failed."); } Logger.WriteToLog($"Completed {tasks.Count} tasks."); return(paths); //try //{ // foreach (var logger in loggers) // { // logger.Dispose(); // } //} //catch (Exception e) //{ // Logger.WriteExceptionToLog( // new Exception($"Error encountered during logging cleanup step (after individual analysis completion).", e)); //} }