Skip to content

Constant regions #233

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ import: ## Run the import on a database, assumes mba_hierarchy.json and out are
@test -n "$(VIRTUAL_LAB_ID_IMPORT)" || (echo "Please set the variable VIRTUAL_LAB_ID_IMPORT"; exit 1)
docker compose up --wait db
uv run -m alembic upgrade head
uv run -m app.cli.import_data --seed 1 hierarchy $(HIERARCHY_NAME) mba_hierarchy.json
uv run -m app.cli.import_data --seed 2 run ./out --virtual-lab-id $(VIRTUAL_LAB_ID_IMPORT) --project-id $(PROJECT_ID_IMPORT) --hierarchy-name $(HIERARCHY_NAME)
uv run -m app.cli.import_data --seed 2 hierarchy $(HIERARCHY_NAME) mba_hierarchy.json --cell-composition-file cell_composition.json
uv run -m app.cli.import_data --seed 3 run ./out --virtual-lab-id $(VIRTUAL_LAB_ID_IMPORT) --project-id $(PROJECT_ID_IMPORT) --hierarchy-name $(HIERARCHY_NAME)

curate-files: ## Create curated files and save them into the curated directory
@$(call load_env,run-local)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ https://openbraininstitute.sharepoint.com/:u:/s/OpenBrainInstitute/EZATMPEZvN5Cj
$ tar xzf out.tar.gz
```

- optionally, donwload the cell composition from:
```
https://staging.openbraininstitute.org/api/entitycore/cell-composition
```

- Import data into the specified database:

```
Expand Down
20 changes: 17 additions & 3 deletions app/cli/import_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# keep uuid used by core-web-app constant
DEFAULT_HIERARCHY_ID = uuid.UUID("e3e70682-c209-4cac-a29f-6fbed82c07cd")
DEFAULT_REGION_ID_FOR_BASIC_CELL_GROUPS_AND_REGIONS = uuid.UUID(
"4642cddb-4fbe-4aae-bbf7-0946d6ada066"
"fd9953d2-32a4-4a98-859b-64de31d0af99"
)
DEFAULT_BRAIN_ATLAS_ID = uuid.UUID("55de9d7b-9796-41f9-b719-213c3305ffd7")
DEFAULT_REGION_ID_FOR_ROOT = uuid.UUID("eb1167b3-67a9-4378-bc65-c1e582e2e662")
Expand All @@ -86,6 +86,7 @@
BRAIN_ATLAS_NAME = "BlueBrain Atlas"

REQUIRED_PATH = click.Path(exists=True, readable=True, dir_okay=False, resolve_path=True)
OPTIONAL_PATH = click.Path(exists=False, readable=True, dir_okay=False, resolve_path=True)
REQUIRED_PATH_DIR = click.Path(
exists=True, readable=True, file_okay=False, dir_okay=True, resolve_path=True
)
Expand Down Expand Up @@ -1922,7 +1923,12 @@ def run(input_dir, virtual_lab_id, project_id, hierarchy_name):
@cli.command()
@click.argument("hierarchy_name", type=str)
@click.argument("hierarchy_path", type=REQUIRED_PATH)
def hierarchy(hierarchy_name, hierarchy_path):
@click.option(
"--cell-composition-file",
type=OPTIONAL_PATH,
help="a composition json file to preserve brain region ids",
)
def hierarchy(hierarchy_name, hierarchy_path, cell_composition_file=None):
"""Load a hierarchy.json."""

with open(hierarchy_path) as fd:
Expand All @@ -1941,6 +1947,13 @@ def recurse(i):
regions.append(item)

recurse(hierarchy)
brain_region_mapping = {}
if cell_composition_file:
with open(cell_composition_file) as fd:
cell_composition = json.load(fd)
brain_region_mapping = {
v["name"]: uuid.UUID(k) for k, v in cell_composition["hasPart"].items()
}

with (
closing(configure_database_session_manager(**SQLA_ENGINE_ARGS)) as database_session_manager,
Expand Down Expand Up @@ -1982,7 +1995,8 @@ def recurse(i):
elif region["id"] == 8:
brain_region_id = DEFAULT_REGION_ID_FOR_BASIC_CELL_GROUPS_AND_REGIONS
else:
brain_region_id = uuid.uuid4()
brain_region_id = brain_region_mapping.get(region["name"], uuid.uuid4())

db_br = BrainRegion(
id=brain_region_id,
annotation_value=region["id"],
Expand Down