def test_MS_LDA_outputs(): output_map = dict(vol_synth_file=dict(), weight_file=dict()) outputs = MS_LDA.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_MS_LDA_outputs(): output_map = dict(vol_synth_file=dict(), weight_file=dict(), ) outputs = MS_LDA.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_MS_LDA_inputs(): input_map = dict(ignore_exception=dict(nohash=True, usedefault=True, ), conform=dict(argstr='-conform', ), weight_file=dict(mandatory=True, argstr='-weight %s', ), lda_labels=dict(mandatory=True, sep=' ', argstr='-lda %s', ), output_synth=dict(new_name='vol_synth_file', mandatory=True, xor=['vol_synth_file', 'output_synth'], deprecated='0.8', argstr='-synth %s', ), vol_synth_file=dict(mandatory=True, argstr='-synth %s', xor=['vol_synth_file', 'output_synth'], ), shift=dict(argstr='-shift %d', ), args=dict(argstr='%s', ), mask_file=dict(argstr='-mask %s', ), terminal_output=dict(mandatory=True, nohash=True, ), environ=dict(nohash=True, usedefault=True, ), label_file=dict(argstr='-label %s', ), subjects_dir=dict(), images=dict(copyfile=False, mandatory=True, position=-1, argstr='%s', ), use_weights=dict(argstr='-W', ), ) inputs = MS_LDA.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_MS_LDA_inputs(): input_map = dict(args=dict(argstr='%s', ), conform=dict(argstr='-conform', ), environ=dict(nohash=True, usedefault=True, ), ignore_exception=dict(nohash=True, usedefault=True, ), images=dict(argstr='%s', copyfile=False, mandatory=True, position=-1, ), label_file=dict(argstr='-label %s', ), lda_labels=dict(argstr='-lda %s', mandatory=True, sep=' ', ), mask_file=dict(argstr='-mask %s', ), shift=dict(argstr='-shift %d', ), subjects_dir=dict(), terminal_output=dict(mandatory=True, nohash=True, ), use_weights=dict(argstr='-W', ), vol_synth_file=dict(argstr='-synth %s', mandatory=True, ), weight_file=dict(argstr='-weight %s', mandatory=True, ), ) inputs = MS_LDA.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_MS_LDA_inputs(): input_map = dict( args=dict(argstr="%s"), conform=dict(argstr="-conform"), environ=dict(nohash=True, usedefault=True), ignore_exception=dict(nohash=True, usedefault=True), images=dict(argstr="%s", copyfile=False, mandatory=True, position=-1), label_file=dict(argstr="-label %s"), lda_labels=dict(argstr="-lda %s", mandatory=True, sep=" "), mask_file=dict(argstr="-mask %s"), shift=dict(argstr="-shift %d"), subjects_dir=dict(), terminal_output=dict(mandatory=True, nohash=True), use_weights=dict(argstr="-W"), vol_synth_file=dict(argstr="-synth %s", mandatory=True), weight_file=dict(argstr="-weight %s", mandatory=True), ) inputs = MS_LDA.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 CreateFreeSurferWorkflow_custom(projectid, subjectid, sessionid, WFname, CLUSTER_QUEUE, CLUSTER_QUEUE_LONG, RunAllFSComponents=True, RunMultiMode=True, constructed_FS_SUBJECTS_DIR='/never_use_this'): freesurferWF = pe.Workflow(name=GenerateWFName(projectid, subjectid, sessionid, WFname)) inputsSpec = pe.Node(interface=IdentityInterface(fields=['subj_session_id', 'T1_files', 'T2_files', 'subjects_dir', 'wm_prob', 'label_file', 'mask_file']), name='inputspec') outputsSpec = pe.Node(interface=IdentityInterface(fields=['full_path_FS_output', 'processed_output_name', 'cnr_optimal_image']), name='outputspec') ### HACK: the nipype interface requires that this environmental variable is set before running print "HACK SETTING SUBJECTS_DIR {0}".format(constructed_FS_SUBJECTS_DIR) os.environ['SUBJECTS_DIR'] = constructed_FS_SUBJECTS_DIR inputsSpec.inputs.subjects_dir = constructed_FS_SUBJECTS_DIR # HACK if RunMultiMode: mergeT1T2 = pe.Node(interface=Merge(2), name="Merge_T1T2") freesurferWF.connect(inputsSpec, 'T1_files', mergeT1T2, 'in1') freesurferWF.connect(inputsSpec, 'T2_files', mergeT1T2, 'in2') # Some constants based on assumpts about the label_file from BRAINSABC white_label = 1 grey_label = 2 msLDA_GenerateWeights = pe.Node(interface=MS_LDA(), name="MS_LDA") MSLDA_sge_options_dictionary = {'qsub_args': '-S /bin/bash -pe smp 4 -l h_vmem=12G,mem_free=2G -o /dev/null -e /dev/null ' + CLUSTER_QUEUE, 'overwrite': True} msLDA_GenerateWeights.plugin_args = MSLDA_sge_options_dictionary msLDA_GenerateWeights.inputs.lda_labels = [white_label, grey_label] msLDA_GenerateWeights.inputs.weight_file = 'weights.txt' msLDA_GenerateWeights.inputs.use_weights = False msLDA_GenerateWeights.inputs.vol_synth_file = 'synth_out.nii.gz' # msLDA_GenerateWeights.inputs.vol_synth_file = 'synth_out.nii.gz' # msLDA_GenerateWeights.inputs.shift = 0 # value to shift by freesurferWF.connect(mergeT1T2, 'out', msLDA_GenerateWeights, 'images') # freesurferWF.connect(inputsSpec,'subjects_dir', msLDA_GenerateWeights,'subjects_dir') freesurferWF.connect(inputsSpec, 'label_file', msLDA_GenerateWeights, 'label_file') # freesurferWF.connect(inputsSpec,'mask_file', msLDA_GenerateWeights,'mask_file') ## Mask file MUST be unsigned char freesurferWF.connect(msLDA_GenerateWeights, 'vol_synth_file', outputsSpec, 'cnr_optimal_image') if RunAllFSComponents == True: print("""Run FreeSurfer ReconAll at""") fs_reconall = pe.Node(interface=fswrap.FSScript(), name="FS52_cross_" + str(sessionid)) freesurfer_sge_options_dictionary = {'qsub_args': '-S /bin/bash -pe smp 4 -l h_vmem=10G,mem_free=10G ' + CLUSTER_QUEUE, 'overwrite': True} fs_reconall.plugin_args = freesurfer_sge_options_dictionary fs_reconall.inputs.subcommand = 'autorecon' # fs_reconall.inputs.directive = 'all' # fs_reconall.inputs.fs_env_script = '' # NOTE: NOT NEEDED HERE 'FreeSurferEnv.sh' # fs_reconall.inputs.fs_home = '' # NOTE: NOT NEEDED HERE freesurferWF.connect(inputsSpec, 'subj_session_id', fs_reconall, 'subj_session_id') if RunMultiMode: ## Use the output of the synthesized T1 with maximized contrast ## HACK: REMOVE FOR NOW - NEEDS FURTHER TESTING ## freesurferWF.connect(msLDA_GenerateWeights, 'vol_synth_file', fs_reconall, 'T1_files') freesurferWF.connect(inputsSpec, 'T1_files', fs_reconall, 'T1_files') ## END HACK else: ## Use the output of the T1 only image freesurferWF.connect(inputsSpec, 'T1_files', fs_reconall, 'T1_files') freesurferWF.connect(inputsSpec, 'label_file', fs_reconall, 'brainmask') freesurferWF.connect(inputsSpec, 'subjects_dir', fs_reconall, 'subjects_dir') freesurferWF.connect(fs_reconall, 'outDir', outputsSpec, 'full_path_FS_output') freesurferWF.connect(fs_reconall, 'processed_output_name', outputsSpec, 'processed_output_name') return freesurferWF
def create_free_surfer_workflow_custom( projectid, subjectid, sessionid, WFname, CLUSTER_QUEUE, CLUSTER_QUEUE_LONG, RunAllFSComponents=True, RunMultiMode=True, constructed_FS_SUBJECTS_DIR="/never_use_this", ): """ This function... :param projectid: :param subjectid: :param sessionid: :param WFname: :param CLUSTER_QUEUE: :param CLUSTER_QUEUE_LONG: :param RunAllFSComponents: True :param RunMultiMode: True :param constructed_FS_SUBJECTS_DIR: '/never_use_this' :return: """ freesurferWF = pe.Workflow( name=generate_wf_name(projectid, subjectid, sessionid, WFname)) inputsSpec = pe.Node( interface=IdentityInterface(fields=[ "subj_session_id", "T1_files", "T2_files", "subjects_dir", "wm_prob", "label_file", "mask_file", ]), name="inputspec", ) outputsSpec = pe.Node( interface=IdentityInterface(fields=[ "full_path_FS_output", "processed_output_name", "cnr_optimal_image" ]), name="outputspec", ) ### HACK: the nipype interface requires that this environmental variable is set before running print( ("HACK SETTING SUBJECTS_DIR {0}".format(constructed_FS_SUBJECTS_DIR))) os.environ["SUBJECTS_DIR"] = constructed_FS_SUBJECTS_DIR inputsSpec.inputs.subjects_dir = constructed_FS_SUBJECTS_DIR # HACK if RunMultiMode: mergeT1T2 = pe.Node(interface=Merge(2), name="Merge_T1T2") freesurferWF.connect(inputsSpec, "T1_files", mergeT1T2, "in1") freesurferWF.connect(inputsSpec, "T2_files", mergeT1T2, "in2") # Some constants based on assumpts about the label_file from BRAINSABC white_label = 1 grey_label = 2 msLDA_GenerateWeights = pe.Node(interface=MS_LDA(), name="MS_LDA") MSLDA_sge_options_dictionary = { "qsub_args": modify_qsub_args(CLUSTER_QUEUE, 2, 1, 1), "overwrite": True, } msLDA_GenerateWeights.plugin_args = MSLDA_sge_options_dictionary msLDA_GenerateWeights.inputs.lda_labels = [white_label, grey_label] msLDA_GenerateWeights.inputs.weight_file = "weights.txt" msLDA_GenerateWeights.inputs.use_weights = False msLDA_GenerateWeights.inputs.vol_synth_file = "synth_out.nii.gz" # msLDA_GenerateWeights.inputs.vol_synth_file = 'synth_out.nii.gz' # msLDA_GenerateWeights.inputs.shift = 0 # value to shift by freesurferWF.connect(mergeT1T2, "out", msLDA_GenerateWeights, "images") # freesurferWF.connect(inputsSpec,'subjects_dir', msLDA_GenerateWeights,'subjects_dir') freesurferWF.connect(inputsSpec, "label_file", msLDA_GenerateWeights, "label_file") # freesurferWF.connect(inputsSpec,'mask_file', msLDA_GenerateWeights,'mask_file') ## Mask file MUST be unsigned char freesurferWF.connect(msLDA_GenerateWeights, "vol_synth_file", outputsSpec, "cnr_optimal_image") if RunAllFSComponents == True: print("""Run FreeSurfer ReconAll at""") fs_reconall = pe.Node(interface=fswrap.FSScript(), name="FS52_cross_" + str(sessionid)) freesurfer_sge_options_dictionary = { "qsub_args": modify_qsub_args(CLUSTER_QUEUE, 8, 4, 4), "overwrite": True, } fs_reconall.plugin_args = freesurfer_sge_options_dictionary fs_reconall.inputs.subcommand = "autorecon" # fs_reconall.inputs.directive = 'all' # fs_reconall.inputs.fs_env_script = '' # NOTE: NOT NEEDED HERE 'FreeSurferEnv.sh' # fs_reconall.inputs.fs_home = '' # NOTE: NOT NEEDED HERE freesurferWF.connect(inputsSpec, "subj_session_id", fs_reconall, "subj_session_id") if RunMultiMode: ## Use the output of the synthesized T1 with maximized contrast ## HACK: REMOVE FOR NOW - NEEDS FURTHER TESTING ## freesurferWF.connect(msLDA_GenerateWeights, 'vol_synth_file', fs_reconall, 'T1_files') freesurferWF.connect(inputsSpec, "T1_files", fs_reconall, "T1_files") ## END HACK else: ## Use the output of the T1 only image freesurferWF.connect(inputsSpec, "T1_files", fs_reconall, "T1_files") freesurferWF.connect(inputsSpec, "label_file", fs_reconall, "brainmask") freesurferWF.connect(inputsSpec, "subjects_dir", fs_reconall, "subjects_dir") freesurferWF.connect(fs_reconall, "outDir", outputsSpec, "full_path_FS_output") freesurferWF.connect(fs_reconall, "processed_output_name", outputsSpec, "processed_output_name") return freesurferWF