Skip to content

Commit

Permalink
Add a task to create annotation.json file
Browse files Browse the repository at this point in the history
Change-Id: If75445f3ad88586e279c3443f7cf3773ceaf10ba
  • Loading branch information
adrien-berchet committed Nov 25, 2020
1 parent 1d4d46e commit d983444
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/synthesis_workflow/tasks/synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/synthesis_workflow/tasks/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/synthesis_workflow/tasks/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Binary file modified tests/data/in_small_O1/out/validation/score_matrix_reports.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion tests/test_O1_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
)

0 comments on commit d983444

Please sign in to comment.