def test_DARTEL_inputs(): input_map = dict( ignore_exception=dict( nohash=True, usedefault=True, ), image_files=dict( copyfile=False, field='warp.images', mandatory=True, ), iteration_parameters=dict(field='warp.settings.param', ), matlab_cmd=dict(), mfile=dict(usedefault=True, ), optimization_parameters=dict(field='warp.settings.optim', ), paths=dict(), regularization_form=dict(field='warp.settings.rform', ), template_prefix=dict( field='warp.settings.template', usedefault=True, ), use_mcr=dict(), use_v8struct=dict( min_ver='8', usedefault=True, ), ) inputs = DARTEL.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_DARTEL_inputs(): input_map = dict(ignore_exception=dict(nohash=True, usedefault=True, ), paths=dict(), iteration_parameters=dict(field='warp.settings.param', ), use_v8struct=dict(min_ver='8', usedefault=True, ), use_mcr=dict(), template_prefix=dict(field='warp.settings.template', usedefault=True, ), image_files=dict(copyfile=False, mandatory=True, field='warp.images', ), matlab_cmd=dict(), optimization_parameters=dict(field='warp.settings.optim', ), mfile=dict(usedefault=True, ), regularization_form=dict(field='warp.settings.rform', ), ) inputs = DARTEL.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_DARTEL_outputs(): output_map = dict(dartel_flow_fields=dict(), final_template_file=dict(), template_files=dict()) outputs = DARTEL.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def test_DARTEL_outputs(): output_map = dict( dartel_flow_fields=dict(), final_template_file=dict(), template_files=dict(), ) outputs = DARTEL.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def create_DARTEL_wf(subj_list, file_template, work_dir, out_dir): ''' Aligns all images to a template (average of all images), then warps images into MNI space (using an SPM tissue probability map, see https://www.fil.ion.ucl.ac.uk/spm/doc/manual.pdf, section 25.4). subj_list: list of subject IDs e.g. [sub-001, sub-002] file_template: string to identify all files to align (using glob). e.g. file_template = os.path.join(work_dir, 'pag_mask', '*_pag_mask.nii') The template can identify a larger set of files, and the subject_list will grab a subset. e.g. The template may grab sub-001, sub-002, sub-003 ... But if the subject_list only includes sub-001, then only sub-001 will be used. This means the template can overgeneralize, but specific subjects can be easily excluded (e.g. for movement) work_dir: string, denoting path to working directory. out_dir: string, denoting output directory (results saved to work directory and output) ''' import nibabel as nib import numpy as np from nipype.interfaces.spm.preprocess import DARTEL, CreateWarped from nipype.interfaces.io import DataSink import nipype.pipeline.engine as pe import os from jtnipyutil.util import files_from_template # set up workflow. DARTEL_wf = pe.Workflow(name='DARTEL_wf') DARTEL_wf.base_dir = work_dir # get images images = files_from_template(subj_list, file_template) # set up DARTEL. dartel = pe.Node(interface=DARTEL(), name='dartel') dartel.inputs.image_files = [images] dartel_warp = pe.Node(interface=CreateWarped(), name='dartel_warp') dartel_warp.inputs.image_files = images # warp_data.inputs.flowfield_files = # from inputspec ################## Setup datasink. sinker = pe.Node(DataSink(parameterization=True), name='sinker') sinker.inputs.base_directory = out_dir DARTEL_wf.connect([ (dartel, dartel_warp, [('dartel_flow_fields', 'flowfield_files')]), (dartel, sinker, [('final_template_file', 'avg_template'), ('template_files', 'avg_template.@template_stages'), ('dartel_flow_fields', 'dartel_flow')]), (dartel_warp, sinker, [('warped_files', 'warped_PAG')]) ]) return DARTEL_wf