Skip to content

[ENC] Created an interface for mrtrix3's mrcat function #3403

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

Closed
wants to merge 3 commits into from
Closed
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
21 changes: 13 additions & 8 deletions doc/devel/matlab_example1.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from nipype.interfaces.matlab import MatlabCommand
from nipype.interfaces.base import TraitedSpec, \
BaseInterface, BaseInterfaceInputSpec, File
from nipype.interfaces.base import (
TraitedSpec,
BaseInterface,
BaseInterfaceInputSpec,
File,
)
import os
from string import Template


class ConmapTxt2MatInputSpec(BaseInterfaceInputSpec):
in_file = File(exists=True, mandatory=True)
out_file = File('cmatrix.mat', usedefault=True)
out_file = File("cmatrix.mat", usedefault=True)


class ConmapTxt2MatOutputSpec(TraitedSpec):
Expand All @@ -19,14 +23,15 @@ class ConmapTxt2Mat(BaseInterface):
output_spec = ConmapTxt2MatOutputSpec

def _run_interface(self, runtime):
d = dict(in_file=self.inputs.in_file,
out_file=self.inputs.out_file)
d = dict(in_file=self.inputs.in_file, out_file=self.inputs.out_file)
# This is your MATLAB code template
script = Template("""in_file = '$in_file';
script = Template(
"""in_file = '$in_file';
out_file = '$out_file';
ConmapTxt2Mat(in_file, out_file);
exit;
""").substitute(d)
"""
).substitute(d)

# mfile = True will create an .m file with your script and executed.
# Alternatively
Expand All @@ -43,5 +48,5 @@ def _run_interface(self, runtime):

def _list_outputs(self):
outputs = self._outputs().get()
outputs['out_file'] = os.path.abspath(self.inputs.out_file)
outputs["out_file"] = os.path.abspath(self.inputs.out_file)
return outputs
8 changes: 5 additions & 3 deletions doc/devel/matlab_example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class HelloWorldInputSpec(MatlabInputSpec):
name = traits.Str(mandatory=True,
desc='Name of person to say hello to')
name = traits.Str(mandatory=True, desc="Name of person to say hello to")


class HelloWorldOutputSpec(TraitedSpec):
Expand All @@ -29,6 +28,7 @@ class HelloWorld(MatlabCommand):
>>> out = hello.run()
>>> print out.outputs.matlab_output
"""

input_spec = HelloWorldInputSpec
output_spec = HelloWorldOutputSpec

Expand All @@ -37,7 +37,9 @@ def _my_script(self):
script = """
disp('Hello %s Python')
two = 1 + 1
""" % (self.inputs.name)
""" % (
self.inputs.name
)
return script

def run(self, **inputs):
Expand Down
1 change: 1 addition & 0 deletions nipype/interfaces/mrtrix3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DWIExtract,
SHConv,
SH2Amp,
MRCat,
)
from .preprocess import (
ResponseSD,
Expand Down
73 changes: 73 additions & 0 deletions nipype/interfaces/mrtrix3/tests/test_auto_MRCat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from ..utils import MRCat


def test_MRCat_inputs():
input_map = dict(
args=dict(
argstr="%s",
),
axis=dict(
argstr="-axis %s",
),
bval_scale=dict(
argstr="-bvalue_scaling %s",
),
datatype=dict(
argstr="-datatype %s",
),
environ=dict(
nohash=True,
usedefault=True,
),
grad_file=dict(
argstr="-grad %s",
extensions=None,
xor=["grad_fsl"],
),
grad_fsl=dict(
argstr="-fslgrad %s %s",
xor=["grad_file"],
),
in_bval=dict(
extensions=None,
),
in_bvec=dict(
argstr="-fslgrad %s %s",
extensions=None,
),
in_files=dict(
argstr="%s",
mandatory=True,
position=-2,
),
nthreads=dict(
argstr="-nthreads %d",
nohash=True,
),
out_file=dict(
argstr="%s",
extensions=None,
mandatory=True,
position=-1,
usedefault=True,
),
)
inputs = MRCat.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_MRCat_outputs():
output_map = dict(
out_file=dict(
extensions=None,
),
)
outputs = MRCat.output_spec()

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