Commit 7f9a655d by Junhao WEN

NODDI pipeline

Adding dependancy of niftimatlib
parent e0db8975
Pipeline #1056 passed with stages
in 1 minute 59 seconds
function noddiprocessing(output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, bStep, noddi_toolbox_dir, num_cores)
function noddiprocessing(output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, bStep, noddi_toolbox_dir, nifti_matlib_dir, num_cores)
%This is a function to fit NODDI onto the multiple shells diffusion data
%based on this paper: NODDI: Practical in vivo neurite orientation
%dispersion and density imaging of the human brain, Neuroimage, 2012, Gary
......@@ -32,7 +32,8 @@ end
%% add path to the python.m file
addpath(fileparts(which(mfilename())));
addpath(noddi_toolbox_dir);
addpath(genpath(noddi_toolbox_dir));
addpath(genpath(nifti_matlib_dir));
%%
cd(output_dir);
......
......@@ -61,8 +61,9 @@ class DwiProcessingNoddiCLI(ce.CmdParser):
caps_directory=self.absolute_path(args.caps_directory),
tsv_file=self.absolute_path(args.subjects_sessions_tsv))
from clinica.utils.check_dependency import check_noddi_matlab_toolbox
from clinica.utils.check_dependency import check_noddi_matlab_toolbox, check_nifti_matlib_toolbox
noddi_matlab_toolbox = check_noddi_matlab_toolbox()
nifti_matlib_toolbox = check_nifti_matlib_toolbox()
pipeline.parameters = {
'bvalue_str': dict(
......@@ -71,6 +72,8 @@ class DwiProcessingNoddiCLI(ce.CmdParser):
[('n_procs', args.n_procs or 4)]),
'noddi_toolbox_dir': dict(
[('noddi_toolbox_dir', noddi_matlab_toolbox)]),
'nifti_matlib_dir': dict(
[('nifti_matlib_dir', nifti_matlib_toolbox)]),
}
if args.working_directory is None:
......
......@@ -45,9 +45,9 @@ class DwiProcessingNoddi(cpe.Pipeline):
def check_custom_dependencies(self):
"""Check dependencies that can not be listed in the `info.json` file.
"""
from clinica.utils.check_dependency import check_noddi_matlab_toolbox
check_noddi_matlab_toolbox()
from clinica.utils.check_dependency import check_noddi_matlab_toolbox, check_nifti_matlib_toolbox
_ = check_noddi_matlab_toolbox()
_ = check_nifti_matlib_toolbox()
def get_input_fields(self):
"""Specify the list of possible inputs of this pipeline.
......@@ -57,7 +57,7 @@ class DwiProcessingNoddi(cpe.Pipeline):
"""
return ['subject_id_list', 'noddi_preprocessed_dwi', 'noddi_preprocessed_bvec', 'noddi_preprocessed_bval',
'noddi_preprocessed_mask', 'n_procs', 'noddi_toolbox_dir'] # Fill here the list
'noddi_preprocessed_mask', 'n_procs', 'noddi_toolbox_dir', 'nifti_matlib_dir'] # Fill here the list
def get_output_fields(self):
......@@ -92,6 +92,7 @@ class DwiProcessingNoddi(cpe.Pipeline):
read_parameters_node.inputs.noddi_preprocessed_bval = noddi_preprocessed_bval
read_parameters_node.inputs.noddi_preprocessed_mask = noddi_preprocessed_mask
read_parameters_node.inputs.noddi_toolbox_dir = self.parameters['noddi_toolbox_dir']['noddi_toolbox_dir']
read_parameters_node.inputs.nifti_matlib_dir = self.parameters['nifti_matlib_dir']['nifti_matlib_dir']
self.connect([
(read_parameters_node, self.input_node, [('subject_id_list', 'subject_id_list')]),
......@@ -101,6 +102,7 @@ class DwiProcessingNoddi(cpe.Pipeline):
(read_parameters_node, self.input_node, [('noddi_preprocessed_mask', 'noddi_preprocessed_mask')]),
(read_parameters_node, self.input_node, [('n_procs', 'n_procs')]),
(read_parameters_node, self.input_node, [('noddi_toolbox_dir', 'noddi_toolbox_dir')]),
(read_parameters_node, self.input_node, [('nifti_matlib_dir', 'nifti_matlib_dir')]),
])
......@@ -155,6 +157,7 @@ class DwiProcessingNoddi(cpe.Pipeline):
(self.input_node, processing_pipeline, [('noddi_preprocessed_bval', 'inputnode.noddi_preprocessed_bval')]),
(self.input_node, processing_pipeline, [('noddi_preprocessed_mask', 'inputnode.noddi_preprocessed_mask')]),
(self.input_node, processing_pipeline, [('noddi_toolbox_dir', 'inputnode.noddi_toolbox_dir')]),
(self.input_node, processing_pipeline, [('nifti_matlib_dir', 'inputnode.nifti_matlib_dir')]),
## output
(processing_pipeline, self.output_node, [('outputnode.fit_icvf', 'fit_icvf')]), # noqa
(processing_pipeline, self.output_node, [('outputnode.fit_isovf', 'fit_isovf')]), # noqa
......
......@@ -255,7 +255,7 @@ def delete_amico(root_dir, subject_id):
else:
[os.remove(f) for f in files_list]
def runmatlab(output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, bStep, num_cores, path_to_matscript, noddi_toolbox_dir):
def runmatlab(output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, bStep, num_cores, path_to_matscript, noddi_toolbox_dir, nifti_matlib_dir):
"""
The wrapper to call noddi matlab script.
Args:
......@@ -302,8 +302,8 @@ def runmatlab(output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, b
matlab.inputs.paths = path_to_matscript # CLINICA_HOME, this is the path to add into matlab, addpath
matlab.inputs.script = """
noddiprocessing('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d');
""" % (output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, bStep, noddi_toolbox_dir, num_cores) # here, we should define the inputs for the matlab function that you want to use
noddiprocessing('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d');
""" % (output_dir, noddi_img, brain_mask, roi_mask, bval, bvec, prefix, bStep, noddi_toolbox_dir, nifti_matlib_dir, num_cores) # here, we should define the inputs for the matlab function that you want to use
matlab.inputs.mfile = True # this will create a file: pyscript.m , the pyscript.m is the default name
matlab.inputs.single_comp_thread = False # this will stop runing with single thread
matlab.inputs.logfile = join(output_dir, prefix + "_matlab_output.log")
......@@ -417,7 +417,7 @@ def matlab_noddi_processing(caps_directory, num_cores, bStep, name='NoddiMatlab'
inputnode = pe.Node(niu.IdentityInterface(
fields=['subject_id_list', 'noddi_preprocessed_dwi', 'noddi_preprocessed_bvec',
'noddi_preprocessed_bval', 'noddi_preprocessed_mask', 'noddi_toolbox_dir']),
'noddi_preprocessed_bval', 'noddi_preprocessed_mask', 'noddi_toolbox_dir', 'nifti_matlib_dir']),
name='inputnode')
capsnode = pe.MapNode(name='capsnode',
......@@ -440,7 +440,7 @@ def matlab_noddi_processing(caps_directory, num_cores, bStep, name='NoddiMatlab'
# Node to wrap noddi matlab toolbox script.
nodditoolbox = pe.MapNode(name='nodditoolbox',
interface=niu.Function(input_names=['output_dir', 'noddi_img', 'brain_mask', 'roi_mask', 'bval', 'bvec', 'prefix', 'bStep', 'num_cores',
'path_to_matscript', 'noddi_toolbox_dir'],
'path_to_matscript', 'noddi_toolbox_dir', 'nifti_matlib_dir'],
output_names=['fit_icvf', 'fit_isovf', 'fit_od'],
function=runmatlab), iterfield=['output_dir', 'noddi_img', 'brain_mask', 'roi_mask', 'bval', 'bvec', 'prefix'])
nodditoolbox.inputs.path_to_matscript = path_to_matscript
......@@ -477,6 +477,7 @@ def matlab_noddi_processing(caps_directory, num_cores, bStep, name='NoddiMatlab'
nodditoolbox_wf.connect(inputnode, 'subject_id_list', nodditoolbox, 'prefix')
# nodditoolbox_wf.connect(inputnode, 'bStep', nodditoolbox, 'bStep')
nodditoolbox_wf.connect(inputnode, 'noddi_toolbox_dir', nodditoolbox, 'noddi_toolbox_dir')
nodditoolbox_wf.connect(inputnode, 'nifti_matlib_dir', nodditoolbox, 'nifti_matlib_dir')
nodditoolbox_wf.connect(inputnode, 'subject_id_list', capsnode, 'subject_id_list')
nodditoolbox_wf.connect(capsnode, 'temp_folder', nodditoolbox, 'output_dir')
......
......@@ -107,6 +107,26 @@ def check_noddi_matlab_toolbox():
return noddi_matlab_toolbox
def check_nifti_matlib_toolbox():
"""
Check Niftimatlib toolbox.
This function checks if the NIFTI_MATLIB_TOOLBOX is present in the environment.
"""
import os
from clinica.utils.stream import cprint
try:
nifti_matlib_toolbox = os.environ.get('NIFTI_MATLIB_TOOLBOX', '')
if not nifti_matlib_toolbox:
raise RuntimeError('NIFTI_MATLIB_TOOLBOX variable is not set')
except Exception as e:
cprint(str(e))
cprint('Niftimatlib toolbox has been detected')
return nifti_matlib_toolbox
def check_fsl():
"""
Check FSL software.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment