Skip to content

Commit

Permalink
Merge pull request #69 from BlueBrain/brain-region-notation
Browse files Browse the repository at this point in the history
Brain region: use Allen notation in metadata string
  • Loading branch information
AurelienJaquier authored Oct 19, 2023
2 parents d442e38 + 635bdb9 commit ae6cf7b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion bluepyemodel/emodel_pipeline/emodel_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(
brain_region=None,
iteration_tag=None,
synapse_class=None,
allen_notation=None,
):
"""Constructor
Expand All @@ -46,6 +47,8 @@ def __init__(
brain_region (str): name of the brain location of the e-model.
iteration_tag (str): tag associated to the current run.
synapse_class (str): synapse class (neurotransmitter) of the e-model.
allen_notation (str): Allen acronym for the brain region (Optional).
Can be used to replace brain region in as_string().
"""

if emodel is None and etype is None:
Expand All @@ -59,6 +62,7 @@ def __init__(
self.brain_region = None if brain_region == "None" else brain_region
self.iteration = None if iteration_tag == "None" else iteration_tag
self.synapse_class = None if synapse_class == "None" else synapse_class
self.allen_notation = allen_notation

def etype_annotation_dict(self):
"""Returns an etype annotation dict to be added to annotations list."""
Expand Down Expand Up @@ -159,11 +163,13 @@ def for_resource(self):

return metadata

def as_string(self, seed=None):
def as_string(self, seed=None, use_allen_notation=True):
s = ""

for k in ["emodel", "etype", "ttype", "mtype", "species", "brain_region", "iteration"]:
v = getattr(self, k)
if use_allen_notation and k == "brain_region" and self.allen_notation:
v = self.allen_notation
if v:
if isinstance(v, int):
v = str(v)
Expand Down
2 changes: 1 addition & 1 deletion bluepyemodel/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def get_checkpoint_path(metadata, seed=None):
""""""

filename = metadata.as_string(seed=seed)
filename = metadata.as_string(seed=seed, use_allen_notation=False)

return f"./checkpoints/{metadata.emodel}/{metadata.iteration}/{filename}.pkl"

Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/test_emodelmetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ def test_as_string(metadata):
"species=mouse__brain_region=SSCX__iteration=v0__seed=42"
)

metadata.allen_notation = "SS"
assert metadata.as_string() == (
"emodel=L5_TPC:B_cAC__etype=cAC__ttype=245_L5 PT CTX__mtype=L5_TPC:B__"
"species=mouse__brain_region=SS__iteration=v0"
)

assert metadata.as_string(use_allen_notation=False) == (
"emodel=L5_TPC:B_cAC__etype=cAC__ttype=245_L5 PT CTX__mtype=L5_TPC:B__"
"species=mouse__brain_region=SSCX__iteration=v0"
)

# with None values and slashes
metadata = EModelMetadata(emodel="w/it/h_sla/she/s")
assert metadata.as_string(seed="None") == "emodel=with_slashes"

0 comments on commit ae6cf7b

Please sign in to comment.