Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate atlasRelease version along with id #17

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/blue_cwl/registering.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from entity_management.base import BrainLocation, Derivation, OntologyTerm
from entity_management.core import DataDownload, Entity, Subject
from entity_management.simulation import DetailedCircuit
from entity_management.util import get_entity

from blue_cwl.typing import StrOrPath
from blue_cwl.utils import load_json, write_json
Expand All @@ -39,16 +38,19 @@ def _brain_location(brain_region_id: str) -> BrainLocation:


def register_partial_circuit(
*,
name: str,
brain_region_id: str,
atlas_release_id: str,
atlas_release: AtlasRelease,
sonata_config_path: StrOrPath,
description: str = "",
species_id: str | None = None,
base: str | None = None,
org: str | None = None,
proj: str | None = None,
token: str | None = None,
) -> DetailedCircuit:
"""Register a partial circuit."""
atlas_release = get_entity(resource_id=atlas_release_id, cls=AtlasRelease)

circuit_config_path = DataDownload(url=f"file://{Path(sonata_config_path).resolve()}")

return DetailedCircuit(
Expand All @@ -58,7 +60,7 @@ def register_partial_circuit(
brainLocation=_brain_location(brain_region_id),
atlasRelease=atlas_release,
circuitConfigPath=circuit_config_path,
).publish()
).publish(include_rev=True, base=base, org=org, proj=proj, use_auth=token)


def register_cell_composition_summary(
Expand Down
2 changes: 1 addition & 1 deletion src/blue_cwl/wrappers/connectome_filtering_synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def register(
partial_circuit = registering.register_partial_circuit(
name="Partial circuit with functional connectivity",
brain_region_id=utils.get_partial_circuit_region_id(partial_circuit),
atlas_release_id=partial_circuit.atlasRelease.get_id(),
atlas_release=partial_circuit.atlasRelease,
description="Circuit with nodes and functionalized synapses.",
sonata_config_path=output_config_file,
)
Expand Down
2 changes: 1 addition & 1 deletion src/blue_cwl/wrappers/connectome_generation_placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def register(*, circuit_id: str, edges_file: StrOrPath, output_dir: StrOrPath):
output_circuit = registering.register_partial_circuit(
name="Partial circuit with connectivity",
brain_region_id=utils.get_partial_circuit_region_id(input_circuit),
atlas_release_id=input_circuit.atlasRelease.get_id(),
atlas_release=input_circuit.atlasRelease,
description="Partial circuit with cell properties, emodels, morphologies and connectivity.",
sonata_config_path=sonata_config_file,
)
Expand Down
2 changes: 1 addition & 1 deletion src/blue_cwl/wrappers/memodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _register_circuit(partial_circuit, output_circuit_config_file):
circuit = registering.register_partial_circuit(
name="Partial circuit with biohysical emodel properties",
brain_region_id=get_partial_circuit_region_id(partial_circuit),
atlas_release_id=partial_circuit.atlasRelease.get_id(),
atlas_release=partial_circuit.atlasRelease,
description="Partial circuit with cell properties, morphologies, and biophysical models.",
sonata_config_path=output_circuit_config_file,
)
Expand Down
2 changes: 1 addition & 1 deletion src/blue_cwl/wrappers/mmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def register(
output_circuit = registering.register_partial_circuit(
name="Partial circuit with morphologies",
brain_region_id=get_partial_circuit_region_id(input_circuit),
atlas_release_id=input_circuit.atlasRelease.get_id(),
atlas_release=input_circuit.atlasRelease,
description="Partial circuit built with cell properties, and morphologies.",
sonata_config_path=sonata_config_file,
)
Expand Down
24 changes: 19 additions & 5 deletions src/blue_cwl/wrappers/neurons_cell_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
from voxcell.nexus.voxelbrain import Atlas

from blue_cwl import Variant, nexus, recipes, registering, staging, utils, validation
from blue_cwl.statistics import mtype_etype_url_mapping, node_population_composition_summary
from blue_cwl.statistics import (
mtype_etype_url_mapping,
node_population_composition_summary,
)
from blue_cwl.typing import StrOrPath

SEED = 42
Expand Down Expand Up @@ -106,8 +109,12 @@ def _extract(
output_file=me_type_densities_file,
)

atlas_release = cell_composition.atlasRelease

full_atlas_id = utils.url_with_revision(url=atlas_release.get_id(), rev=atlas_release.get_rev())

return {
"atlas-id": cell_composition.atlasRelease.get_id(),
"atlas-id": full_atlas_id,
"region": region,
"atlas-dir": atlas_dir,
"me-type-densities-file": me_type_densities_file,
Expand Down Expand Up @@ -315,7 +322,12 @@ def _generate_circuit_config(


def _generate_cell_composition_summary(
nodes_file, node_population_name, atlas_dir, mtype_urls, etype_urls, output_file: Path
nodes_file,
node_population_name,
atlas_dir,
mtype_urls,
etype_urls,
output_file: Path,
):
atlas = Atlas.open(str(atlas_dir))
population = libsonata.NodeStorage(nodes_file).open_population(node_population_name)
Expand All @@ -332,10 +344,12 @@ def _register(
output_dir,
):
"""Register outputs to nexus."""
atlas_release = get_entity(generated_data["atlas-id"], cls=AtlasRelease)

circuit_resource = registering.register_partial_circuit(
name="Cell properties partial circuit",
brain_region_id=region_id,
atlas_release_id=generated_data["atlas-id"],
atlas_release=atlas_release,
description="Partial circuit built with cell positions and me properties.",
sonata_config_path=generated_data["partial-circuit"],
)
Expand All @@ -350,6 +364,6 @@ def _register(
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),
atlas_release=atlas_release,
derivation_entity=circuit_resource,
)
47 changes: 36 additions & 11 deletions tests/unit/test_registering.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ def atlas_release():
"@type": "AtlasRelease",
"label": "my-atlas",
"name": "foo",
"brainTemplateDataLayer": {"@id": "template-id", "@type": "braintemplatedatalayer"},
"brainTemplateDataLayer": {
"@id": "template-id",
"@type": "braintemplatedatalayer",
},
"parcellationOntology": {"@id": "ontology-id", "@type": "parcellationontology"},
"parcellationVolume": {"@id": "volume-id", "@type": "parcellationvolume"},
"subject": {"@type": "subject"},
"spatialReferenceSystem": {"@id": "ref-id", "@type": "spatialreferencesystem", "_rev": 1},
"spatialReferenceSystem": {
"@id": "ref-id",
"@type": "spatialreferencesystem",
"_rev": 1,
},
"brainLocation": {"brainRegion": {"@id": "mba:997", "label": "root"}},
}

Expand All @@ -51,7 +58,9 @@ def test_brain_location(monkeypatch):
mock_region.get_id.return_value = "foo"
mock_region.label = "bar"

monkeypatch.setattr(AtlasBrainRegion, "from_id", lambda *args, **kwargs: mock_region)
monkeypatch.setattr(
AtlasBrainRegion, "from_id", lambda *args, **kwargs: mock_region
)

payload = {
"@id": "foo",
Expand All @@ -70,7 +79,7 @@ def test_brain_location(monkeypatch):
assert res.brainRegion.label == "bar"


def test_register_partial_circuit():
def test_register_partial_circuit(atlas_release):
def load_by_url(url, *args, **kwargs):
if "brain-region-id" in url:
return {
Expand All @@ -87,11 +96,23 @@ def load_by_url(url, *args, **kwargs):
"@type": "AtlasRelease",
"label": "my-atlas",
"name": "foo",
"brainTemplateDataLayer": {"@id": "template-id", "@type": "braintemplatedatalayer"},
"parcellationOntology": {"@id": "ontology-id", "@type": "parcellationontology"},
"parcellationVolume": {"@id": "volume-id", "@type": "parcellationvolume"},
"brainTemplateDataLayer": {
"@id": "template-id",
"@type": "braintemplatedatalayer",
},
"parcellationOntology": {
"@id": "ontology-id",
"@type": "parcellationontology",
},
"parcellationVolume": {
"@id": "volume-id",
"@type": "parcellationvolume",
},
"subject": {"@type": "subject"},
"spatialReferenceSystem": {"@id": "ref-id", "@type": "spatialreferencesystem"},
"spatialReferenceSystem": {
"@id": "ref-id",
"@type": "spatialreferencesystem",
},
}
raise

Expand All @@ -105,7 +126,7 @@ def create(base_url, payload, *args, **kwargs):
res = test_module.register_partial_circuit(
name="my-circuit",
brain_region_id="brain-region-id",
atlas_release_id="atlas-release-id",
atlas_release=atlas_release,
sonata_config_path="my-sonata-path",
description="my-description",
)
Expand Down Expand Up @@ -403,13 +424,17 @@ def upload_file(name, data, *args, **kwargs):
"@id": "http://bbp.epfl.ch/neurosciencegraph/ontologies/etypes/Foo",
"label": "Foo",
"about": ["https://neuroshapes.org/EType"],
"hasPart": [{"@type": "METypeDensity", "@id": "foo-id", "_rev": 2}],
"hasPart": [
{"@type": "METypeDensity", "@id": "foo-id", "_rev": 2}
],
},
{
"@id": "http://bbp.epfl.ch/neurosciencegraph/ontologies/etypes/Bar",
"label": "Bar",
"about": ["https://neuroshapes.org/EType"],
"hasPart": [{"@id": "bar-id", "_rev": 1, "@type": "METypeDensity"}],
"hasPart": [
{"@id": "bar-id", "_rev": 1, "@type": "METypeDensity"}
],
},
],
}
Expand Down
Loading