Skip to content

convert eddy & adding test data #48

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Empty file added pydra/tasks/fsl/epi/__init__.py
Empty file.
506 changes: 506 additions & 0 deletions pydra/tasks/fsl/epi/eddy.py

Large diffs are not rendered by default.

Empty file.
68 changes: 68 additions & 0 deletions pydra/tasks/fsl/epi/tests/test_run_eddy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import re, os, shutil, pytest
from pathlib import Path
from ..eddy import Eddy


@pytest.mark.xfail("FSLDIR" not in os.environ, reason="no FSL found", raises=FileNotFoundError)
@pytest.mark.parametrize(
"inputs, outputs",
[
(
{
"in_file": "test.nii.gz",
"in_mask": "mask.nii.gz",
"in_index": "test_index.txt",
"in_acqp": "test_acqp.txt",
"in_bvec": "bvecs.scheme",
"in_bval": "bvals.scheme",
},
[
"out_corrected",
"out_parameter",
"out_movement_rms",
"out_restricted_movement_rms",
"out_shell_alignment_parameters",
"out_shell_pe_translation_parameters",
"out_outlier_map",
"out_outlier_n_stdev_map",
"out_outlier_n_sqr_stdev_map",
"out_outlier_report",
],
)
],
)
def test_Eddy(test_data, inputs, outputs):
if inputs is None:
in_file = Path(test_data) / "test.nii.gz"
task = Eddy(in_file=in_file)
else:
for key, val in inputs.items():
try:
pattern = r"\.[a-zA-Z]*"
if isinstance(val, str):
if re.findall(pattern, val) != []:
inputs[key] = Path(test_data) / val
elif "_dir" in key:
dirpath = Path(test_data) / val
if dirpath.exists() and dirpath.is_dir():
shutil.rmtree(dirpath)
inputs[key] = Path(test_data) / val
else:
inputs[key] = eval(val)
elif isinstance(val, list):
if all(re.findall(pattern, _) != [] for _ in val):
inputs[key] = [Path(test_data) / _ for _ in val]
else:
inputs[key] = eval(val)
except:
pass
task = Eddy(**inputs)
assert set(task.generated_output_names) == set(["return_code", "stdout", "stderr"] + outputs)
breakpoint()
res = task()
print("RESULT: ", res)
for out_nm in outputs:
if isinstance(getattr(res.output, out_nm), list):
assert [os.path.exists(x) for x in getattr(res.output, out_nm)]
else:
assert os.path.exists(getattr(res.output, out_nm))
59 changes: 59 additions & 0 deletions pydra/tasks/fsl/epi/tests/test_spec_eddy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import re, os, shutil, pytest
from pathlib import Path
from ..eddy import Eddy


@pytest.mark.parametrize(
"inputs, outputs",
[
(
{
"in_file": "test.nii.gz",
"in_mask": "mask.nii.gz",
"in_index": "test_index.txt",
"in_acqp": "test_acqp.txt",
"in_bvec": "bvecs.scheme",
"in_bval": "bvals.scheme",
},
[
"out_corrected",
"out_parameter",
"out_movement_rms",
"out_restricted_movement_rms",
"out_shell_alignment_parameters",
"out_shell_pe_translation_parameters",
"out_outlier_map",
"out_outlier_n_stdev_map",
"out_outlier_n_sqr_stdev_map",
"out_outlier_report",
],
)
],
)
def test_Eddy(test_data, inputs, outputs):
if inputs is None:
in_file = Path(test_data) / "test.nii.gz"
task = Eddy(in_file=in_file)
else:
for key, val in inputs.items():
try:
pattern = r"\.[a-zA-Z]*"
if isinstance(val, str):
if re.findall(pattern, val) != []:
inputs[key] = Path(test_data) / val
elif "_dir" in key:
dirpath = Path(test_data) / val
if dirpath.exists() and dirpath.is_dir():
shutil.rmtree(dirpath)
inputs[key] = Path(test_data) / val
else:
inputs[key] = eval(val)
elif isinstance(val, list):
if all(re.findall(pattern, _) != [] for _ in val):
inputs[key] = [Path(test_data) / _ for _ in val]
else:
inputs[key] = eval(val)
except:
pass
task = Eddy(**inputs)
assert set(task.generated_output_names) == set(["return_code", "stdout", "stderr"] + outputs)
1 change: 1 addition & 0 deletions pydra/tasks/fsl/tests/data/bvals.scheme
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
3 changes: 3 additions & 0 deletions pydra/tasks/fsl/tests/data/bvecs.scheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0 1 0 -1 0
0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 changes: 12 additions & 0 deletions pydra/tasks/fsl/tests/data/test_acqp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
0 1 0 0.1
0 1 0 0.1
0 1 0 0.1
1 0 0 0.1
1 0 0 0.1
1 0 0 0.1
0 -1 0 0.1
0 -1 0 0.1
0 -1 0 0.1
-1 0 0 0.1
-1 0 0 0.1
-1 0 0 0.1
1 change: 1 addition & 0 deletions pydra/tasks/fsl/tests/data/test_index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11
4 changes: 4 additions & 0 deletions specs/callables.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def FAST_output_infile(field, in_files, out_basename):


def FEAT_output(fsf_file):
import os
from glob import glob

is_ica = False
with open(fsf_file, "rt") as fp:
text = fp.read()
Expand All @@ -173,6 +176,7 @@ def FEAT_output(fsf_file):

def FEATModel_output(field, fsf_file):
import os
from glob import glob

# TODO: figure out file names and get rid off the globs
outputs = {}
Expand Down
60 changes: 52 additions & 8 deletions specs/fsl_epi_param.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,58 @@
# tests_inputs:
# tests_outputs:

# Eddy:
# output_requirements:
# output_callables:
# output_templates:
# inputs_drop:
# doctest:
# tests_inputs:
# tests_outputs:
Eddy:
output_requirements:
out_corrected:
out_parameter:
out_rotated_bvec:
out_movement_rms:
out_restricted_movement_rms:
out_shell_alignment_parameters:
out_shell_pe_translation_parameters:
out_outlier_map:
out_outlier_n_stdev_map:
out_outlier_n_sqr_stdev_map:
out_outlier_report:
out_outlier_free: [repol]
out_movement_over_time: [mporder]
out_cnr_maps: [cnr_maps]
out_residuals: [residuals]
output_callables:
output_templates:
out_corrected: "{out_base}.nii.gz"
out_parameter: "{out_base}.eddy_parameters"
out_rotated_bvec: "{out_base}.eddy_rotated_bvecs"
out_movement_rms: "{out_base}.eddy_movement_rms"
out_restricted_movement_rms: "{out_base}.eddy_restricted_movement_rms"
out_shell_alignment_parameters: "{out_base}.eddy_post_eddy_shell_alignment_parameters"
out_shell_pe_translation_parameters: "{out_base}.eddy_post_eddy_shell_PE_translation_parameters"
out_outlier_map: "{out_base}.eddy_outlier_map"
out_outlier_n_stdev_map: "{out_base}.eddy_outlier_n_stdev_map"
out_outlier_n_sqr_stdev_map: "{out_base}.eddy_outlier_n_sqr_stdev_map"
out_outlier_report: "{out_base}.eddy_outlier_report"
out_outlier_free: "{out_base}.eddy_outlier_free_data"
out_movement_over_time: "{out_base}.eddy_movement_over_time"
out_cnr_maps: "{out_base}.eddy_cnr_maps"
out_residuals: "{out_base}.eddy_residuals"
inputs_drop:
doctest:
in_file: test.nii.gz
in_mask: mask.nii.gz
in_index: test_index.txt
in_acqp: test_acqp.txt
in_bvec: bvecs.scheme
in_bval: bvals.scheme
cmdline: eddy_openmp --imain=test.nii.gz --mask=test_mask.nii.gz --index=test_index.txt --acqp=test_acqp.txt --bvecs=bvecs.scheme --bvals=bvals.scheme --verbose
tests_inputs:
- in_file: test.nii.gz
in_mask: mask.nii.gz
in_index: test_index.txt
in_acqp: test_acqp.txt
in_bvec: bvecs.scheme
in_bval: bvals.scheme
tests_outputs:
- [out_corrected, out_parameter, out_movement_rms, out_restricted_movement_rms, out_shell_alignment_parameters, out_shell_pe_translation_parameters, out_outlier_map, out_outlier_n_stdev_map, out_outlier_n_sqr_stdev_map, out_outlier_report]

# EddyCorrect:
# output_requirements:
Expand Down