Skip to content
Merged
Changes from 1 commit
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
Next Next commit
added mrtrix3 dwifslpreproc as interface
  • Loading branch information
axiezai committed Nov 26, 2020
commit 69a7493f54f6877bd64a4ca19b11bcf0e4c0df16
115 changes: 115 additions & 0 deletions nipype/interfaces/mrtrix3/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class DWIBiasCorrect(MRTrix3Base):
_cmd = "dwibiascorrect"
input_spec = DWIBiasCorrectInputSpec
output_spec = DWIBiasCorrectOutputSpec

def _format_arg(self, name, trait_spec, value):
if name in ("use_ants", "use_fsl"):
ver = self.version
Expand All @@ -241,6 +242,120 @@ def _format_arg(self, name, trait_spec, value):
return f"-{trait_spec.argstr}"
return super()._format_arg(name, trait_spec, value)


class DWIPreprocInputSpec(MRTrix3BaseInputSpec):
in_file = File(
exists=True, argstr="%s", position=-5, mandatory=True, desc="input DWI image"
)
out_file = File(
"preproc.mif",
argstr="%s",
mandatory=True,
position=-4,
usedefault=True,
desc="output file after preprocessing",
)
rpe_options = traits.Enum(
"-rpe_none",
"-rpe_pair",
"-rpe_all",
"-rpe_header",
argstr="%s",
position=-3,
mandatory=True,
desc="Specify acquisition phase-encoding design, one of the -rpe_* options must be provided",
)
pe_dir = traits.Str(
argstr="-pe_dir %s",
position=-2,
mandatory=True,
desc="Specify the phase encoding direction of the input series, can be a signed axis number (e.g. -0, 1, +2), an axis designator (e.g. RL, PA, IS), or NIfTI axis codes (e.g. i-, j, k)",
)
ro_time = traits.Float(
argstr="-readout_time %f",
position=-1,
desc="Total readout time of input series (in seconds)",
)
in_epi = File(
exists=True,
argstr="-se_epi %s",
desc="Provide an additional image series consisting of spin-echo EPI images, which is to be used exclusively by topup for estimating the inhomogeneity field (i.e. it will not form part of the output image series)",
)
align_seepi = traits.Bool(
argstr="-align_seepi",
desc="Achieve alignment between the SE-EPI images used for inhomogeneity field estimation, and the DWIs",
)
eddy_options = traits.Str(
argstr="-eddy_options %s",
desc="-eddy_options ” EddyOptions” Manually provide additional command-line options to the eddy command (provide a string within quotation marks that contains at least one space, even if only passing a single command-line option to eddy)",
)
topup_options = traits.Str(
argstr="-topup_options %s",
desc="-topup_options ” TopupOptions” Manually provide additional command-line options to the topup command (provide a string within quotation marks that contains at least one space, even if only passing a single command-line option to topup)",
)
export_grad_mrtrix = traits.Bool(
argstr="-export_grad_mrtrix", desc="export new gradientt files in mrtrix format"
)
export_grad_fsl = traits.Bool(
argstr="-export_grad_fsl", desc="export gradient files in FSL format"
)
out_grad_mrtrix = File("dwi.b", argstrt="%s", desc="name of new gradient file")
out_grad_fsl = traits.Tuple(
File("dwi.bvecs", desc="bvecs"),
File("dwi.bvals", desc="bvals"),
argstr="%s, %s",
desc="Output (bvecs, bvals) gradients FSL format",
)


class DWIPreprocOutputtSpec(TraitedSpec):
out_file = File(argstr="%s", desc="output preprocessed image series")
out_grad_mrtrix = File(
argstr="%s", desc="preprocessed gradient file in mrtrix3 format"
)
out_fsl_bvec = File("dwi.bvecs", desc="exported fsl gradient bvec file")
out_fsl_bval = File("dwi.bvals", desc="exported fsl gradient bval file")


class DWIPreproc(MRTrix3Base):
"""
Perform diffusion image pre-processing using FSL's eddy tool; including inhomogeneity distortion correction using FSL's topup tool if possible

For more information, see
<https://mrtrix.readthedocs.io/en/latest/reference/commands/dwifslpreproc.html>

Example
-------

>>> import nipype.interfaces.mrtrix3 as mrt
>>> preproc = mrt.DWIPreproc()
>>> preproc.inputs.in_file = 'dwi.mif'
>>> preproc.inputs.rpe_options = '-rpe_none'
>>> preproc.inputs.eddy_options = '"--slm=linear --repol"'
>>> preproc.inputs.out_file = "preproc.mif"
>>> preproc.inputs.grad_file = "dwi.b"
>>> preproc.inputs.ro_time = 0.165240 # 'TotalReadoutTime' in BIDS JSON metadata files
>>> preproc.inputs.pe_dir = 'j' # 'PhaseEncodingDirection' in BIDS JSON metadata files
>>> preproc.cmdline
`dwifslpreproc dwi.mif preproc.mif -eddy_options "--slm=linear " -rpe_none -pe_dir j -grad dwi.b -readout_time 0.165240`
"""

_cmd = "dwifslpreproc"
input_spec = DWIPreprocInputSpec
output_spec = DWIPreprocOutputtSpec

def _list_outputs(self):
outputs = self.output_spec().get()
outputs["out_file"] = op.abspath(self.inputs.out_file)
if self.inputs.export_grad_mrtrix == True:
outputs["out_grad_mrtrix"] = op.abspath(self.inputs.out_grad_mrtrix)
if self.inputs.export_grad_fsl == True:
outputs["out_fsl_bvec"] = op.abspath(self.inputs.out_grad_fsl[0])
outputs["out_fsl_bval"] = op.abspath(self.inputs.out_grad_fsl[1])

return outputs


class ResponseSDInputSpec(MRTrix3BaseInputSpec):
algorithm = traits.Enum(
"msmt_5tt",
Expand Down