Skip to content

Commit

Permalink
Add tests for registration
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherioszisis committed Jun 14, 2024
1 parent 8da2951 commit 96f0936
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 59 deletions.
60 changes: 41 additions & 19 deletions src/blue_cwl/registering.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
METypeDensity,
)
from entity_management.base import BrainLocation, Derivation, OntologyTerm
from entity_management.core import DataDownload, Subject
from entity_management.core import DataDownload, Entity, Subject
from entity_management.simulation import DetailedCircuit
from entity_management.util import get_entity

Expand Down Expand Up @@ -62,11 +62,12 @@ def register_partial_circuit(


def register_cell_composition_summary(
*,
name: str,
description: str,
distribution_file: StrOrPath,
atlas_release,
derivation_entity,
*,
atlas_release: AtlasRelease,
derivation_entity: Entity,
base=None,
org=None,
proj=None,
Expand All @@ -84,8 +85,8 @@ def register_cell_composition_summary(
derivation = Derivation(entity=derivation_entity)
summary = CellCompositionSummary(
name=name,
description=description,
about=["nsg:Neuron", "nsg:Glia"],
description="Statistical summary of the model cell composition.",
atlasRelease=atlas_release,
brainLocation=atlas_release.brainLocation,
distribution=distribution,
Expand All @@ -96,11 +97,12 @@ def register_cell_composition_summary(


def register_cell_composition_volume(
*,
name: str,
description: str,
distribution_file: StrOrPath,
atlas_release,
derivation_entity,
*,
atlas_release: AtlasRelease,
derivation_entity: Entity,
base=None,
org=None,
proj=None,
Expand All @@ -118,8 +120,8 @@ def register_cell_composition_volume(
derivation = Derivation(entity=derivation_entity)
volume = CellCompositionVolume(
name=name,
description=description,
about=["nsg:Neuron", "nsg:Glia"],
description="NRRD volume distribution of the cell composition.",
atlasRelease=atlas_release,
brainLocation=atlas_release.brainLocation,
distribution=distribution,
Expand All @@ -129,9 +131,18 @@ def register_cell_composition_volume(
return volume.publish(base=base, org=org, proj=proj, use_auth=token)


def register_densities(atlas_release, cell_composition_volume_file, output_file=None):
def register_densities(
*,
atlas_release: AtlasRelease,
distribution_file: StrOrPath,
output_file: StrOrPath | None = None,
base: str | None = None,
org: str | None = None,
proj: str | None = None,
token: str | None = None,
) -> dict:
"""Register METypeDensity volumes."""
volumes_dict = load_json(cell_composition_volume_file)
volumes_dict = load_json(distribution_file)

derivation = Derivation(entity=atlas_release)
subject = atlas_release.subject
Expand All @@ -147,6 +158,10 @@ def register_densities(atlas_release, cell_composition_volume_file, output_file=
brain_location=brain_location,
derivation=derivation,
subject=subject,
base=base,
org=org,
proj=proj,
token=token,
)

nrrd_data["@id"] = me_density.get_id()
Expand All @@ -161,14 +176,16 @@ def register_densities(atlas_release, cell_composition_volume_file, output_file=
if output_file is not None:
write_json(data=volumes_dict, filepath=output_file)

return volumes_dict


def _register_me_density(
distribution_file: StrOrPath,
atlas_release,
brain_location,
derivation,
subject,
*,
distribution_file: StrOrPath,
atlas_release: AtlasRelease,
brain_location: BrainLocation,
derivation: Derivation,
subject: Subject,
base=None,
org=None,
proj=None,
Expand All @@ -195,10 +212,12 @@ def _register_me_density(


def register_cell_composition(
atlas_release,
*,
name: str,
description: str,
atlas_release: AtlasRelease,
cell_composition_volume_file: StrOrPath,
cell_composition_summary_file: StrOrPath,
*,
base=None,
org=None,
proj=None,
Expand All @@ -207,6 +226,7 @@ def register_cell_composition(
"""Register CellComposition."""
summary = register_cell_composition_summary(
name="Cell Composition Summary",
description="Cell Composition Summary Distribution",
distribution_file=cell_composition_summary_file,
atlas_release=atlas_release,
derivation_entity=atlas_release,
Expand All @@ -217,6 +237,7 @@ def register_cell_composition(
)
volume = register_cell_composition_volume(
name="Cell Composition Volume",
description="Cell Composition Volume Distribution",
distribution_file=cell_composition_volume_file,
atlas_release=atlas_release,
derivation_entity=atlas_release,
Expand All @@ -226,7 +247,8 @@ def register_cell_composition(
token=token,
)
cell_composition = CellComposition(
name="Cell Composition",
name=name,
description=description,
about=["nsg:Neuron", "nsg:Glia"],
atlasRelease=atlas_release,
atlasSpatialReferenceSystem=atlas_release.spatialReferenceSystem,
Expand Down
4 changes: 3 additions & 1 deletion src/blue_cwl/wrappers/cell_composition_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,12 @@ def register(
)
registering.register_densities(
atlas_release=atlas_release,
cell_composition_volume_file=cell_composition_volume_file,
distribution_file=cell_composition_volume_file,
output_file=registered_cell_composition_volume_file,
)
cell_composition = registering.register_cell_composition(
name="Cell Composition",
description="Manipulated Cell Composition",
atlas_release=atlas_release,
cell_composition_volume_file=registered_cell_composition_volume_file,
cell_composition_summary_file=cell_composition_summary_file,
Expand Down
3 changes: 2 additions & 1 deletion src/blue_cwl/wrappers/cell_composition_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def from_density_distribution(

# pylint: disable=no-member
registering.register_cell_composition_summary(
name="Cell composition summary",
name="Cell Composition Summary",
description="Cell Composition Summary from density distribution",
distribution_file=composition_summary_file,
atlas_release=get_entity(atlas_release, cls=AtlasRelease),
derivation_entity=cell_composition_volume,
Expand Down
3 changes: 2 additions & 1 deletion src/blue_cwl/wrappers/neurons_cell_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def _register(
)
# pylint: disable=no-member
registering.register_cell_composition_summary(
name="Cell composition summary",
name="Cell Composition Summary",
description="Cell Composition Summary of Node Population",
distribution_file=generated_data["composition-summary-file"],
atlas_release=get_entity(generated_data["atlas-id"], cls=AtlasRelease),
derivation_entity=circuit_resource,
Expand Down
Loading

0 comments on commit 96f0936

Please sign in to comment.