def rs_grouplevel(z, prefix, output_dir, work_dir): from nipype.interfaces.fsl.model import Randomise from nipype.interfaces import fsl as fsl merger = fsl.utils.Merge() merger.inputs.in_files = z merger.inputs.dimension = 't' merger.inputs.merged_file = op.join(work_dir, 'z_merge.nii.gz') merger.run() immaths = fsl.utils.ImageMaths() immaths.inputs.in_file = op.join(work_dir, 'z_merge.nii.gz') immaths.inputs.op_string = "-abs -bin -Tmin" immaths.inputs.out_file = op.join(work_dir, 'mask.nii.gz') immaths.run() masker = fsl.maths.ApplyMask() masker.inputs.in_file = op.join(work_dir, 'z_merge.nii.gz') masker.inputs.mask_file = op.join(work_dir, 'mask.nii.gz') masker.inputs.out_file = op.join(work_dir, 'z_merge.nii.gz') masker.run() meaner = fsl.utils.ImageMaths() meaner.inputs.in_file = op.join(work_dir, 'z_merge.nii.gz') meaner.inputs.op_string = "-Tmean" meaner.inputs.out_file = op.join(work_dir, 'z.nii.gz') meaner.run() shutil.copyfile(op.join(work_dir, 'z.nii.gz'), op.join(output_dir, '{prefix}_z.nii.gz'.format(prefix=prefix))) randomise = Randomise() randomise.inputs.in_file = op.join(work_dir, 'z_merge.nii.gz') randomise.inputs.mask = op.join(work_dir, 'mask.nii.gz') randomise.inputs.one_sample_group_mean = True randomise.inputs.raw_stats_imgs = True randomise.inputs.vox_p_values = True randomise.inputs.base_name = 'randomise' os.chdir(work_dir) randomise.run() thresher = fsl.utils.ImageMaths() thresher.inputs.in_file = op.join(work_dir, 'randomise_vox_corrp_tstat1.nii.gz') thresher.inputs.op_string = "-thr 0.999" thresher.inputs.out_file = op.join(work_dir, 'randomise_vox_corrp_tstat1_thr001.nii.gz') thresher.run() masker = fsl.maths.ApplyMask() masker.inputs.in_file = op.join(work_dir, 'randomise_tstat1.nii.gz') masker.inputs.mask_file = op.join(work_dir, 'randomise_vox_corrp_tstat1_thr001.nii.gz') masker.inputs.out_file = op.join(work_dir, 'randomise_tstat1_thr001.nii.gz') masker.run() #copy data to directory vox_corrp_tstat1.nii.gz shutil.copyfile(op.join(work_dir, 'randomise_tstat1.nii.gz'), op.join(output_dir, '{prefix}_tstat1.nii.gz'.format(prefix=prefix))) shutil.copyfile(op.join(work_dir, 'randomise_vox_corrp_tstat1.nii.gz'), op.join(output_dir, '{prefix}_vox_corrp.nii.gz'.format(prefix=prefix))) shutil.copyfile(op.join(work_dir, 'randomise_tstat1_thr001.nii.gz'), op.join(output_dir, '{prefix}_tstat1_thr001.nii.gz'.format(prefix=prefix))) shutil.rmtree(work_dir)
def test_Randomise_inputs(): input_map = dict( args=dict(argstr='%s', ), base_name=dict( argstr='-o "%s"', position=1, usedefault=True, ), c_thresh=dict(argstr='-c %.2f', ), cm_thresh=dict(argstr='-C %.2f', ), demean=dict(argstr='-D', ), design_mat=dict( argstr='-d %s', position=2, ), environ=dict( nohash=True, usedefault=True, ), f_c_thresh=dict(argstr='-F %.2f', ), f_cm_thresh=dict(argstr='-S %.2f', ), f_only=dict(argstr='--f_only', ), fcon=dict(argstr='-f %s', ), ignore_exception=dict( nohash=True, usedefault=True, ), in_file=dict( argstr='-i %s', mandatory=True, position=0, ), mask=dict(argstr='-m %s', ), num_perm=dict(argstr='-n %d', ), one_sample_group_mean=dict(argstr='-1', ), output_type=dict(), p_vec_n_dist_files=dict(argstr='-P', ), raw_stats_imgs=dict(argstr='-R', ), seed=dict(argstr='--seed=%d', ), show_info_parallel_mode=dict(argstr='-Q', ), show_total_perms=dict(argstr='-q', ), tcon=dict( argstr='-t %s', position=3, ), terminal_output=dict(nohash=True, ), tfce=dict(argstr='-T', ), tfce2D=dict(argstr='--T2', ), tfce_C=dict(argstr='--tfce_C=%.2f', ), tfce_E=dict(argstr='--tfce_E=%.2f', ), tfce_H=dict(argstr='--tfce_H=%.2f', ), var_smooth=dict(argstr='-v %d', ), vox_p_values=dict(argstr='-x', ), x_block_labels=dict(argstr='-e %s', ), ) inputs = Randomise.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_Randomise_outputs(): output_map = dict(tstat_files=dict(), t_p_files=dict(), f_p_files=dict(), f_corrected_p_files=dict(), t_corrected_p_files=dict(), fstat_files=dict(), ) outputs = Randomise.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_Randomise_outputs(): output_map = dict( f_corrected_p_files=dict(), f_p_files=dict(), fstat_files=dict(), t_corrected_p_files=dict(), t_p_files=dict(), tstat_files=dict(), ) outputs = Randomise.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_Randomise_inputs(): input_map = dict( args=dict(argstr="%s"), base_name=dict(argstr='-o "%s"', position=1, usedefault=True), c_thresh=dict(argstr="-c %.2f"), cm_thresh=dict(argstr="-C %.2f"), demean=dict(argstr="-D"), design_mat=dict(argstr="-d %s", position=2), environ=dict(nohash=True, usedefault=True), f_c_thresh=dict(argstr="-F %.2f"), f_cm_thresh=dict(argstr="-S %.2f"), f_only=dict(argstr="--f_only"), fcon=dict(argstr="-f %s"), ignore_exception=dict(nohash=True, usedefault=True), in_file=dict(argstr="-i %s", mandatory=True, position=0), mask=dict(argstr="-m %s"), num_perm=dict(argstr="-n %d"), one_sample_group_mean=dict(argstr="-1"), output_type=dict(), p_vec_n_dist_files=dict(argstr="-P"), raw_stats_imgs=dict(argstr="-R"), seed=dict(argstr="--seed=%d"), show_info_parallel_mode=dict(argstr="-Q"), show_total_perms=dict(argstr="-q"), tcon=dict(argstr="-t %s", position=3), terminal_output=dict(nohash=True), tfce=dict(argstr="-T"), tfce2D=dict(argstr="--T2"), tfce_C=dict(argstr="--tfce_C=%.2f"), tfce_E=dict(argstr="--tfce_E=%.2f"), tfce_H=dict(argstr="--tfce_H=%.2f"), var_smooth=dict(argstr="-v %d"), vox_p_values=dict(argstr="-x"), x_block_labels=dict(argstr="-e %s"), ) inputs = Randomise.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
base_directory=output_dir, template='glm_seed_copes/%s_*/cope.nii', field_template=templates, template_args=dict(roi=[['roi']])), name='datagrabber') # In[ ]: ## Level 2 # merge param estimates across all subjects per seed merge = Node(Merge(dimension='t'), name='merge') # FSL randomise for higher level analysis highermodel = Node(Randomise(tfce=True, raw_stats_imgs=True, design_mat=group_mat, tcon=group_con), name='highermodel') ## Cluster results # make binary masks of sig clusters binarize = Node(Binarize(min=0.95, max=1.0), name='binarize', iterfield='in_file') # mask T-map before clustering mask_tmaps = Node(ApplyMask(), name='mask_tmaps') # clusterize and extract cluster stats/peaks clusterize = Node(Cluster(threshold=2.3,
def test_Randomise_inputs(): input_map = dict(one_sample_group_mean=dict(argstr='-1', ), vox_p_values=dict(argstr='-x', ), show_total_perms=dict(argstr='-q', ), tfce2D=dict(argstr='--T2', ), tfce_H=dict(argstr='--tfce_H=%.2f', ), p_vec_n_dist_files=dict(argstr='-P', ), cm_thresh=dict(argstr='-C %.2f', ), f_only=dict(argstr='--f_only', ), environ=dict(nohash=True, usedefault=True, ), in_file=dict(position=0, mandatory=True, argstr='-i %s', ), ignore_exception=dict(nohash=True, usedefault=True, ), f_cm_thresh=dict(argstr='-S %.2f', ), tfce=dict(argstr='-T', ), tfce_E=dict(argstr='--tfce_E=%.2f', ), args=dict(argstr='%s', ), tfce_C=dict(argstr='--tfce_C=%.2f', ), raw_stats_imgs=dict(argstr='-R', ), terminal_output=dict(mandatory=True, nohash=True, ), var_smooth=dict(argstr='-v %d', ), design_mat=dict(position=2, argstr='-d %s', ), tcon=dict(position=3, argstr='-t %s', ), show_info_parallel_mode=dict(argstr='-Q', ), base_name=dict(position=1, usedefault=True, argstr='-o "%s"', ), f_c_thresh=dict(argstr='-F %.2f', ), num_perm=dict(argstr='-n %d', ), mask=dict(argstr='-m %s', ), c_thresh=dict(argstr='-c %.2f', ), x_block_labels=dict(argstr='-e %s', ), seed=dict(argstr='--seed=%d', ), demean=dict(argstr='-D', ), output_type=dict(), fcon=dict(argstr='-f %s', ), ) inputs = Randomise.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value