def run_resample( in_file, ref_file, transform, out_file, interpolation_mode="Linear", pixel_type="float", inverse_transform=True, ): """ This function... :param in_file: :param ref_file: :param transform: :param out_file: :param interpolation_mode: :param pixel_type: :param inverse_transform: :return: """ resample = BRAINSResample() resample.inputs.inputVolume = in_file resample.inputs.warpTransform = transform resample.inputs.pixelType = pixel_type resample.inputs.interpolationMode = interpolation_mode resample.inputs.outputVolume = os.path.abspath(out_file) resample.inputs.referenceVolume = ref_file resample.inputs.inverseTransform = inverse_transform result = resample.run() return result.outputs.outputVolume
def run_resample(in_file, ref_file, transform, out_file, interpolation_mode='Linear', pixel_type='float', inverse_transform=True): resample = BRAINSResample() resample.inputs.inputVolume = in_file resample.inputs.warpTransform = transform resample.inputs.pixelType = pixel_type resample.inputs.interpolationMode = interpolation_mode resample.inputs.outputVolume = os.path.abspath(out_file) resample.inputs.referenceVolume = ref_file resample.inputs.inverseTransform = inverse_transform result = resample.run() return result.outputs.outputVolume
def create_workflow_to_resample_baw_files(name="ResampleBAWOutputs"): """ This function... :param name: :return: """ workflow = Workflow(name) inputs_to_resample = ["t1_file", "t2_file", "hncma_file", "abc_file"] other_inputs = ["reference_file", "acpc_transform"] label_maps = ["hncma_file", "abc_file"] input_spec = Node(IdentityInterface(inputs_to_resample + other_inputs), name="input_spec") output_spec = Node(IdentityInterface(inputs_to_resample), name="output_spec") for input in inputs_to_resample: node = Node(BRAINSResample(), "Resample_{0}".format(input)) node.inputs.pixelType = "short" node.inputs.inverseTransform = True node.inputs.outputVolume = input + ".nii.gz" if input in label_maps: node.inputs.interpolationMode = "NearestNeighbor" workflow.connect([ (input_spec, node, [("reference_file", "referenceVolume"), ("acpc_transform", "warpTransform"), ("{0}".format(input), "inputVolume")]), (node, output_spec, [("outputVolume", "{0}".format(input))]) ]) return workflow
def create_logb_workflow(name="LOGISMOSB_WF", master_config=None, plugin_args=None): logb_wf = Workflow(name=name) config = read_json_config("config.json") config['atlas_info'] = get_local_file_location(config['atlas_info']) inputs_node = Node(IdentityInterface(fields=[ 't1_file', 't2_file', 'posterior_files', 'joint_fusion_file', 'brainlabels_file', 'hncma_atlas' ]), name="inputspec") inputs_node.run_without_submitting = True # ensure that t1 and t2 are in the same voxel lattice input_t2 = Node(BRAINSResample(), "ResampleInputT2Volume") input_t2.inputs.outputVolume = "t2_resampled.nii.gz" input_t2.inputs.pixelType = 'ushort' input_t2.inputs.interpolationMode = "Linear" logb_wf.connect([(inputs_node, input_t2, [('t1_file', 'referenceVolume'), ('t2_file', 'inputVolume')])]) white_matter_masking_node = Node(interface=WMMasking(), name="WMMasking") white_matter_masking_node.inputs.dilation = config['WMMasking']['dilation'] white_matter_masking_node.inputs.csf_threshold = config['WMMasking'][ 'csf_threshold'] if master_config and master_config['labelmap_colorlookup_table']: white_matter_masking_node.inputs.atlas_info = master_config[ 'labelmap_colorlookup_table'] else: white_matter_masking_node.inputs.atlas_info = config['atlas_info'] logb_wf.connect([(inputs_node, white_matter_masking_node, [("posterior_files", "posterior_files"), ("joint_fusion_file", "atlas_file"), ("brainlabels_file", "brainlabels_file"), ("hncma_atlas", "hncma_file")])]) gm_labels = Node(interface=CreateGMLabelMap(), name="GM_Labelmap") gm_labels.inputs.atlas_info = config['atlas_info'] logb_wf.connect([(inputs_node, gm_labels, [('joint_fusion_file', 'atlas_file')])]) logismosb_output_node = create_output_spec( ["wmsurface_file", "gmsurface_file"], config["hemisphere_names"], name="outputspec") for hemisphere in config["hemisphere_names"]: genus_zero_filter = Node( interface=GenusZeroImageFilter(), name="{0}_GenusZeroImageFilter".format(hemisphere)) genus_zero_filter.inputs.connectivity = config['GenusZeroImageFilter'][ 'connectivity'] genus_zero_filter.inputs.biggestComponent = config[ 'GenusZeroImageFilter']['biggestComponent'] genus_zero_filter.inputs.connectedComponent = config[ 'GenusZeroImageFilter']['connectedComponent'] genus_zero_filter.inputs.out_mask = "{0}_genus_zero_white_matter.nii.gz".format( hemisphere) logb_wf.connect([(white_matter_masking_node, genus_zero_filter, [('{0}_wm'.format(hemisphere), 'in_file')])]) surface_generation = Node( interface=BRAINSSurfaceGeneration(), name="{0}_BRAINSSurfaceGeneration".format(hemisphere)) surface_generation.inputs.smoothSurface = config[ 'BRAINSSurfaceGeneration']['smoothSurface'] surface_generation.inputs.numIterations = config[ 'BRAINSSurfaceGeneration']['numIterations'] surface_generation.inputs.out_file = "{0}_white_matter_surface.vtk".format( hemisphere) logb_wf.connect([(genus_zero_filter, surface_generation, [('out_file', 'in_file')])]) logismosb = Node(interface=LOGISMOSB(), name="{0}_LOGISMOSB".format(hemisphere)) logismosb.inputs.smoothnessConstraint = config['LOGISMOSB'][ 'smoothnessConstraint'] logismosb.inputs.nColumns = config['LOGISMOSB']['nColumns'] logismosb.inputs.columnChoice = config['LOGISMOSB']['columnChoice'] logismosb.inputs.columnHeight = config['LOGISMOSB']['columnHeight'] logismosb.inputs.nodeSpacing = config['LOGISMOSB']['nodeSpacing'] logismosb.inputs.w = config['LOGISMOSB']['w'] logismosb.inputs.a = config['LOGISMOSB']['a'] logismosb.inputs.nPropagate = config['LOGISMOSB']['nPropagate'] logismosb.inputs.basename = hemisphere if config['LOGISMOSB']['thickRegions']: logismosb.inputs.thick_regions = config['LOGISMOSB'][ 'thickRegions'] else: logismosb.inputs.useHNCMALabels = True if plugin_args: logismosb.plugin_args = plugin_args logb_wf.connect([ (inputs_node, logismosb, [("t1_file", "t1_file"), ('hncma_atlas', 'atlas_file')]), (input_t2, logismosb, [("outputVolume", "t2_file")]), (genus_zero_filter, logismosb, [("out_file", "wm_file")]), (surface_generation, logismosb, [("out_file", "mesh_file")]), (white_matter_masking_node, logismosb, [('{0}_boundary'.format(hemisphere), 'brainlabels_file')]), (logismosb, logismosb_output_node, [("gmsurface_file", "{0}_gmsurface_file".format(hemisphere)), ("wmsurface_file", "{0}_wmsurface_file".format(hemisphere))]) ]) return logb_wf
def create_logb_workflow(name="LOGISMOSB_WF", master_config=None, plugin_args=None): """ This function... :param name: :param master_config: :param plugin_args: :return: """ logb_wf = Workflow(name=name) config = read_json_config("config.json") config["atlas_info"] = get_local_file_location(config["atlas_info"]) inputs_node = Node( IdentityInterface( fields=[ "t1_file", "t2_file", "posterior_files", "joint_fusion_file", "brainlabels_file", "hncma_atlas", ] ), name="inputspec", ) inputs_node.run_without_submitting = True # ensure that t1 and t2 are in the same voxel lattice input_t2 = Node(BRAINSResample(), "ResampleInputT2Volume") input_t2.inputs.outputVolume = "t2_resampled.nii.gz" input_t2.inputs.pixelType = "ushort" input_t2.inputs.interpolationMode = "Linear" logb_wf.connect( [ ( inputs_node, input_t2, [("t1_file", "referenceVolume"), ("t2_file", "inputVolume")], ) ] ) white_matter_masking_node = Node(interface=WMMasking(), name="WMMasking") white_matter_masking_node.inputs.dilation = config["WMMasking"]["dilation"] white_matter_masking_node.inputs.csf_threshold = config["WMMasking"][ "csf_threshold" ] if master_config and master_config["labelmap_colorlookup_table"]: white_matter_masking_node.inputs.atlas_info = master_config[ "labelmap_colorlookup_table" ] else: white_matter_masking_node.inputs.atlas_info = config["atlas_info"] logb_wf.connect( [ ( inputs_node, white_matter_masking_node, [ ("posterior_files", "posterior_files"), ("joint_fusion_file", "atlas_file"), ("brainlabels_file", "brainlabels_file"), ("hncma_atlas", "hncma_file"), ], ) ] ) gm_labels = Node(interface=CreateGMLabelMap(), name="GM_Labelmap") gm_labels.inputs.atlas_info = config["atlas_info"] logb_wf.connect([(inputs_node, gm_labels, [("joint_fusion_file", "atlas_file")])]) logismosb_output_node = create_output_spec( ["wmsurface_file", "gmsurface_file"], config["hemisphere_names"], name="outputspec", ) for hemisphere in config["hemisphere_names"]: genus_zero_filter = Node( interface=GenusZeroImageFilter(), name="{0}_GenusZeroImageFilter".format(hemisphere), ) genus_zero_filter.inputs.connectivity = config["GenusZeroImageFilter"][ "connectivity" ] genus_zero_filter.inputs.biggestComponent = config["GenusZeroImageFilter"][ "biggestComponent" ] genus_zero_filter.inputs.connectedComponent = config["GenusZeroImageFilter"][ "connectedComponent" ] genus_zero_filter.inputs.out_mask = "{0}_genus_zero_white_matter.nii.gz".format( hemisphere ) logb_wf.connect( [ ( white_matter_masking_node, genus_zero_filter, [("{0}_wm".format(hemisphere), "in_file")], ) ] ) surface_generation = Node( interface=BRAINSSurfaceGeneration(), name="{0}_BRAINSSurfaceGeneration".format(hemisphere), ) surface_generation.inputs.smoothSurface = config["BRAINSSurfaceGeneration"][ "smoothSurface" ] surface_generation.inputs.numIterations = config["BRAINSSurfaceGeneration"][ "numIterations" ] surface_generation.inputs.out_file = "{0}_white_matter_surface.vtk".format( hemisphere ) logb_wf.connect( [(genus_zero_filter, surface_generation, [("out_file", "in_file")])] ) logismosb = Node(interface=LOGISMOSB(), name="{0}_LOGISMOSB".format(hemisphere)) logismosb.inputs.smoothnessConstraint = config["LOGISMOSB"][ "smoothnessConstraint" ] logismosb.inputs.nColumns = config["LOGISMOSB"]["nColumns"] logismosb.inputs.columnChoice = config["LOGISMOSB"]["columnChoice"] logismosb.inputs.columnHeight = config["LOGISMOSB"]["columnHeight"] logismosb.inputs.nodeSpacing = config["LOGISMOSB"]["nodeSpacing"] logismosb.inputs.w = config["LOGISMOSB"]["w"] logismosb.inputs.a = config["LOGISMOSB"]["a"] logismosb.inputs.nPropagate = config["LOGISMOSB"]["nPropagate"] logismosb.inputs.basename = hemisphere if config["LOGISMOSB"]["thickRegions"]: logismosb.inputs.thick_regions = config["LOGISMOSB"]["thickRegions"] else: logismosb.inputs.useHNCMALabels = True if plugin_args: logismosb.plugin_args = plugin_args logb_wf.connect( [ ( inputs_node, logismosb, [("t1_file", "t1_file"), ("hncma_atlas", "atlas_file")], ), (input_t2, logismosb, [("outputVolume", "t2_file")]), (genus_zero_filter, logismosb, [("out_file", "wm_file")]), (surface_generation, logismosb, [("out_file", "mesh_file")]), ( white_matter_masking_node, logismosb, [("{0}_boundary".format(hemisphere), "brainlabels_file")], ), ( logismosb, logismosb_output_node, [ ("gmsurface_file", "{0}_gmsurface_file".format(hemisphere)), ("wmsurface_file", "{0}_wmsurface_file".format(hemisphere)), ], ), ] ) return logb_wf