Skip to content

Commit

Permalink
⚗️ Try forcing relative paths for FSL Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Sep 3, 2021
1 parent 81925d7 commit 9545a7b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CPAC/utils/interfaces/fsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""FSL Nipype interfaces with customized functionality"""
import os
from nipype.interfaces.fsl.utils import Merge as fslMerge


class Merge(fslMerge):
"""Use relative paths for input files"""
def _format_arg(self, name, spec, value):
if name == "tr":
if self.inputs.dimension != "t":
raise ValueError("When TR is specified, dimension must be t")
return spec.argstr % value
if name == "dimension":
if isdefined(self.inputs.tr):
return "-tr"
return spec.argstr % value
# Begin custom code
# -----------------
if name == "in_files":
return ' '.join([
os.path.relpath(in_file) for in_file in value.split(' ')
])
# ---------------
# End custom code
return super(Merge, self)._format_arg(name, spec, value)
Empty file.
54 changes: 54 additions & 0 deletions CPAC/utils/interfaces/tests/test_fsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from ..fsl import Merge


def test_Merge_inputs():
input_map = dict(
args=dict(
argstr="%s",
),
dimension=dict(
argstr="-%s",
mandatory=True,
position=0,
),
environ=dict(
nohash=True,
usedefault=True,
),
in_files=dict(
argstr="%s",
mandatory=True,
position=2,
),
merged_file=dict(
argstr="%s",
extensions=None,
hash_files=False,
name_source="in_files",
name_template="%s_merged",
position=1,
),
output_type=dict(),
tr=dict(
argstr="%.2f",
position=-1,
),
)
inputs = Merge.input_spec()

for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(inputs.traits()[key], metakey) == value


def test_Merge_outputs():
output_map = dict(
merged_file=dict(
extensions=None,
),
)
outputs = Merge.output_spec()

for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
assert getattr(outputs.traits()[key], metakey) == value

0 comments on commit 9545a7b

Please sign in to comment.