Skip to content

Commit

Permalink
Write predictions to common column across algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
axdanbol committed Nov 6, 2023
1 parent b545052 commit d30bc0b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion containers/azimuth/context/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_builtin_options(self):

class AzimuthAlgorithm(Algorithm[str, AzimuthOptions]):
def __init__(self):
super().__init__(AzimuthOrganLookup)
super().__init__(AzimuthOrganLookup, "azimuth_label")

def do_run(self, matrix: Path, organ: str, options: AzimuthOptions):
data = anndata.read_h5ad(matrix)
Expand Down
2 changes: 1 addition & 1 deletion containers/celltypist/context/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def from_raw(self, id: str):

class CelltypistAlgorithm(Algorithm[celltypist.Model, CelltypistOptions]):
def __init__(self):
super().__init__(CelltypistOrganLookup)
super().__init__(CelltypistOrganLookup, "predicted_labels")

def do_run(self, matrix: Path, organ: celltypist.Model, options: CelltypistOptions):
data = scanpy.read_h5ad(matrix)
Expand Down
2 changes: 1 addition & 1 deletion containers/popv/context/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PopvOptions(t.TypedDict):

class PopvAlgorithm(Algorithm[str, PopvOptions]):
def __init__(self):
super().__init__(OrganLookup)
super().__init__(OrganLookup, "popv_prediction")

def do_run(self, matrix: Path, organ: str, options: PopvOptions):
data = scanpy.read_h5ad(matrix)
Expand Down
13 changes: 11 additions & 2 deletions src/algorithm/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@


class Algorithm(t.Generic[Organ, Options], abc.ABC):
def __init__(self, organ_lookup: t.Callable[[Path], OrganLookup[Organ]]):
def __init__(
self,
organ_lookup: t.Callable[[Path], OrganLookup[Organ]],
prediction_column: str,
):
self.organ_lookup = organ_lookup
self.prediction_column = prediction_column

def run(
self,
Expand All @@ -26,7 +31,11 @@ def run(
**options,
) -> AlgorithmReport:
report = AlgorithmReport(
output_matrix, output_annotations, output_report, matrix
output_matrix,
output_annotations,
output_report,
matrix,
self.prediction_column,
)
try:
lookup = self.organ_lookup(organ_mapping)
Expand Down
2 changes: 2 additions & 0 deletions src/algorithm/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AlgorithmReport:
annotations: Path
report: Path
data: t.Union[Path, anndata.AnnData]
prediction_column: str
status = Status.SUCCESS
failure_cause: t.Any = None

Expand Down Expand Up @@ -53,6 +54,7 @@ def save_matrix(self):
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]
obs.to_csv(self.annotations)

def save_report(self):
Expand Down

0 comments on commit d30bc0b

Please sign in to comment.