Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorial issue fix #56

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/guides/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

PyALFE supports Linux x86-64, Mac x86-64, and Mac arm64 and requires python >= 3.9.

### Image registration and processing
PyALFE can be configured to use either [Greedy](https://greedy.readthedocs.io/en/latest/) or [AntsPy](https://antspy.readthedocs.io/en/latest/registration.html) registration tools.
Similarly, PyALFE can be configured to use [Convert3D](https://sourceforge.net/p/c3d/git/ci/master/tree/doc/c3d.md) or python native library [Nilearn](https://nilearn.github.io/stable/index.html) for image processing tasks.
To use Greedy and Convert3d, these command line tools should be downloaded using the [download command](#download-models-and-tools).
### Prerquisite
PyALFE uses [Greedy](https://greedy.readthedocs.io/en/latest/) registration tool by default. The instruction for installing Greedy can be found [here](https://greedy.readthedocs.io/en/latest/install.html#using-pre-compiled-binaries).

Alternatively, PyALFE can be configured to use [AntsPy](https://antspy.readthedocs.io/en/latest/registration.html) registration tool. To use AntsPy, you can install PyALFE with [ants support](#extras).

### Option 1: PyPI

Expand Down Expand Up @@ -72,7 +72,7 @@ when performing a build and install
pip install 'dist/pyalfe-0.1.0-py3-none-any.whl[radiomics]'
```

If you want to use ant registration tool, you can install pyalfe with ants support:
If you want to use ants registration tool, you can install pyalfe with ants support:
```bash
pip install 'pyalfe[ants]'
```
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pyalfe download models

Configure pyalfe by running
```bash
pyalfe configrue
pyalfe configure
```
and simply pressing enter for all the prompts for default values.

Expand Down
18 changes: 12 additions & 6 deletions pyalfe/interfaces/c3d.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import subprocess
import io

from pyalfe.tools import C3D_PATH
from picsl_c3d import Convert3D


class C3D:
def __init__(self, c3d_path=C3D_PATH):
self.cmd = [c3d_path]
def __init__(self):
self.cmd = []
self.c = Convert3D()

def __repr__(self):
return ' '.join([str(part) for part in self.cmd])

def assign(self, var):
self.cmd.append('-as')
Expand Down Expand Up @@ -97,7 +101,9 @@ def sdt(self):
return self

def run(self):
return subprocess.run(self.cmd, capture_output=True).stdout.decode("utf-8")
return self.c.execute(self.__repr__())

def check_output(self):
return subprocess.check_output(self.cmd).decode("utf-8")
cmd_output = io.StringIO()
self.c.execute(self.__repr__(), out=cmd_output)
return cmd_output.getvalue()
13 changes: 12 additions & 1 deletion pyalfe/interfaces/freesurfer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import subprocess
from shutil import which


class FreeSurfer:
def __init__(self):
self.cmd = []

def mri_synthseg(self, input, output):
self.cmd += ['mri_synthseg', '--i', input, '--o', output]
synthseg_cmd = 'mri_synthseg'
if which(synthseg_cmd) is None:
raise RuntimeError(
f'{synthseg_cmd} executable was not found in your system. '
'To download and install FreeSurfer version 7, visit:\n '
'https://surfer.nmr.mgh.harvard.edu/fswiki/DownloadAndInstall \n'
'To configure FreeSurfer, visit:\n'
'https://surfer.nmr.mgh.harvard.edu/fswiki/SetupConfiguration_Linux \n'
'https://surfer.nmr.mgh.harvard.edu/fswiki/SetupConfiguration_Mac'
)
self.cmd += [synthseg_cmd, '--i', input, '--o', output]
return self

def run(self):
Expand Down
13 changes: 12 additions & 1 deletion pyalfe/interfaces/greedy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import subprocess
from shutil import which

from pyalfe.tools import GREEDY_PATH
from pyalfe.tools import GREEDY_PATH, greedy_url


class Greedy:
def __init__(self, greedy_path=GREEDY_PATH):
self.cmd = [greedy_path]
if which(greedy_path) is None:
msg = (
f'{greedy_path} executable was not found in your system. '
'To download and install greedy, visit:\n '
'https://greedy.readthedocs.io/en/latest/install.html#using-pre-compiled-binaries'
)
if greedy_url:
msg += f'\n or {greedy_url} \n'

raise RuntimeError(msg)

def dim(self, d):
self.cmd += ['-d', str(d)]
Expand Down
80 changes: 50 additions & 30 deletions pyalfe/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
import os
from collections import defaultdict

greedy_url = {
'Linux': {
'x86_64': (
'https://sourceforge.net/projects/greedy-reg/files/Nightly/'
'greedy-nightly-Linux-gcc64.tar.gz'
)
},
'Darwin': {
'x86_64': (
'https://sourceforge.net/projects/greedy-reg/files/Nightly/'
'greedy-nightly-MacOS-x86_64.dmg'
greedy_url = defaultdict(
lambda: defaultdict(str),
{
'Linux': defaultdict(
str,
{
'x86_64': (
'https://sourceforge.net/projects/greedy-reg/files/Nightly/'
'greedy-nightly-Linux-gcc64.tar.gz'
)
},
),
'arm64': (
'https://sourceforge.net/projects/greedy-reg/files/Nightly/'
'greedy-nightly-MacOS-arm64.dmg'
'Darwin': defaultdict(
str,
{
'x86_64': (
'https://sourceforge.net/projects/greedy-reg/files/Nightly/'
'greedy-nightly-MacOS-x86_64.dmg'
),
'arm64': (
'https://sourceforge.net/projects/greedy-reg/files/Nightly/'
'greedy-nightly-MacOS-arm64.dmg'
),
},
),
},
}[os.uname()[0]][os.uname()[-1]]
)[os.uname()[0]][os.uname()[-1]]

c3d_url = {
'Linux': {
'x86_64': (
'https://sourceforge.net/projects/c3d/files/c3d/Nightly/'
'c3d-nightly-Linux-gcc64.tar.gz'
)
},
'Darwin': {
'x86_64': (
'https://sourceforge.net/projects/c3d/files/c3d/Nightly/'
'c3d-nightly-MacOS-x86_64.dmg'

c3d_url = defaultdict(
lambda: defaultdict(str),
{
'Linux': defaultdict(
str,
{
'x86_64': (
'https://sourceforge.net/projects/c3d/files/c3d/Nightly/'
'c3d-nightly-Linux-gcc64.tar.gz'
)
},
),
'arm64': (
'https://sourceforge.net/projects/c3d/files/c3d/Nightly/'
'c3d-nightly-MacOS-arm64.dmg'
'Darwin': defaultdict(
str,
{
'x86_64': (
'https://sourceforge.net/projects/c3d/files/c3d/Nightly/'
'c3d-nightly-MacOS-x86_64.dmg'
),
'arm64': (
'https://sourceforge.net/projects/c3d/files/c3d/Nightly/'
'c3d-nightly-MacOS-arm64.dmg'
),
},
),
},
}[os.uname()[0]][os.uname()[-1]]
)[os.uname()[0]][os.uname()[-1]]

GREEDY_PATH = 'greedy' # importlib.resources.files('pyalfe.tools').joinpath('greedy')
C3D_PATH = 'c3d' # importlib.resources.files('pyalfe.tools').joinpath('c3d')
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies = [
"huggingface_hub",
"torch",
"pandas",
"picsl_c3d",
"pybids",
"nibabel",
"nilearn",
Expand Down
Loading