Skip to content

Commit 160bbcf

Browse files
committed
Initial implementation of brain-atlas endpoints
See #168 for the specification. Briefly; a `BrainAtlas` is an named entity that has an asset `annotation.nrrd` attached to it. It is associated with a particular `BrainRegionHierarchy` In addition, `BrainAtlasRegion` gives metadata for all the regions within a `BrainAtlas`; * their volume in the `annotation.nrrd` if they are a leaf, -1 otherwise. * an attached asset with the .obj mesh
1 parent 9061703 commit 160bbcf

19 files changed

+2107
-593
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import: ## Run the import on a database, assumes mba_hierarchy.json and out are
5353
@$(call load_env,run-local)
5454
@test -n "$(PROJECT_ID_IMPORT)" || (echo "Please set the variable PROJECT_ID_IMPORT"; exit 1)
5555
@test -n "$(VIRTUAL_LAB_ID_IMPORT)" || (echo "Please set the variable VIRTUAL_LAB_ID_IMPORT"; exit 1)
56-
docker compose up --wait db
56+
#docker compose up --wait db
5757
uv run -m alembic upgrade head
5858
uv run -m app.cli.import_data --seed 0 hierarchy $(HIERARCHY_NAME) mba_hierarchy.json
5959
uv run -m app.cli.import_data --seed 1 run ./out --virtual-lab-id $(VIRTUAL_LAB_ID_IMPORT) --project-id $(PROJECT_ID_IMPORT) --hierarchy-name $(HIERARCHY_NAME)
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
"""brainatlas
2+
3+
Revision ID: 4a2e856cf2db
4+
Revises: 7699329e803f
5+
Create Date: 2025-05-23 11:15:26.847117
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
import sqlalchemy as sa
13+
from alembic_postgresql_enum import TableReference
14+
from alembic_utils.pg_trigger import PGTrigger
15+
from sqlalchemy import text as sql_text
16+
from sqlalchemy.dialects import postgresql
17+
18+
from sqlalchemy import Text
19+
import app.db.types
20+
21+
# revision identifiers, used by Alembic.
22+
revision: str = "4a2e856cf2db"
23+
down_revision: Union[str, None] = "7699329e803f"
24+
branch_labels: Union[str, Sequence[str], None] = None
25+
depends_on: Union[str, Sequence[str], None] = None
26+
27+
28+
def upgrade() -> None:
29+
# ### commands auto generated by Alembic - please adjust! ###
30+
op.create_table(
31+
"brain_atlas_region",
32+
sa.Column("id", sa.Uuid(), nullable=False),
33+
sa.Column("volume", sa.Float(), nullable=True),
34+
sa.Column("leaf_region", sa.Boolean(), nullable=False),
35+
sa.Column("brain_atlas_id", sa.Uuid(), nullable=False),
36+
sa.Column("brain_region_id", sa.Uuid(), nullable=False),
37+
sa.ForeignKeyConstraint(
38+
["brain_atlas_id"],
39+
["brain_atlas.id"],
40+
name=op.f("fk_brain_atlas_region_brain_atlas_id_brain_atlas"),
41+
),
42+
sa.ForeignKeyConstraint(
43+
["brain_region_id"],
44+
["brain_region.id"],
45+
name=op.f("fk_brain_atlas_region_brain_region_id_brain_region"),
46+
),
47+
sa.ForeignKeyConstraint(
48+
["id"], ["entity.id"], name=op.f("fk_brain_atlas_region_id_entity")
49+
),
50+
sa.PrimaryKeyConstraint("id", name=op.f("pk_brain_atlas_region")),
51+
)
52+
op.create_index(
53+
op.f("ix_brain_atlas_region_brain_atlas_id"),
54+
"brain_atlas_region",
55+
["brain_atlas_id"],
56+
unique=False,
57+
)
58+
op.create_index(
59+
op.f("ix_brain_atlas_region_brain_region_id"),
60+
"brain_atlas_region",
61+
["brain_region_id"],
62+
unique=False,
63+
)
64+
op.drop_index("ix_mesh_brain_region_id", table_name="mesh")
65+
op.drop_index("ix_mesh_description_vector", table_name="mesh", postgresql_using="gin")
66+
op.drop_index("ix_mesh_name", table_name="mesh")
67+
op.drop_table("mesh")
68+
op.add_column("brain_atlas", sa.Column("hierarchy_id", sa.Uuid(), nullable=False))
69+
op.drop_index("ix_brain_atlas_brain_region_id", table_name="brain_atlas")
70+
op.create_index(
71+
op.f("ix_brain_atlas_hierarchy_id"), "brain_atlas", ["hierarchy_id"], unique=False
72+
)
73+
op.drop_constraint(
74+
"fk_brain_atlas_brain_region_id_brain_region", "brain_atlas", type_="foreignkey"
75+
)
76+
op.create_foreign_key(
77+
op.f("fk_brain_atlas_hierarchy_id_brain_region_hierarchy"),
78+
"brain_atlas",
79+
"brain_region_hierarchy",
80+
["hierarchy_id"],
81+
["id"],
82+
)
83+
op.drop_column("brain_atlas", "brain_region_id")
84+
op.sync_enum_values(
85+
enum_schema="public",
86+
enum_name="entitytype",
87+
new_values=[
88+
"analysis_software_source_code",
89+
"brain_atlas",
90+
"brain_atlas_region",
91+
"emodel",
92+
"cell_composition",
93+
"experimental_bouton_density",
94+
"experimental_neuron_density",
95+
"experimental_synapses_per_connection",
96+
"memodel",
97+
"mesh",
98+
"me_type_density",
99+
"reconstruction_morphology",
100+
"electrical_cell_recording",
101+
"electrical_recording_stimulus",
102+
"single_neuron_simulation",
103+
"single_neuron_synaptome",
104+
"single_neuron_synaptome_simulation",
105+
"ion_channel_model",
106+
"subject",
107+
"validation_result",
108+
],
109+
affected_columns=[
110+
TableReference(table_schema="public", table_name="entity", column_name="type")
111+
],
112+
enum_values_to_rename=[],
113+
)
114+
115+
# ### end Alembic commands ###
116+
117+
118+
def downgrade() -> None:
119+
# ### commands auto generated by Alembic - please adjust! ###
120+
public_mesh_mesh_description_vector = PGTrigger(
121+
schema="public",
122+
signature="mesh_description_vector",
123+
on_entity="public.mesh",
124+
is_constraint=False,
125+
definition="BEFORE INSERT OR UPDATE ON public.mesh FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('description_vector', 'pg_catalog.english', 'description', 'name')",
126+
)
127+
op.create_entity(public_mesh_mesh_description_vector)
128+
129+
op.sync_enum_values(
130+
enum_schema="public",
131+
enum_name="entitytype",
132+
new_values=[
133+
"analysis_software_source_code",
134+
"brain_atlas",
135+
"emodel",
136+
"cell_composition",
137+
"experimental_bouton_density",
138+
"experimental_neuron_density",
139+
"experimental_synapses_per_connection",
140+
"memodel",
141+
"mesh",
142+
"me_type_density",
143+
"reconstruction_morphology",
144+
"electrical_cell_recording",
145+
"electrical_recording_stimulus",
146+
"single_neuron_simulation",
147+
"single_neuron_synaptome",
148+
"single_neuron_synaptome_simulation",
149+
"ion_channel_model",
150+
"subject",
151+
"validation_result",
152+
],
153+
affected_columns=[
154+
TableReference(table_schema="public", table_name="entity", column_name="type")
155+
],
156+
enum_values_to_rename=[],
157+
)
158+
op.add_column(
159+
"brain_atlas", sa.Column("brain_region_id", sa.UUID(), autoincrement=False, nullable=False)
160+
)
161+
op.drop_constraint(
162+
op.f("fk_brain_atlas_hierarchy_id_brain_region_hierarchy"),
163+
"brain_atlas",
164+
type_="foreignkey",
165+
)
166+
op.create_foreign_key(
167+
"fk_brain_atlas_brain_region_id_brain_region",
168+
"brain_atlas",
169+
"brain_region",
170+
["brain_region_id"],
171+
["id"],
172+
)
173+
op.drop_index(op.f("ix_brain_atlas_hierarchy_id"), table_name="brain_atlas")
174+
op.create_index(
175+
"ix_brain_atlas_brain_region_id", "brain_atlas", ["brain_region_id"], unique=False
176+
)
177+
op.drop_column("brain_atlas", "hierarchy_id")
178+
op.create_table(
179+
"mesh",
180+
sa.Column("id", sa.UUID(), autoincrement=False, nullable=False),
181+
sa.Column("brain_region_id", sa.UUID(), autoincrement=False, nullable=False),
182+
sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=False),
183+
sa.Column("description", sa.VARCHAR(), autoincrement=False, nullable=False),
184+
sa.Column("description_vector", postgresql.TSVECTOR(), autoincrement=False, nullable=True),
185+
sa.ForeignKeyConstraint(
186+
["brain_region_id"], ["brain_region.id"], name="fk_mesh_brain_region_id_brain_region"
187+
),
188+
sa.ForeignKeyConstraint(["id"], ["entity.id"], name="fk_mesh_id_entity"),
189+
sa.PrimaryKeyConstraint("id", name="pk_mesh"),
190+
)
191+
op.create_index("ix_mesh_name", "mesh", ["name"], unique=False)
192+
op.create_index(
193+
"ix_mesh_description_vector",
194+
"mesh",
195+
["description_vector"],
196+
unique=False,
197+
postgresql_using="gin",
198+
)
199+
op.create_index("ix_mesh_brain_region_id", "mesh", ["brain_region_id"], unique=False)
200+
op.drop_index(op.f("ix_brain_atlas_region_brain_region_id"), table_name="brain_atlas_region")
201+
op.drop_index(op.f("ix_brain_atlas_region_brain_atlas_id"), table_name="brain_atlas_region")
202+
op.drop_table("brain_atlas_region")
203+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)