-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚗️ Try forcing relative paths for FSL Merge
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |