From 110bd8df259793612538504403462947781ae8d1 Mon Sep 17 00:00:00 2001 From: Daniel Bolin Date: Wed, 8 Nov 2023 09:00:18 -0500 Subject: [PATCH] Skip further processing when annotation tool fails --- src/algorithm/report.py | 10 +++------- steps/check_annotation_report.cwl | 21 +++++++++++++++++++++ steps/js/options-util.js | 2 +- steps/run-one.cwl | 16 ++++++++++++++-- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 steps/check_annotation_report.cwl diff --git a/src/algorithm/report.py b/src/algorithm/report.py index 7a435f3..189bfef 100644 --- a/src/algorithm/report.py +++ b/src/algorithm/report.py @@ -9,7 +9,6 @@ from pathlib import Path import anndata -import pandas class Status(enum.Enum): @@ -49,13 +48,10 @@ def save_matrix(self): if isinstance(self.data, Path): self.data = anndata.read_h5ad(self.data) - obs = self.data.obs - if not self.is_success(): - # Create an empty observations frame with the same columns as the original - obs = pandas.DataFrame(columns=obs.columns) - obs['hra_prediction'] = obs[self.prediction_column] + if self.is_success(): + self.data.obs["hra_prediction"] = self.data.obs[self.prediction_column] - obs.to_csv(self.annotations) + self.data.obs.to_csv(self.annotations) self.data.write_h5ad(self.matrix) def save_report(self): diff --git a/steps/check_annotation_report.cwl b/steps/check_annotation_report.cwl new file mode 100644 index 0000000..f226ef6 --- /dev/null +++ b/steps/check_annotation_report.cwl @@ -0,0 +1,21 @@ +#!/usr/bin/env cwl-runner +class: ExpressionTool +cwlVersion: v1.2 + +requirements: + InlineJavascriptRequirement: {} + +inputs: + report: + type: File + loadContents: true + matrix: File + +outputs: + matrix_or_null: File? + +expression: | + ${ + var isSuccess = /success/g.test(inputs.report.contents); + return { matrix_or_null: isSuccess ? inputs.matrix : null }; + } diff --git a/steps/js/options-util.js b/steps/js/options-util.js index 25b40a8..76f1e1a 100644 --- a/steps/js/options-util.js +++ b/steps/js/options-util.js @@ -3,7 +3,7 @@ var ALGORITHMS = ["azimuth", "celltypist", "popv"]; function _find_algorithm(obj) { for (var index = 0; index < ALGORITHMS.length; ++index) { var name = ALGORITHMS[index]; - if (typeof obj[name] === "object") { + if (typeof obj[name] === "object" && obj[name] !== null) { return name; } } diff --git a/steps/run-one.cwl b/steps/run-one.cwl index 544a7ec..1eb1082 100644 --- a/steps/run-one.cwl +++ b/steps/run-one.cwl @@ -48,10 +48,18 @@ steps: algorithm: algorithm out: [annotations, annotated_matrix, report] + check_result: + run: ./check_annotation_report.cwl + in: + report: annotate/report + matrix: annotate/annotated_matrix + out: [matrix_or_null] + crosswalk: run: ../containers/crosswalking/pipeline.cwl + when: $(!!inputs.matrix) in: - matrix: annotate/annotated_matrix + matrix: check_result/matrix_or_null options: source: algorithm valueFrom: $(self.crosswalk || {}) @@ -59,6 +67,7 @@ steps: gene_expression: run: ../containers/gene-expression/pipeline.cwl + when: $(!!inputs.matrix) in: matrix: crosswalk/matrix_with_crosswalking options: @@ -68,6 +77,7 @@ steps: summarize: run: ../containers/extract-summary/pipeline.cwl + when: $(!!inputs.matrix) in: matrix: gene_expression/matrix_with_gene_expr options: @@ -78,7 +88,9 @@ steps: collect: run: ./collect-files.cwl in: - files: [summarize/summary, summarize/annotations, annotate/report] + files: + source: [summarize/summary, summarize/annotations, annotate/report] + pickValue: all_non_null outputDirectory: source: algorithm valueFrom: $(selectOutputDirectory(self))