Skip to content

Commit f136ed8

Browse files
authored
Merge pull request #1385 from FCP-INDI/monkey_improve
Monkey improve
2 parents 2b48241 + cb84012 commit f136ed8

File tree

6 files changed

+58
-25
lines changed

6 files changed

+58
-25
lines changed

CPAC/func_preproc/func_ingress.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,6 @@ def connect_func_ingress(workflow, strat_list, c, sub_dict, subject_id,
164164
as_module=True
165165
), name=workflow_name)
166166

167-
if "Selected Functional Volume" in c.func_reg_input:
168-
get_func_volume = pe.Node(interface=afni.Calc(),
169-
name='get_func_volume_{0}'.format(
170-
num_strat))
171-
172-
get_func_volume.inputs.set(
173-
expr='a',
174-
single_idx=c.func_reg_input_volume,
175-
outputtype='NIFTI_GZ'
176-
)
177-
workflow.connect(func_wf, 'outputspec.rest',
178-
get_func_volume, 'in_file_a')
179-
180167
# wire in the scan parameter workflow
181168
workflow.connect(func_wf, 'outputspec.scan_params',
182169
scan_params, 'data_config_scan_params')
@@ -205,9 +192,4 @@ def connect_func_ingress(workflow, strat_list, c, sub_dict, subject_id,
205192

206193
strat.set_leaf_properties(func_wf, 'outputspec.rest')
207194

208-
if "Selected Functional Volume" in c.func_reg_input:
209-
strat.update_resource_pool({
210-
'selected_func_volume': (get_func_volume, 'out_file')
211-
})
212-
213195
return (workflow, diff, blip, fmap_rp_list)

CPAC/func_preproc/func_preproc.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ def create_func_preproc(skullstrip_tool, motion_correct_tool,
796796
'mask',
797797
'skullstrip',
798798
'func_mean',
799+
'get_func_volume',
799800
'preprocessed',
800801
'preprocessed_median',
801802
'preprocessed_mask',
@@ -1296,7 +1297,35 @@ def create_func_preproc(skullstrip_tool, motion_correct_tool,
12961297
preproc.connect(skullstrip_func, 'outputspec.func_brain',
12971298
func_mean, 'in_file')
12981299

1299-
if config.n4_correct_mean_EPI :
1300+
if "Selected Functional Volume" in config.func_reg_input:
1301+
get_func_volume = pe.Node(interface=afni.Calc(),
1302+
name='get_func_volume')
1303+
1304+
get_func_volume.inputs.set(
1305+
expr='a',
1306+
single_idx=config.func_reg_input_volume,
1307+
outputtype='NIFTI_GZ'
1308+
)
1309+
preproc.connect(skullstrip_func, 'outputspec.func_brain',
1310+
get_func_volume, 'in_file_a')
1311+
1312+
if config.n4_correct_func_reg_input :
1313+
1314+
get_func_volume_n4_corrected = pe.Node(interface = ants.N4BiasFieldCorrection(dimension=3, copy_header=True, bspline_fitting_distance=200), shrink_factor=2,
1315+
name='get_func_volume_n4_corrected')
1316+
get_func_volume_n4_corrected.inputs.args = '-r True'
1317+
1318+
preproc.connect(get_func_volume, 'out_file',
1319+
get_func_volume_n4_corrected, 'input_image')
1320+
preproc.connect(get_func_volume_n4_corrected, 'output_image',
1321+
output_node, 'get_func_volume')
1322+
1323+
else:
1324+
preproc.connect(get_func_volume, 'out_file',
1325+
output_node, 'get_func_volume')
1326+
1327+
if config.n4_correct_func_reg_input :
1328+
13001329
func_mean_n4_corrected = pe.Node(interface = ants.N4BiasFieldCorrection(dimension=3, copy_header=True, bspline_fitting_distance=200), shrink_factor=2,
13011330
name='func_mean_n4_corrected')
13021331
func_mean_n4_corrected.inputs.args = '-r True'
@@ -1820,6 +1849,7 @@ def connect_func_preproc(workflow, strat_list, c, unique_id=None):
18201849

18211850
strat.update_resource_pool({
18221851
'mean_functional': (func_preproc, 'outputspec.func_mean'),
1852+
'selected_func_volume': (func_preproc, 'outputspec.get_func_volume'),
18231853
'functional_preprocessed_mask': (func_preproc, 'outputspec.preprocessed_mask'),
18241854
'functional_preprocessed': (func_preproc, 'outputspec.preprocessed'),
18251855
'functional_brain_mask': (func_preproc, 'outputspec.mask'),
@@ -1910,6 +1940,7 @@ def connect_func_preproc(workflow, strat_list, c, unique_id=None):
19101940
'motion_correction_method': motion_correct_tool,
19111941
'motion_correction_ref': motion_correct_ref,
19121942
'mean_functional': (func_preproc, 'outputspec.func_mean'),
1943+
'selected_func_volume': (func_preproc, 'outputspec.get_func_volume'),
19131944
'functional_preprocessed_mask': (func_preproc, 'outputspec.preprocessed_mask'),
19141945
'movement_parameters': (func_preproc, 'outputspec.movement_parameters'),
19151946
'max_displacement': (func_preproc, 'outputspec.max_displacement'),

CPAC/nuisance/nuisance.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ def create_regressor_workflow(nuisance_selectors,
628628
'lat_ventricles_mask_file_path',
629629
'functional_brain_mask_file_path',
630630
'func_to_anat_linear_xfm_file_path',
631+
'anat_to_func_linear_xfm_file_path',
631632
'mni_to_anat_linear_xfm_file_path',
632633
'anat_to_mni_initial_xfm_file_path',
633634
'anat_to_mni_rigid_xfm_file_path',
@@ -667,6 +668,7 @@ def create_regressor_workflow(nuisance_selectors,
667668

668669
"Transformations": {
669670
"func_to_anat_linear_xfm": (inputspec, "func_to_anat_linear_xfm_file_path"),
671+
"anat_to_func_linear_xfm": (inputspec, "anat_to_func_linear_xfm_file_path"),
670672
"mni_to_anat_linear_xfm": (inputspec, "mni_to_anat_linear_xfm_file_path"),
671673
"anat_to_mni_initial_xfm": (inputspec, "anat_to_mni_initial_xfm_file_path"),
672674
"anat_to_mni_rigid_xfm": (inputspec, "anat_to_mni_rigid_xfm_file_path"),

CPAC/nuisance/utils/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,18 +317,25 @@ def generate_summarize_tissue_mask(nuisance_wf,
317317
pass
318318

319319
elif step == 'resolution':
320-
321320
mask_to_epi = pe.Node(interface=fsl.FLIRT(),
322321
name='{}_flirt'
323322
.format(node_mask_key))
324323

325324
mask_to_epi.inputs.interp = 'nearestneighbour'
326325

327326
if regressor_selector['extraction_resolution'] == "Functional":
327+
# apply anat2func matrix
328+
mask_to_epi.inputs.apply_xfm = True
329+
mask_to_epi.inputs.output_type = 'NIFTI_GZ'
328330
nuisance_wf.connect(*(
329331
pipeline_resource_pool['Functional_mean'] +
330332
(mask_to_epi, 'reference')
331333
))
334+
nuisance_wf.connect(*(
335+
pipeline_resource_pool['Transformations']['anat_to_func_linear_xfm'] +
336+
(mask_to_epi, 'in_matrix_file')
337+
))
338+
332339
else:
333340
resolution = regressor_selector['extraction_resolution']
334341
mask_to_epi.inputs.apply_isoxfm = resolution

CPAC/pipeline/cpac_pipeline.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,6 +2069,18 @@ def build_workflow(subject_id, sub_dict, c, pipeline_name=None, num_ants_cores=1
20692069
'inputspec.func_to_anat_linear_xfm_file_path'
20702070
)
20712071

2072+
# invert func2anat matrix to get anat2func_linear_xfm
2073+
anat2func_linear_xfm = pe.Node(interface=fsl.ConvertXFM(), name='anat_to_func_linear_xfm_{0}_{1}'.format(regressors_selector_i, num_strat))
2074+
anat2func_linear_xfm.inputs.invert_xfm = True
2075+
workflow.connect(
2076+
node, out_file,
2077+
anat2func_linear_xfm, 'in_file')
2078+
workflow.connect(
2079+
anat2func_linear_xfm, 'out_file',
2080+
regressor_workflow,
2081+
'inputspec.anat_to_func_linear_xfm_file_path'
2082+
)
2083+
20722084
node, out_file = new_strat.get_leaf_properties()
20732085
workflow.connect(
20742086
node, out_file,

dev/docker_data/default_pipeline.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,15 +814,14 @@ funcRegFSLinterpolation: sinc
814814
# Options: ['Mean Functional', 'Selected Functional Volume']
815815
func_reg_input : ['Mean Functional']
816816

817-
818-
# Run ANTs’ N4 Bias Field Correction on the input BOLD average(mean EPI)
819-
n4_correct_mean_EPI : False
820-
821-
822817
# Only for when 'Use as Functional-to-Anatomical Registration Input' is set to 'Selected Functional Volume'. Input the index of which volume from the functional 4D timeseries input file you wish to use as the input for functional-to-anatomical registration.
823818
func_reg_input_volume : 0
824819

825820

821+
# Run ANTs’ N4 Bias Field Correction on the input of functional-to-anatomical registration (mean of the functional/EPI or one of the volumes from the functional 4D timeseries)
822+
n4_correct_func_reg_input : False
823+
824+
826825
# Choose which tool to be used in functional masking - AFNI (3dAutoMask), FSL (BET), FSL_AFNI (BET+3dAutoMask), or refine functional mask by registering anatomical mask to functional space.
827826
# Options: ['AFNI', 'FSL', 'FSL_AFNI', 'Anatomical_Refined']
828827
functionalMasking : ['AFNI']

0 commit comments

Comments
 (0)