Skip to content

Commit 72fc030

Browse files
committed
Handle blip-warps for opposing registration tools appropriately.
1 parent 5c38cdd commit 72fc030

File tree

3 files changed

+125
-18
lines changed

3 files changed

+125
-18
lines changed

CPAC/distortion_correction/distortion_correction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def distcor_blip_afni_qwarp(wf, cfg, strat_pool, pipe_num, opt=None):
349349
"pe-direction"],
350350
"outputs": ["sbref",
351351
"space-bold_desc-brain_mask",
352-
"blip-warp"]}
352+
"ants-blip-warp"]}
353353
'''
354354

355355
match_epi_imports = ['import json']
@@ -476,7 +476,7 @@ def distcor_blip_afni_qwarp(wf, cfg, strat_pool, pipe_num, opt=None):
476476
wf.connect(undistort_func_mean, 'output_image', remask, 'in_file')
477477

478478
outputs = {
479-
'blip-warp': (convert_afni_warp, 'ants_warp'),
479+
'ants-blip-warp': (convert_afni_warp, 'ants_warp'),
480480
#'inv-blip-warp': None, # TODO
481481
'sbref': (undistort_func_mean, 'output_image'),
482482
'space-bold_desc-brain_mask': (remask, 'out_file')
@@ -510,7 +510,7 @@ def distcor_blip_fsl_topup(wf, cfg, strat_pool, pipe_num, opt=None):
510510
"epi-2-total-readout"],
511511
"outputs": ["sbref",
512512
"space-bold_desc-brain_mask",
513-
"blip-warp"]}
513+
"fsl-blip-warp"]}
514514
'''
515515

516516
# TODO: re-integrate gradient distortion coefficient usage at a later date
@@ -850,7 +850,7 @@ def distcor_blip_fsl_topup(wf, cfg, strat_pool, pipe_num, opt=None):
850850
outputs = {
851851
'sbref': (mul_jac, 'out_file'),
852852
'space-bold_desc-brain_mask': (bet, 'out_file'),
853-
'blip-warp': (convert_warp, 'out_file')
853+
'fsl-blip-warp': (convert_warp, 'out_file')
854854
}
855855

856856
return (wf, outputs)

CPAC/pipeline/cpac_pipeline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
coregistration,
9999
create_func_to_T1template_xfm,
100100
create_func_to_T1template_symmetric_xfm,
101+
apply_blip_to_timeseries_separately,
101102
warp_timeseries_to_T1template,
102103
warp_bold_mean_to_T1template,
103104
warp_bold_mask_to_T1template,
@@ -1265,7 +1266,8 @@ def build_workflow(subject_id, sub_dict, cfg, pipeline_name=None,
12651266

12661267
if apply_func_warp['T1']:
12671268

1268-
ts_to_T1template_block = [warp_timeseries_to_T1template,
1269+
ts_to_T1template_block = [apply_blip_to_timeseries_separately,
1270+
warp_timeseries_to_T1template,
12691271
warp_timeseries_to_T1template_dcan_nhp]
12701272

12711273
if cfg.nuisance_corrections['2-nuisance_regression']['create_regressors']:

CPAC/registration/registration.py

Lines changed: 118 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,8 @@ def ANTs_registration_connector(wf_name, cfg, params, orig="T1w",
17941794
return (wf, outputs)
17951795

17961796

1797-
def bold_to_T1template_xfm_connector(wf_name, cfg, reg_tool, symmetric=False):
1797+
def bold_to_T1template_xfm_connector(wf_name, cfg, reg_tool, symmetric=False,
1798+
blip=False):
17981799

17991800
wf = pe.Workflow(name=wf_name)
18001801

@@ -1804,7 +1805,8 @@ def bold_to_T1template_xfm_connector(wf_name, cfg, reg_tool, symmetric=False):
18041805
'coreg_xfm',
18051806
'T1w-brain-template_funcreg',
18061807
'T1w_to_template_xfm',
1807-
'template_to_T1w_xfm']),
1808+
'template_to_T1w_xfm',
1809+
'blip_warp']),
18081810
name='inputspec')
18091811

18101812
sym = ''
@@ -1856,11 +1858,18 @@ def bold_to_T1template_xfm_connector(wf_name, cfg, reg_tool, symmetric=False):
18561858
cfg.registration_workflows['anatomical_registration'][
18571859
'registration']['ANTs']['interpolation']
18581860

1859-
collect_all_transforms = pe.Node(util.Merge(2),
1860-
name=f'collect_all_transforms')
1861+
if not blip:
1862+
collect_all_transforms = pe.Node(util.Merge(2),
1863+
name='collect_all_transforms')
1864+
else:
1865+
collect_all_transforms = pe.Node(util.Merge(3),
1866+
name='collect_all_transforms')
1867+
1868+
wf.connect(inputNode, 'blip_warp',
1869+
collect_all_transforms, 'in3')
18611870

18621871
wf.connect(inputNode, 'T1w_to_template_xfm',
1863-
collect_all_transforms, 'in1')
1872+
collect_all_transforms, 'in1')
18641873

18651874
wf.connect(change_transform, 'updated_affine_file',
18661875
collect_all_transforms, 'in2')
@@ -1916,10 +1925,18 @@ def bold_to_T1template_xfm_connector(wf_name, cfg, reg_tool, symmetric=False):
19161925
wf.connect(inputNode, 'T1w-brain-template_funcreg',
19171926
write_composite_xfm, 'reference')
19181927

1919-
wf.connect(inputNode, 'coreg_xfm', write_composite_xfm, 'premat')
1920-
1921-
wf.connect(inputNode, 'T1w_to_template_xfm',
1922-
write_composite_xfm, 'warp1')
1928+
if blip:
1929+
wf.connect(inputNode, 'coreg_xfm',
1930+
write_composite_xfm, 'postmat')
1931+
wf.connect(inputNode, 'blip_warp',
1932+
write_composite_xfm, 'warp1')
1933+
wf.connect(inputNode, 'T1w_to_template_xfm',
1934+
write_composite_xfm, 'warp2')
1935+
else:
1936+
wf.connect(inputNode, 'coreg_xfm',
1937+
write_composite_xfm, 'premat')
1938+
wf.connect(inputNode, 'T1w_to_template_xfm',
1939+
write_composite_xfm, 'warp1')
19231940

19241941
outputs = {
19251942
f'from-bold_to-{sym}template_mode-image_xfm':
@@ -2935,7 +2952,9 @@ def create_func_to_T1template_xfm(wf, cfg, strat_pool, pipe_num, opt=None):
29352952
"option_key": ["target_template", "using"],
29362953
"option_val": "T1_template",
29372954
"inputs": [("sbref",
2938-
"from-bold_to-T1w_mode-image_desc-linear_xfm"),
2955+
"from-bold_to-T1w_mode-image_desc-linear_xfm",
2956+
"ants-blip-warp",
2957+
"fsl-blip-warp"),
29392958
("from-T1w_to-template_mode-image_xfm",
29402959
"from-template_to-T1w_mode-image_xfm",
29412960
"desc-brain_T1w"),
@@ -2974,6 +2993,21 @@ def create_func_to_T1template_xfm(wf, cfg, strat_pool, pipe_num, opt=None):
29742993
node, out = strat_pool.get_data('from-template_to-T1w_mode-image_xfm')
29752994
wf.connect(node, out, xfm, 'inputspec.template_to_T1w_xfm')
29762995

2996+
if strat_pool.check_rpool('ants-blip-warp'):
2997+
if reg_tool == 'ants':
2998+
node, out = strat_pool.get_data('ants-blip-warp')
2999+
wf.connect(node, out, xfm, 'inputspec.blip_warp')
3000+
elif reg_tool == 'fsl':
3001+
# apply the ants blip warp separately
3002+
pass
3003+
elif strat_pool.check_rpool('fsl-blip-warp'):
3004+
if reg_tool == 'fsl':
3005+
node, out = strat_pool.get_data('fsl-blip-warp')
3006+
wf.connect(node, out, xfm, 'inputspec.blip_warp')
3007+
elif reg_tool == 'ants':
3008+
# apply the fsl blip warp separately
3009+
pass
3010+
29773011
return (wf, outputs)
29783012

29793013

@@ -3033,6 +3067,77 @@ def create_func_to_T1template_symmetric_xfm(wf, cfg, strat_pool, pipe_num,
30333067
return (wf, outputs)
30343068

30353069

3070+
def apply_blip_to_timeseries_separately(wf, cfg, strat_pool, pipe_num,
3071+
opt=None):
3072+
'''
3073+
Node Block:
3074+
{"name": "apply_blip_to_timeseries_separately",
3075+
"config": "None",
3076+
"switch": [["registration_workflows", "functional_registration",
3077+
"func_registration_to_template", "run"],
3078+
["functional_preproc", "distortion_correction", "run"]],
3079+
"option_key": "None",
3080+
"option_val": "None",
3081+
"inputs": [("sbref",
3082+
"desc-preproc_bold",
3083+
"from-bold_to-template_mode-image_xfm",
3084+
"ants-blip-warp",
3085+
"fsl-blip-warp")],
3086+
"outputs": ["desc-preproc_bold"]}
3087+
'''
3088+
3089+
xfm_prov = strat_pool.get_cpac_provenance(
3090+
'from-bold_to-template_mode-image_xfm')
3091+
reg_tool = check_prov_for_regtool(xfm_prov)
3092+
3093+
if strat_pool.check_rpool("ants-blip-warp"):
3094+
if reg_tool == 'fsl':
3095+
blip_node, blip_out = strat_pool.get_data("ants-blip-warp")
3096+
else:
3097+
outputs = {'desc-preproc_bold': strat_pool.get_data("desc-preproc_bold")}
3098+
return (wf, outputs)
3099+
elif strat_pool.check_rpool("fsl-blip-warp"):
3100+
if reg_tool == 'ants':
3101+
blip_node, blip_out = strat_pool.get_data("fsl-blip-warp")
3102+
else:
3103+
outputs = {'desc-preproc_bold': strat_pool.get_data("desc-preproc_bold")}
3104+
return (wf, outputs)
3105+
3106+
num_cpus = cfg.pipeline_setup['system_config'][
3107+
'max_cores_per_participant']
3108+
3109+
num_ants_cores = cfg.pipeline_setup['system_config']['num_ants_threads']
3110+
3111+
apply_xfm = apply_transform(f'warp_ts_to_blip_sep_{pipe_num}', reg_tool,
3112+
time_series=True, num_cpus=num_cpus,
3113+
num_ants_cores=num_ants_cores)
3114+
3115+
if reg_tool == 'ants':
3116+
apply_xfm.inputs.inputspec.interpolation = cfg.registration_workflows[
3117+
'functional_registration']['func_registration_to_template'][
3118+
'ANTs_pipelines']['interpolation']
3119+
elif reg_tool == 'fsl':
3120+
apply_xfm.inputs.inputspec.interpolation = cfg.registration_workflows[
3121+
'functional_registration']['func_registration_to_template'][
3122+
'FNIRT_pipelines']['interpolation']
3123+
3124+
connect = strat_pool.get_data("desc-preproc_bold")
3125+
node, out = connect
3126+
wf.connect(node, out, apply_xfm, 'inputspec.input_image')
3127+
3128+
node, out = strat_pool.get_data("sbref")
3129+
wf.connect(node, out, apply_xfm, 'inputspec.reference')
3130+
3131+
wf.connect(blip_node, blip_out, apply_xfm, 'inputspec.transform')
3132+
3133+
outputs = {
3134+
'desc-preproc_bold': (apply_xfm, 'outputspec.output_image')
3135+
}
3136+
3137+
return (wf, outputs)
3138+
3139+
3140+
30363141
def warp_timeseries_to_T1template(wf, cfg, strat_pool, pipe_num, opt=None):
30373142
'''
30383143
Node Block:
@@ -3102,7 +3207,7 @@ def warp_timeseries_to_T1template_abcd(wf, cfg, strat_pool, pipe_num, opt=None):
31023207
"from-T1w_to-template_mode-image_xfm",
31033208
"from-bold_to-T1w_mode-image_desc-linear_xfm",
31043209
"from-bold_to-template_mode-image_xfm",
3105-
"blip-warp",
3210+
"fsl-blip-warp",
31063211
"desc-preproc_T1w",
31073212
"space-template_res-bold_desc-brain_T1w",
31083213
"space-template_desc-bold_mask",
@@ -3126,11 +3231,11 @@ def warp_timeseries_to_T1template_abcd(wf, cfg, strat_pool, pipe_num, opt=None):
31263231
node, out = strat_pool.get_data('desc-preproc_T1w')
31273232
wf.connect(node, out, convert_func_to_anat_linear_warp, 'reference')
31283233

3129-
if strat_pool.check_rpool('blip-warp'):
3234+
if strat_pool.check_rpool('fsl-blip-warp'):
31303235
node, out = strat_pool.get_data('from-bold_to-T1w_mode-image_desc-linear_xfm')
31313236
wf.connect(node, out, convert_func_to_anat_linear_warp, 'postmat')
31323237

3133-
node, out = strat_pool.get_data('blip-warp')
3238+
node, out = strat_pool.get_data('fsl-blip-warp')
31343239
wf.connect(node, out, convert_func_to_anat_linear_warp, 'warp1')
31353240
else:
31363241
node, out = strat_pool.get_data('from-bold_to-T1w_mode-image_desc-linear_xfm')

0 commit comments

Comments
 (0)