From a727206fe9fa2c338c9332a558d70de62dbd3e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20POIRET?= Date: Mon, 12 Jul 2021 10:12:10 +0200 Subject: [PATCH] 0.1.0 release * Added support for poetry scripts --- README.rst | 5 +++-- pyproject.toml | 8 +++++++- roiloc.py => roiloc/roiloc.py | 11 ++++++----- roiloc/template.py | 15 ++++++++++----- 4 files changed, 26 insertions(+), 13 deletions(-) rename roiloc.py => roiloc/roiloc.py (95%) diff --git a/README.rst b/README.rst index bbe3a96..4e47823 100644 --- a/README.rst +++ b/README.rst @@ -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:: @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 183f00c..91de368 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,14 +2,20 @@ name = "ROILoc" version = "0.1.0" description = "" +license = "MIT" +readme = "README.rst" authors = ["Clément POIRET "] [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" diff --git a/roiloc.py b/roiloc/roiloc.py similarity index 95% rename from roiloc.py rename to roiloc/roiloc.py index 02f0101..cfefccc 100644 --- a/roiloc.py +++ b/roiloc/roiloc.py @@ -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 @@ -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] @@ -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" diff --git a/roiloc/template.py b/roiloc/template.py index 2bc286c..dfcdb64 100644 --- a/roiloc/template.py +++ b/roiloc/template.py @@ -1,4 +1,5 @@ import ants +import importlib_resources import pandas as pd from ants.core.ants_image import ANTsImage @@ -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"]]