Skip to content

Commit

Permalink
Add exit codes helper file (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
lazappi authored Jan 15, 2025
1 parent 83da5db commit 363df4d
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/methods/geneformer/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ resources:
- type: python_script
path: script.py
- path: /src/utils/read_anndata_partial.py
- path: /src/utils/exit_codes.py

engines:
- type: docker
Expand Down
5 changes: 3 additions & 2 deletions src/methods/geneformer/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
print(">>> Reading input...", flush=True)
sys.path.append(meta["resources_dir"])
from read_anndata_partial import read_anndata
from exit_codes import exit_non_applicable

adata = read_anndata(par["input"], X="layers/counts", obs="obs", var="var", uns="uns")

if adata.uns["dataset_organism"] != "homo_sapiens":
raise ValueError(
exit_non_applicable(
f"Geneformer can only be used with human data "
f"(dataset_organism == '{adata.uns['dataset_organism']}')"
f"(dataset_organism == \"{adata.uns['dataset_organism']}\")"
)

# Set adata.var_names to gene IDs
Expand Down
1 change: 1 addition & 0 deletions src/methods/scgpt/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ resources:
- type: python_script
path: script.py
- path: /src/utils/read_anndata_partial.py
- path: /src/utils/exit_codes.py

engines:
- type: docker
Expand Down
7 changes: 4 additions & 3 deletions src/methods/scgpt/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
meta = {"name": "scgpt"}
## VIASH END

print(f"====== scGPT version {scgpt.__version__} ======", flush=True)

sys.path.append(meta["resources_dir"])
from read_anndata_partial import read_anndata
from exit_codes import exit_non_applicable

print(f"====== scGPT version {scgpt.__version__} ======", flush=True)

print("\n>>> Reading input files...", flush=True)
print(f"Input H5AD file: '{par['input']}'", flush=True)
adata = read_anndata(par["input"], X="layers/counts", obs="obs", var="var", uns="uns")

if adata.uns["dataset_organism"] != "homo_sapiens":
raise ValueError(
exit_non_applicable(
f"scGPT can only be used with human data "
f"(dataset_organism == \"{adata.uns['dataset_organism']}\")"
)
Expand Down
1 change: 1 addition & 0 deletions src/methods/scimilarity/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ resources:
- type: python_script
path: script.py
- path: /src/utils/read_anndata_partial.py
- path: /src/utils/exit_codes.py
engines:
- type: docker
image: openproblems/base_pytorch_nvidia:1.0.0
Expand Down
3 changes: 2 additions & 1 deletion src/methods/scimilarity/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@

sys.path.append(meta["resources_dir"])
from read_anndata_partial import read_anndata
from exit_codes import exit_non_applicable

print("Read input", flush=True)
adata = read_anndata(par["input"], X="layers/counts", obs="obs", var="var", uns="uns")

if adata.uns["dataset_organism"] != "homo_sapiens":
raise ValueError(
exit_non_applicable(
f"SCimilarity can only be used with human data "
f"(dataset_organism == \"{adata.uns['dataset_organism']}\")"
)
Expand Down
1 change: 1 addition & 0 deletions src/methods/scprint/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ resources:
- type: python_script
path: script.py
- path: /src/utils/read_anndata_partial.py
- path: /src/utils/exit_codes.py

engines:
- type: docker
Expand Down
3 changes: 2 additions & 1 deletion src/methods/scprint/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

sys.path.append(meta["resources_dir"])
from read_anndata_partial import read_anndata
from exit_codes import exit_non_applicable

print(f"====== scPRINT version {scprint.__version__} ======", flush=True)

Expand All @@ -30,7 +31,7 @@
elif input.uns["dataset_organism"] == "mus_musculus":
input.obs["organism_ontology_term_id"] = "NCBITaxon:10090"
else:
raise ValueError(
exit_non_applicable(
f"scPRINT requires human or mouse data, not '{input.uns['dataset_organism']}'"
)
adata = input.copy()
Expand Down
1 change: 1 addition & 0 deletions src/methods/uce/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ resources:
- type: python_script
path: script.py
- path: /src/utils/read_anndata_partial.py
- path: /src/utils/exit_codes.py

engines:
- type: docker
Expand Down
3 changes: 2 additions & 1 deletion src/methods/uce/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
print(">>> Reading input...", flush=True)
sys.path.append(meta["resources_dir"])
from read_anndata_partial import read_anndata
from exit_codes import exit_non_applicable

adata = read_anndata(par["input"], X="layers/counts", obs="obs", var="var", uns="uns")

Expand All @@ -54,7 +55,7 @@
elif adata.uns["dataset_organism"] == "mus_musculus":
species = "mouse"
else:
raise ValueError(f"Species '{adata.uns['dataset_organism']}' not yet implemented")
exit_non_applicable(f"Species '{adata.uns['dataset_organism']}' not yet implemented")

print("\n>>> Creating working directory...", flush=True)
work_dir = tempfile.TemporaryDirectory()
Expand Down
6 changes: 6 additions & 0 deletions src/utils/exit_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys


def exit_non_applicable(msg):
print(f"NON-APPLICABLE ERROR: {msg}", flush=True)
sys.exit(99)

0 comments on commit 363df4d

Please sign in to comment.