Skip to content

Commit

Permalink
Restructuring code: metadata on top
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorpm committed Sep 6, 2024
1 parent 14b87e5 commit 31c5527
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 219 deletions.
46 changes: 28 additions & 18 deletions brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__version__ = "1"
__atlas__ = "allen_cord"

### Import
import json
import multiprocessing as mp
import time
Expand All @@ -14,8 +12,6 @@
from loguru import logger
from rich.progress import track

# import sys
# sys.path.append("./")
from brainglobe_atlasapi import utils
from brainglobe_atlasapi.atlas_generation.mesh_utils import (
Region,
Expand All @@ -26,9 +22,23 @@
from brainglobe_atlasapi.config import DEFAULT_WORKDIR

Check warning on line 22 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py#L22

Added line #L22 was not covered by tests
from brainglobe_atlasapi.structure_tree_util import get_structures_tree

### Settings
PARALLEL = True
TEST = False

### Metadata
__version__ = "1"

Check warning on line 30 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py#L30

Added line #L30 was not covered by tests

ATLAS_NAME = "allen_cord"
SPECIES = "Mus musculus"
ATLAS_LINK = "https://data.mendeley.com/datasets/4rrggzv5d5/1"
CITATION = "Fiederling et al. 2021, https://doi.org/10.1101/2021.05.06.443008"
ORIENTATION = "asr"
RESOLUTION = (20, 10, 10)
ROOT_ID = 250
ATLAS_FILE_URL = "https://prod-dcd-datasets-cache-zipfiles.s3.eu-west-1.amazonaws.com/4rrggzv5d5-1.zip"
ATLAS_PACKAGER = "MetaCell LLC, Ltd."

Check warning on line 40 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py#L32-L40

Added lines #L32 - L40 were not covered by tests


def download_atlas_files(download_dir_path: Path, atlas_file_url: str) -> Path:
utils.check_internet_connection()

Check warning on line 44 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py#L43-L44

Added lines #L43 - L44 were not covered by tests
Expand All @@ -41,7 +51,7 @@ def download_atlas_files(download_dir_path: Path, atlas_file_url: str) -> Path:
processor=pooch.Unzip(extract_dir="."),
)

atlas_files_dir = download_dir_path / "SC_P56_Atlas_1bg0x10x20_v5_2020"
atlas_files_dir = download_dir_path / "SC_P56_Atlas_10x10x20_v5_2020"

Check warning on line 54 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py#L54

Added line #L54 was not covered by tests

return atlas_files_dir

Expand Down Expand Up @@ -208,17 +218,17 @@ def create_mesh_dict(structures, meshes_dir_path):


def create_atlas(working_dir):
ATLAS_NAME = "allen_cord"
SPECIES = "Mus musculus"
ATLAS_LINK = "https://data.mendeley.com/datasets/4rrggzv5d5/1"
CITATION = (
"Fiederling et al. 2021, https://doi.org/10.1101/2021.05.06.443008"
)
ORIENTATION = "asr"
RESOLUTION = (20, 10, 10)
ROOT_ID = 250
ATLAS_FILE_URL = "https://prod-dcd-datasets-cache-zipfiles.s3.eu-west-1.amazonaws.com/4rrggzv5d5-1.zip"
ATLAS_PACKAGER = "MetaCell LLC, Ltd."
# ATLAS_NAME = "allen_cord"
# SPECIES = "Mus musculus"
# ATLAS_LINK = "https://data.mendeley.com/datasets/4rrggzv5d5/1"
# CITATION = (
# "Fiederling et al. 2021, https://doi.org/10.1101/2021.05.06.443008"
# )
# ORIENTATION = "asr"
# RESOLUTION = (20, 10, 10)
# ROOT_ID = 250
# ATLAS_FILE_URL = "https://prod-dcd-datasets-cache-zipfiles.s3.eu-west-1.amazonaws.com/4rrggzv5d5-1.zip"
# ATLAS_PACKAGER = "MetaCell LLC, Ltd."

download_dir_path = working_dir / "downloads"
download_dir_path.mkdir(exist_ok=True)
Expand Down Expand Up @@ -288,7 +298,7 @@ def create_atlas(working_dir):

if __name__ == "__main__":
# Generated atlas path:
bg_root_dir = DEFAULT_WORKDIR / __atlas__
bg_root_dir = DEFAULT_WORKDIR / ATLAS_NAME

Check warning on line 301 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_cord.py#L301

Added line #L301 was not covered by tests
bg_root_dir.mkdir(exist_ok=True, parents=True)

# generate atlas
Expand Down
24 changes: 12 additions & 12 deletions brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
__version__ = "2"
__atlas__ = "allen_mouse"


### Import
from allensdk.api.queries.ontologies_api import OntologiesApi
from allensdk.api.queries.reference_space_api import ReferenceSpaceApi
from allensdk.core.reference_space_cache import ReferenceSpaceCache
Expand All @@ -12,14 +9,18 @@
from brainglobe_atlasapi.atlas_generation.wrapup import wrapup_atlas_from_data
from brainglobe_atlasapi.config import DEFAULT_WORKDIR

Check warning on line 10 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py#L10

Added line #L10 was not covered by tests

### Metadata
__version__ = "2"

Check warning on line 13 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py#L13

Added line #L13 was not covered by tests

ATLAS_NAME = "allen_mouse"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007"
ORIENTATION = "asr"
RES_UM = 25

Check warning on line 20 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py#L15-L20

Added lines #L15 - L20 were not covered by tests


def create_atlas(working_dir, resolution):
# Specify information about the atlas:
ATLAS_NAME = "allen_mouse"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007"
ORIENTATION = "asr"

# Temporary folder for nrrd files download:
download_dir_path = working_dir / "downloading_path"
Expand Down Expand Up @@ -108,9 +109,8 @@ def create_atlas(working_dir, resolution):


if __name__ == "__main__":
RES_UM = 25
# Generated atlas path:
bg_root_dir = DEFAULT_WORKDIR / __atlas__
bg_root_dir = DEFAULT_WORKDIR / ATLAS_NAME

Check warning on line 113 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse.py#L113

Added line #L113 was not covered by tests
bg_root_dir.mkdir(exist_ok=True)

create_atlas(bg_root_dir, RES_UM)
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
__version__ = "0"
__atlas__ = "allen_mouse_bluebrain_barrels"


### Import
import json
import time

Expand All @@ -25,18 +22,21 @@
from brainglobe_atlasapi.config import DEFAULT_WORKDIR

Check warning on line 22 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py#L22

Added line #L22 was not covered by tests
from brainglobe_atlasapi.structure_tree_util import get_structures_tree

### Metadata
__version__ = "0"

Check warning on line 26 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py#L26

Added line #L26 was not covered by tests

ATLAS_NAME = "allen_mouse_bluebrain_barrels"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Bolaños-Puchet S., Teska A., et al. (2024). https://doi.org/10.1162/imag_a_00209"
ATLAS_PACKAGER = "Axel Bisi"
ORIENTATION = "asr"
ROOT_ID = 997
RES_UM = 25

Check warning on line 35 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py#L28-L35

Added lines #L28 - L35 were not covered by tests

def create_atlas(working_dir, resolution):
# Specify information about the atlas:
ATLAS_NAME = "allen_mouse_bluebrain_barrels"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Bolaños-Puchet S., Teska A., et al. (2024). https://doi.org/10.1162/imag_a_00209"
ATLAS_PACKAGER = "Axel Bisi"
ORIENTATION = "asr"

def create_atlas(working_dir, resolution):

Check warning on line 38 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py#L38

Added line #L38 was not covered by tests
# Parameters for mesh creation:
ROOT_ID = 997
CLOSING_N_ITERS = 2
DECIMATE_FRACTION = 0.3
SMOOTH = True
Expand Down Expand Up @@ -368,9 +368,8 @@ def recurse(sub_d):


if __name__ == "__main__":
RES_UM = 25
# Generated atlas path:
bg_root_dir = DEFAULT_WORKDIR / __atlas__
bg_root_dir = DEFAULT_WORKDIR / ATLAS_NAME

Check warning on line 372 in brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/allen_mouse_bluebrain_barrels.py#L372

Added line #L372 was not covered by tests
bg_root_dir.mkdir(exist_ok=True)

create_atlas(bg_root_dir, RES_UM)
34 changes: 17 additions & 17 deletions brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
@author: Kailyn Fields, [email protected]
"""

__version__ = "2"
__atlas__ = "azba_zfish"

### Import
import csv
import time

Expand All @@ -24,18 +22,22 @@
from brainglobe_atlasapi.config import DEFAULT_WORKDIR

Check warning on line 22 in brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py#L22

Added line #L22 was not covered by tests
from brainglobe_atlasapi.structure_tree_util import get_structures_tree

### Metadata
__version__ = "2"

Check warning on line 26 in brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py#L26

Added line #L26 was not covered by tests

ATLAS_NAME = "azba_zfish"
SPECIES = "Danio rerio"
ATLAS_LINK = "http://www.azba.wayne.edu"
CITATION = "Kenney et al. 2021, https://doi.org/10.7554/elife.69988"
ATLAS_FILE_URL = "http://www.azba.wayne.edu/2021-08-22_AZBA.tar.gz"
ORIENTATION = "las"
ROOT_ID = 9999
ATLAS_PACKAGER = "Kailyn Fields, [email protected]"
ADDITIONAL_METADATA = {}
RESOLUTION = 4

Check warning on line 37 in brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py#L28-L37

Added lines #L28 - L37 were not covered by tests


def create_atlas(working_dir, resolution):
# metadata
ATLAS_NAME = "azba_zfish"
SPECIES = "Danio rerio"
ATLAS_LINK = "http://www.azba.wayne.edu"
CITATION = "Kenney et al. 2021, https://doi.org/10.7554/elife.69988"
ATLAS_FILE_URL = "http://www.azba.wayne.edu/2021-08-22_AZBA.tar.gz"
ORIENTATION = "las"
ROOT_ID = 9999
ATLAS_PACKAGER = "Kailyn Fields, [email protected]"
ADDITIONAL_METADATA = {}

working_dir = working_dir

Check warning on line 42 in brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py#L42

Added line #L42 was not covered by tests
download_path = working_dir / "downloads"
Expand Down Expand Up @@ -203,8 +205,6 @@ def create_atlas(working_dir, resolution):


if __name__ == "__main__":
resolution = 4

# generated atlas path
bg_root_dir = DEFAULT_WORKDIR / __atlas__
create_atlas(bg_root_dir, resolution)
bg_root_dir = DEFAULT_WORKDIR / ATLAS_NAME
create_atlas(bg_root_dir, RESOLUTION)

Check warning on line 210 in brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/azba_zfish.py#L209-L210

Added lines #L209 - L210 were not covered by tests
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
__version__ = "0"
__atlas__ = "sju_cavefish"

### Import
import csv
import glob as glob
import time
from pathlib import Path

Expand All @@ -22,18 +21,20 @@
from brainglobe_atlasapi.config import DEFAULT_WORKDIR

Check warning on line 21 in brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py#L21

Added line #L21 was not covered by tests
from brainglobe_atlasapi.structure_tree_util import get_structures_tree

### Metadata
ATLAS_NAME = "sju_cavefish"
SPECIES = "Astyanax mexicanus"
ATLAS_LINK = "https://a-cavefishneuroevoluti.vev.site/lab-website"
CITATION = "Kozol et al. 2023, https://doi.org/10.7554/eLife.80777"
ATLAS_FILE_URL = "https://cdn.vev.design/private/30dLuULhwBhk45Fm8dHoSpD6uG12/35s9sm-asty-atlas.zip"
ORIENTATION = "sla"
ROOT_ID = 999
ATLAS_PACKAGER = "Robert Kozol, [email protected]"
ADDITIONAL_METADATA = {}
RESOLUTION = 2, 2, 2

Check warning on line 34 in brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py#L25-L34

Added lines #L25 - L34 were not covered by tests

def create_atlas(working_dir, resolution):
ATLAS_NAME = "sju_cavefish"
SPECIES = "Astyanax mexicanus"
ATLAS_LINK = "https://a-cavefishneuroevoluti.vev.site/lab-website"
CITATION = "Kozol et al. 2023, https://doi.org/10.7554/eLife.80777"
ATLAS_FILE_URL = "https://cdn.vev.design/private/30dLuULhwBhk45Fm8dHoSpD6uG12/35s9sm-asty-atlas.zip"
ORIENTATION = "sla"
ROOT_ID = 999
ATLAS_PACKAGER = "Robert Kozol, [email protected]"
ADDITIONAL_METADATA = {}

def create_atlas(working_dir, resolution):

Check warning on line 37 in brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py#L37

Added line #L37 was not covered by tests
# setup folder for downloading

download_dir_path = working_dir / "downloads"
Expand Down Expand Up @@ -208,9 +209,8 @@ def create_atlas(working_dir, resolution):


if __name__ == "__main__":
res = 2, 2, 2
home = str(Path.home())
bg_root_dir = DEFAULT_WORKDIR / __atlas__
bg_root_dir = DEFAULT_WORKDIR / ATLAS_NAME

Check warning on line 213 in brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py#L213

Added line #L213 was not covered by tests
bg_root_dir.mkdir(exist_ok=True, parents=True)

create_atlas(bg_root_dir, res)
create_atlas(bg_root_dir, RESOLUTION)

Check warning on line 216 in brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/cavefish_atlas.py#L216

Added line #L216 was not covered by tests
27 changes: 13 additions & 14 deletions brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
__version__ = "2"
__atlas__ = "example_mouse"


### Import
from allensdk.api.queries.ontologies_api import OntologiesApi
from allensdk.api.queries.reference_space_api import ReferenceSpaceApi
from allensdk.core.reference_space_cache import ReferenceSpaceCache
Expand All @@ -11,16 +10,16 @@
from brainglobe_atlasapi.atlas_generation.wrapup import wrapup_atlas_from_data
from brainglobe_atlasapi.config import DEFAULT_WORKDIR

Check warning on line 11 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L11

Added line #L11 was not covered by tests

### Metadata
RES_UM = 100 # 100
ATLAS_NAME = "example_mouse"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007"
ORIENTATION = "asr"

Check warning on line 19 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L14-L19

Added lines #L14 - L19 were not covered by tests

def create_atlas(working_dir, resolution):
# Specify information about the atlas:
RES_UM = resolution # 100
ATLAS_NAME = "example_mouse"
SPECIES = "Mus musculus"
ATLAS_LINK = "http://www.brain-map.org"
CITATION = "Wang et al 2020, https://doi.org/10.1016/j.cell.2020.04.007"
ORIENTATION = "asr"

def create_atlas(working_dir, resolution):

Check warning on line 22 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L22

Added line #L22 was not covered by tests
# Temporary folder for nrrd files download:
download_dir_path = working_dir / "downloading_path"
download_dir_path.mkdir(exist_ok=True)
Expand All @@ -30,7 +29,7 @@ def create_atlas(working_dir, resolution):
spacecache = ReferenceSpaceCache(
manifest=download_dir_path / "manifest.json",
# downloaded files are stored relative to here
resolution=RES_UM,
resolution=resolution,
reference_space_key="annotation/ccf_2017",
# use the latest version of the CCF
)
Expand Down Expand Up @@ -91,7 +90,7 @@ def create_atlas(working_dir, resolution):
citation=CITATION,
atlas_link=ATLAS_LINK,
species=SPECIES,
resolution=(RES_UM,) * 3,
resolution=(resolution,) * 3,
orientation=ORIENTATION,
root_id=997,
reference_stack=template_volume,
Expand All @@ -109,7 +108,7 @@ def create_atlas(working_dir, resolution):

if __name__ == "__main__":
# Generated atlas path:
bg_root_dir = DEFAULT_WORKDIR / __atlas__
bg_root_dir = DEFAULT_WORKDIR / ATLAS_NAME

Check warning on line 111 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L111

Added line #L111 was not covered by tests
bg_root_dir.mkdir(exist_ok=True)

# create_atlas(working_dir, 100)
create_atlas(bg_root_dir, RES_UM)

Check warning on line 114 in brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_atlasapi/atlas_generation/atlas_scripts/example_mouse.py#L114

Added line #L114 was not covered by tests
Loading

0 comments on commit 31c5527

Please sign in to comment.