Skip to content

Commit a727206

Browse files
author
Clément POIRET
committed
0.1.0 release
* Added support for poetry scripts
1 parent da12564 commit a727206

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ It requires the following packages:
1515

1616
- ANTs (Can be a system installation or anaconda installation),
1717
- ANTsPyX,
18+
- importlib_resources,
1819
- NiBabel,
1920
- Pandas,
2021
- Rich.
2122

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

2425
arguments::
2526

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

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

60-
``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``
61+
``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``
6162

6263

6364
Supported Registrations

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
name = "ROILoc"
33
version = "0.1.0"
44
description = ""
5+
license = "MIT"
6+
readme = "README.rst"
57
authors = ["Clément POIRET <[email protected]>"]
68

79
[tool.poetry.dependencies]
8-
python = "^3.9"
10+
python = "^3.7"
911
antspyx = "^0.2.7"
1012
nibabel = "^3.2.1"
1113
pandas = "^1.3.0"
1214
rich = "^10.5.0"
15+
importlib-resources = "^5.2.0"
16+
17+
[tool.poetry.scripts]
18+
roiloc = 'roiloc.roiloc:start'
1319

1420
[tool.poetry.dev-dependencies]
1521
pytest = "^5.2"

roiloc.py renamed to roiloc/roiloc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88

99
import ants
10-
import pandas as pd
10+
import importlib_resources
1111
from rich import print
1212
from rich.console import Console
1313
from rich.progress import track
@@ -39,9 +39,10 @@ def main(args):
3939
)
4040

4141
mni = get_mni(args.contrast, args.bet)
42-
atlas = ants.image_read(
43-
"./roiloc/MNI/cerebra/mni_icbm152_CerebrA_tal_nlin_sym_09c.nii",
44-
pixeltype="unsigned int")
42+
res = importlib_resources.files("roiloc")
43+
data = str(res / "MNI" / "cerebra" /
44+
"mni_icbm152_CerebrA_tal_nlin_sym_09c.nii")
45+
atlas = ants.image_read(data, pixeltype="unsigned int")
4546

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

8586

86-
if __name__ == "__main__":
87+
def start():
8788
parser = argparse.ArgumentParser(
8889
description=
8990
"Locate the Hippocampus or any other CerebrA ROI by using MNI152 Template and CerebrA Atlas"

roiloc/template.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ants
2+
import importlib_resources
23
import pandas as pd
34
from ants.core.ants_image import ANTsImage
45

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

2122
betstr = "bet" if bet else ""
2223

23-
return ants.image_read(
24-
f"roiloc/MNI/icbm152/mni_icbm152_{contrast}{betstr}_tal_nlin_sym_09c.nii",
25-
pixeltype="float")
24+
template = f"mni_icbm152_{contrast}{betstr}_tal_nlin_sym_09c.nii"
25+
res = importlib_resources.files("roiloc")
26+
data = str(res / "MNI" / "icbm152" / template)
27+
return ants.image_read(str(data), pixeltype="float")
2628

2729

2830
def get_roi_indices(roi: str) -> list:
2931
roi = roi.title()
30-
cerebra = pd.read_csv("roiloc/MNI/cerebra/CerebrA_LabelDetails.csv",
31-
index_col="Label Name")
32+
33+
res = importlib_resources.files("roiloc")
34+
data = str(res / "MNI" / "cerebra" / "CerebrA_LabelDetails.csv")
35+
cerebra = pd.read_csv(data, index_col="Label Name")
36+
3237
return [cerebra.loc[roi, "RH Label"], cerebra.loc[roi, "LH Labels"]]

0 commit comments

Comments
 (0)