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

[ENH]: Add functions to mrtrix3 interface #3613

Merged
merged 19 commits into from
Mar 20, 2024
28 changes: 16 additions & 12 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -891,16 +891,6 @@
"name": "Mihai, Paul Glad",
"orcid": "0000-0001-5715-6442"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Gorgolewski, Krzysztof J.",
"orcid": "0000-0003-3321-7583"
},
{
"affiliation": "MIT, HMS",
"name": "Ghosh, Satrajit",
"orcid": "0000-0002-5312-6729"
},
{
"affiliation": "University of Tübingen and MPI for Biological Cybernertics",
"name": "Bannert, Michael M.",
Expand All @@ -909,13 +899,27 @@
{
"affiliation": "Research Centre Juelich",
"name": "Wu, Jianxiao",
"orcid": "0000-0002-4866-272X",
"orcid": "0000-0002-4866-272X"
},
{
"affiliation": "Department of Neurology, BG-University Hospital Bergmannsheil Bochum, Germany",
"name": "Butry, Lionel"
},
{
"affiliation": "Lund University",
"name": "Anijärv, Toomas Erik",
"orcid": "0000-0002-3650-4230",
"orcid": "0000-0002-3650-4230"
},
{
"affiliation": "Department of Psychology, Stanford University",
"name": "Gorgolewski, Krzysztof J.",
"orcid": "0000-0003-3321-7583"
},
{
"affiliation": "MIT, HMS",
"name": "Ghosh, Satrajit",
"orcid": "0000-0002-5312-6729"
}
],
"keywords": [
"neuroimaging",
Expand Down
3 changes: 3 additions & 0 deletions nipype/interfaces/mrtrix3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
SHConv,
TensorMetrics,
TransformFSLConvert,
MaskFilter,
MTNormalise,
Generate5tt2gmwmi,
)
194 changes: 194 additions & 0 deletions nipype/interfaces/mrtrix3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,3 +1185,197 @@
outputs = self.output_spec().get()
outputs["out_file"] = op.abspath(self.inputs.out_file)
return outputs

class MaskFilterInputSpec(CommandLineInputSpec):
in_file = File(
exists=True,
mandatory=True,
argstr="%s",
position=-3,
desc="Input mask",
)
filter = traits.Str(
mandatory=True,
argstr="%s",
position=-2,
desc="Filter to perform (e.g. dilate, erode)"
)
out_file = File(
name_source=["input_image"],
mandatory=True,
argstr="%s",
position=-1,
desc="Output mask"
)
npass = traits.Int(
argstr="-npass %d",
position=1,
desc="Number of passes"
)

class MaskFilterOutputSpec(TraitedSpec):
out_file = File(exists=True, desc="the filtered output mask")

class MaskFilter(CommandLine):
"""
Perform filtering operations on 3D / 4D mask images.
Only supports dilate / erode filters at the moment.
For more information see: https://mrtrix.readthedocs.io/en/latest/reference/commands/maskfilter.html


Example
-------

>>> import nipype.interfaces.mrtrix3 as mrt
>>> mf = mrt.MaskFilter()
>>> mf.inputs.in_file = 'mask.mif'
>>> mf.inputs.filter = 'dilate'
>>> mf.inputs.npass = 2
>>> mf.out_file = 'mask_filtered.mif'
lbutry marked this conversation as resolved.
Show resolved Hide resolved
>>> mf.cmdline
'maskfilter -npass 2 mask.mif dilate mask_filtered.mif'
>>> mf.run()
"""

_cmd = "maskfilter"
input_spec = MaskFilterInputSpec
output_spec = MaskFilterOutputSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs["out_file"] = op.abspath(self.inputs.out_file)
return outputs

Check warning on line 1247 in nipype/interfaces/mrtrix3/utils.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/mrtrix3/utils.py#L1245-L1247

Added lines #L1245 - L1247 were not covered by tests

class MTNormaliseInputSpec(MRTrix3BaseInputSpec):
wm_fod = File(
argstr="%s",
exists=True,
position=1,
desc="input fod of white matter tissue compartment"
)
out_file_wm = File(
argstr="%s",
position=2,
desc="output file of white matter tissue compartment"
)
gm_fod = File(
argstr="%s",
exists=True,
position=3,
desc="input fod of grey matter tissue compartment"
)
out_file_gm = File(
argstr="%s",
position=4,
desc="output file of grey matter tissue compartment"
)
csf_fod = File(
argstr="%s",
exists=True,
position=5,
desc="input fod of CSF tissue compartment"
)
out_file_csf = File(
argstr="%s",
position=6,
desc="output file of CSF tissue compartment 3"
)
mask = File(
argstr="-mask %s",
exists=True,
position=-1,
desc="input brain mask"
)

class MTNormaliseOutputSpec(TraitedSpec):
out_file_wm = File(exists=True, desc="the normalized white matter fod")
out_file_gm = File(exists=True, desc="the normalized grey matter fod")
out_file_csf = File(exists=True, desc="the normalized csf fod")


class MTNormalise(CommandLine):
"""
Multi-tissue informed log-domain intensity normalisation


Example
-------

>>> import nipype.interfaces.mrtrix3 as mrt
>>> mtn = mrt.MTnormalise()
lbutry marked this conversation as resolved.
Show resolved Hide resolved
>>> mtn.inputs.fod_wm = 'wmfod.mif'
>>> mtn.inputs.fod_gm = 'gmfod.mif'
>>> mtn.inputs.fod_csf = 'csffod.mif'
>>> mtn.inputs.out_file_wm = 'wmfod_norm.mif'
>>> mtn.inputs.out_file_gm = 'gmfod_norm.mif'
>>> mtn.inputs.out_file_csf = 'csffod_norm.mif'
>>> mtn.inputs.mask = 'mask.mif'
>>> mtn.cmdline
'mtnormalise wmfod.mif wmfod_norm.mif gmfod.mif gmfod_norm.mif csffod.mif csffod_norm.mif -mask mask.mif'
>>> mtn.run()
"""

_cmd = "mtnormalise"
input_spec = MTNormaliseInputSpec
output_spec = MTNormaliseOutputSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs["out_file_wm"] = op.abspath(self.inputs.out_file_wm)
outputs["out_file_gm"] = op.abspath(self.inputs.out_file_gm)
outputs["out_file_csf"] = op.abspath(self.inputs.out_file_csf)
return outputs

Check warning on line 1327 in nipype/interfaces/mrtrix3/utils.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/mrtrix3/utils.py#L1323-L1327

Added lines #L1323 - L1327 were not covered by tests


class Generate5tt2gmwmiInputSpec(MRTrix3BaseInputSpec):
in_file = File(
exists=True,
argstr="%s",
mandatory=True,
position=-2,
desc="the input 5TT segmented anatomical image",
)
mask_out = File(
"mask_gmwmi.mif",
argstr="%s",
mandatory=True,
position=-1,
desc="the output mask image",
)
mask_in = File(
argstr="-mask_in %s",
position=-3,
desc="filter an imput mask image according to those voxels that lie upon the grey matter - white matter boundary",

Check failure on line 1348 in nipype/interfaces/mrtrix3/utils.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

imput ==> input
lbutry marked this conversation as resolved.
Show resolved Hide resolved
)


class Generate5tt2gmwmiOutputSpec(TraitedSpec):
mask_out = File(exists=True, desc="the output mask file")


class Generate5tt2gmwmi(CommandLine):
"""
Generate a mask image appropriate for seeding streamlines on
the grey matter-white matter interface


Example
-------

>>> import nipype.interfaces.mrtrix3 as mrt
>>> gmwmi = mrt.Generate5TT2GMWMI()
>>> gmwmi.inputs.in_file = '5tt_in.mif'
>>> gmwmi.inputs.mask_out = 'mask_gmwmi.mif'
>>> gmwmi.cmdline
'5tt2gmwmi 5tt_in.mif mask_gmwmi.mif'
>>> gmwmi.run()
"""

_cmd = "5tt2gmwmi"
input_spec = Generate5tt2gmwmiInputSpec
output_spec = Generate5tt2gmwmiOutputSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs["mask_out"] = op.abspath(self.inputs.mask_out)
return outputs

Check warning on line 1381 in nipype/interfaces/mrtrix3/utils.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/mrtrix3/utils.py#L1379-L1381

Added lines #L1379 - L1381 were not covered by tests
Loading