diff --git a/src/synthesis_workflow/tasks/synthesis.py b/src/synthesis_workflow/tasks/synthesis.py index 2a4e288..6023d35 100644 --- a/src/synthesis_workflow/tasks/synthesis.py +++ b/src/synthesis_workflow/tasks/synthesis.py @@ -34,6 +34,7 @@ from synthesis_workflow.tasks.luigi_tools import ParamLink from synthesis_workflow.tasks.luigi_tools import RatioParameter from synthesis_workflow.tasks.luigi_tools import WorkflowTask +from synthesis_workflow.tasks.utils import CreateAnnotationsFile from synthesis_workflow.tasks.utils import GetSynthesisInputs from synthesis_workflow.tools import ensure_dir from synthesis_workflow.tools import find_case_insensitive_file @@ -323,19 +324,30 @@ def requires(self): def run(self): """""" - ensure_dir(self.output().path) if self.annotations_path is None: + annotations_file = None neurondb_path = None atlas_path = None axon_cells = self.input()["axon_cells"].path else: + if Path(self.annotations_path).is_dir(): + annotations_file = SynthesisLocalTarget("annotations.json").ppath + yield CreateAnnotationsFile( + annotation_dir=self.annotations_path, + destination=annotations_file, + ) + else: + annotations_file = ( + Path(PathConfig().local_synthesis_input_path) + / self.annotations_path + ) axon_cells = None neurondb_path = find_case_insensitive_file(self.get_neuron_db_path("dat")) if any( [ - self.annotations_path is None, + annotations_file is None, self.placement_rules_path is None, neurondb_path is None, axon_cells is not None, @@ -349,7 +361,7 @@ def run(self): self.input()["circuit"].path, morphs_df_path=axon_cells, atlas_path=atlas_path, - annotations_path=self.annotations_path, + annotations_path=annotations_file, rules_path=self.placement_rules_path, morphdb_path=neurondb_path, alpha=self.placement_alpha, diff --git a/src/synthesis_workflow/tasks/utils.py b/src/synthesis_workflow/tasks/utils.py index 44d77e1..7968a7c 100644 --- a/src/synthesis_workflow/tasks/utils.py +++ b/src/synthesis_workflow/tasks/utils.py @@ -1,10 +1,12 @@ """Utils luigi tasks.""" +import json import shutil from pathlib import Path from tempfile import TemporaryDirectory import luigi from git import Repo +from placement_algorithm.app.compact_annotations import _collect_annotations from synthesis_workflow.tasks.config import PathConfig from synthesis_workflow.tasks.luigi_tools import OutputLocalTarget @@ -75,3 +77,25 @@ def output(self): """""" # TODO: it would probably be better to have a specific target for each file return OutputLocalTarget(PathConfig().local_synthesis_input_path) + + +class CreateAnnotationsFile(WorkflowTask): + """Task to compact annotations into a single JSON file.""" + + annotation_dir = luigi.Parameter(description=(":str: Path to annotations folder.")) + morph_db = luigi.OptionalParameter( + default=None, description=":str: Path to MorphDB file." + ) + destination = luigi.Parameter(description=":str: Path to output JSON file.") + + def run(self): + """""" + # pylint: disable=protected-access + annotations = _collect_annotations(self.annotation_dir, self.morph_db) + + with open(self.destination, "w") as f: + json.dump(annotations, f, indent=4, sort_keys=True) + + def output(self): + """""" + return OutputLocalTarget(self.destination) diff --git a/src/synthesis_workflow/tasks/workflows.py b/src/synthesis_workflow/tasks/workflows.py index f191671..1911f2b 100644 --- a/src/synthesis_workflow/tasks/workflows.py +++ b/src/synthesis_workflow/tasks/workflows.py @@ -63,7 +63,7 @@ def requires(self): if self.with_morphology_validation_reports: tasks.append(MorphologyValidationReports()) if self.with_score_matrix_reports: - tasks.append(PlotScoreMatrix()) + tasks.append(PlotScoreMatrix(in_atlas=True)) return tasks diff --git a/tests/data/in_small_O1/out/validation/score_matrix_reports.pdf b/tests/data/in_small_O1/out/validation/score_matrix_reports.pdf index ea07be1..5089b37 100644 Binary files a/tests/data/in_small_O1/out/validation/score_matrix_reports.pdf and b/tests/data/in_small_O1/out/validation/score_matrix_reports.pdf differ diff --git a/tests/test_O1_workflow.py b/tests/test_O1_workflow.py index 3475a02..1af1893 100644 --- a/tests/test_O1_workflow.py +++ b/tests/test_O1_workflow.py @@ -36,6 +36,5 @@ def test_ValidateSynthesis(small_O1_working_directory): "validation/morphology_validation_reports/validation_results.json": { "kwargs": {"precision": 1} # weird precision issue in CI }, - "validation/score_matrix_reports.pdf": {"kwargs": {"threshold": 64.5}}, }, )