Skip to content

Commit

Permalink
0.1.0 release
Browse files Browse the repository at this point in the history
* Added support for poetry scripts
  • Loading branch information
clementpoiret committed Jul 12, 2021
1 parent da12564 commit a727206
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ It requires the following packages:

- ANTs (Can be a system installation or anaconda installation),
- ANTsPyX,
- importlib_resources,
- NiBabel,
- Pandas,
- Rich.

usage: roiloc.py [-h] -p PATH -i INPUTPATTERN [-r ROI] -c CONTRAST [-b BET] [-t TRANSFORM] [-m MARGIN [MARGIN ...]] [--mask MASK]
usage: roiloc [-h] -p PATH -i INPUTPATTERN [-r ROI] -c CONTRAST [-b BET] [-t TRANSFORM] [-m MARGIN [MARGIN ...]] [--mask MASK]

arguments::

Expand Down Expand Up @@ -57,7 +58,7 @@ Let's say I have a main database folder, containing one subfolder for each subje

Therefore, to extract both left and right hippocampi (``Hippocampus``), I can run:

``python roiloc.py -p "~/Datasets/MemoDev/ManualSegmentation/" -i "**/tse.nii.gz" -r "hippocampus" -c "t2" -b True -t "AffineFast" -m 8 8 2 --mask "*brain_mask.nii``
``roiloc -p "~/Datasets/MemoDev/ManualSegmentation/" -i "**/tse.nii.gz" -r "hippocampus" -c "t2" -b True -t "AffineFast" -m 8 8 2 --mask "*brain_mask.nii``


Supported Registrations
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
name = "ROILoc"
version = "0.1.0"
description = ""
license = "MIT"
readme = "README.rst"
authors = ["Clément POIRET <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.7"
antspyx = "^0.2.7"
nibabel = "^3.2.1"
pandas = "^1.3.0"
rich = "^10.5.0"
importlib-resources = "^5.2.0"

[tool.poetry.scripts]
roiloc = 'roiloc.roiloc:start'

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand Down
11 changes: 6 additions & 5 deletions roiloc.py → roiloc/roiloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path

import ants
import pandas as pd
import importlib_resources
from rich import print
from rich.console import Console
from rich.progress import track
Expand Down Expand Up @@ -39,9 +39,10 @@ def main(args):
)

mni = get_mni(args.contrast, args.bet)
atlas = ants.image_read(
"./roiloc/MNI/cerebra/mni_icbm152_CerebrA_tal_nlin_sym_09c.nii",
pixeltype="unsigned int")
res = importlib_resources.files("roiloc")
data = str(res / "MNI" / "cerebra" /
"mni_icbm152_CerebrA_tal_nlin_sym_09c.nii")
atlas = ants.image_read(data, pixeltype="unsigned int")

for image_path in track(images):
stem = image_path.stem.split(".")[0]
Expand Down Expand Up @@ -83,7 +84,7 @@ def main(args):
print("[bold green]Done! :)")


if __name__ == "__main__":
def start():
parser = argparse.ArgumentParser(
description=
"Locate the Hippocampus or any other CerebrA ROI by using MNI152 Template and CerebrA Atlas"
Expand Down
15 changes: 10 additions & 5 deletions roiloc/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ants
import importlib_resources
import pandas as pd
from ants.core.ants_image import ANTsImage

Expand All @@ -20,13 +21,17 @@ def get_mni(contrast: str, bet: bool) -> ANTsImage:

betstr = "bet" if bet else ""

return ants.image_read(
f"roiloc/MNI/icbm152/mni_icbm152_{contrast}{betstr}_tal_nlin_sym_09c.nii",
pixeltype="float")
template = f"mni_icbm152_{contrast}{betstr}_tal_nlin_sym_09c.nii"
res = importlib_resources.files("roiloc")
data = str(res / "MNI" / "icbm152" / template)
return ants.image_read(str(data), pixeltype="float")


def get_roi_indices(roi: str) -> list:
roi = roi.title()
cerebra = pd.read_csv("roiloc/MNI/cerebra/CerebrA_LabelDetails.csv",
index_col="Label Name")

res = importlib_resources.files("roiloc")
data = str(res / "MNI" / "cerebra" / "CerebrA_LabelDetails.csv")
cerebra = pd.read_csv(data, index_col="Label Name")

return [cerebra.loc[roi, "RH Label"], cerebra.loc[roi, "LH Labels"]]

0 comments on commit a727206

Please sign in to comment.