Skip to content

Commit

Permalink
Fix azimuth bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
axdanbol committed Oct 24, 2023
1 parent 6bab687 commit dddb25e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions containers/azimuth/context/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import subprocess
from pathlib import Path
import typing as t
from pathlib import Path

import anndata
import pandas
Expand Down Expand Up @@ -72,19 +72,21 @@ def copy_annotations(

def run_azimuth_scripts(self, matrix_path: Path, reference_data: Path):
script_command = ["Rscript", "/run_azimuth.R", matrix_path, reference_data]
subprocess.run(script_command, capture_output=True, check=True)
subprocess.run(script_command, capture_output=True, check=True, text=True)
return "./result.h5ad"

def find_reference_data(self, organ: str, dir: Path):
def is_reference_data_candidate(path: Path):
return path.is_dir() and organ.lower() in path.name.lower()

return self._find_in_dir(
subdir = self._find_in_dir(
dir,
is_reference_data_candidate,
f"Cannot find reference data for organ '{organ}'",
f"Multiple reference data candidates for organ '{organ}'",
)
# idx.annoy and ref.Rds is always located inside an 'azimuth' subdirectory
return subdir / "azimuth"

def _find_in_dir(
self, dir: Path, cond: t.Callable[[Path], bool], error_msg: str, warn_msg: str
Expand Down
6 changes: 6 additions & 0 deletions src/algorithm/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io
import json
import pprint
import subprocess
import traceback
import typing as t
from pathlib import Path
Expand Down Expand Up @@ -67,6 +68,11 @@ def format_cause(self, result: dict):
if isinstance(cause, Exception):
result["cause"] = repr(cause)
result["traceback"] = traceback.format_tb(cause.__traceback__)
if isinstance(cause, subprocess.CalledProcessError):
# stdout and stderr does not show in the repr of a CalledProcessError
# Add them to the result here instead to give more context on errors
result["stdout"] = cause.stdout
result["stderr"] = cause.stderr
else:
stream = io.StringIO()
pprint.pprint(cause, stream=stream)
Expand Down

0 comments on commit dddb25e

Please sign in to comment.