Skip to content

Commit

Permalink
Skip further processing when annotation tool fails
Browse files Browse the repository at this point in the history
  • Loading branch information
axdanbol committed Nov 8, 2023
1 parent c9fe0ce commit 110bd8d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/algorithm/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pathlib import Path

import anndata
import pandas


class Status(enum.Enum):
Expand Down Expand Up @@ -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):
Expand Down
21 changes: 21 additions & 0 deletions steps/check_annotation_report.cwl
Original file line number Diff line number Diff line change
@@ -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 };
}
2 changes: 1 addition & 1 deletion steps/js/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
16 changes: 14 additions & 2 deletions steps/run-one.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,26 @@ 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 || {})
out: [matrix_with_crosswalking]

gene_expression:
run: ../containers/gene-expression/pipeline.cwl
when: $(!!inputs.matrix)
in:
matrix: crosswalk/matrix_with_crosswalking
options:
Expand All @@ -68,6 +77,7 @@ steps:

summarize:
run: ../containers/extract-summary/pipeline.cwl
when: $(!!inputs.matrix)
in:
matrix: gene_expression/matrix_with_gene_expr
options:
Expand All @@ -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))
Expand Down

0 comments on commit 110bd8d

Please sign in to comment.