Skip to content

Commit 7897957

Browse files
committed
adding native transforms (.mat files) to outputs
1 parent b8d22b7 commit 7897957

File tree

5 files changed

+206
-118
lines changed

5 files changed

+206
-118
lines changed

CPAC/pipeline/schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ def sanitize(filename):
692692
},
693693
},
694694
"registration_workflows": {
695+
"sink_native_transforms": bool1_1,
695696
"anatomical_registration": {
696697
"run": bool1_1,
697698
"resolution_for_anat": All(str, Match(RESOLUTION_REGEX)),

CPAC/registration/registration.py

Lines changed: 155 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,20 @@ def FSL_registration_connector(
15521552
),
15531553
}
15541554

1555+
if cfg.registration_workflows["sink_native_transforms"]:
1556+
outputs.update(
1557+
{
1558+
f"from-{orig}_to-{sym}{tmpl}template_mode-image_desc-linear_xfm": (
1559+
flirt_reg_anat_mni,
1560+
"outputspec.linear_xfm",
1561+
),
1562+
f"from-{sym}{tmpl}template_to-{orig}_mode-image_desc-linear_xfm": (
1563+
flirt_reg_anat_mni,
1564+
"outputspec.invlinear_xfm",
1565+
),
1566+
}
1567+
)
1568+
15551569
if opt == "FSL":
15561570
fnirt_reg_anat_mni = create_fsl_fnirt_nonlinear_reg_nhp(
15571571
f"anat_mni_fnirt_register{symm}"
@@ -2048,6 +2062,24 @@ def ANTs_registration_connector(
20482062
),
20492063
}
20502064

2065+
if cfg.registration_workflows["sink_native_transforms"]:
2066+
outputs.update(
2067+
{
2068+
f"from-{orig}_to-{sym}{tmpl}template_mode-image_desc-initial_xfm": (
2069+
ants_reg_anat_mni,
2070+
"outputspec.ants_initial_xfm",
2071+
),
2072+
f"from-{orig}_to-{sym}{tmpl}template_mode-image_desc-rigid_xfm": (
2073+
ants_reg_anat_mni,
2074+
"outputspec.ants_rigid_xfm",
2075+
),
2076+
f"from-{orig}_to-{sym}{tmpl}template_mode-image_desc-affine_xfm": (
2077+
ants_reg_anat_mni,
2078+
"outputspec.ants_affine_xfm",
2079+
),
2080+
}
2081+
)
2082+
20512083
return (wf, outputs)
20522084

20532085

@@ -2482,75 +2514,76 @@ def register_FSL_EPI_to_template(wf, cfg, strat_pool, pipe_num, opt=None):
24822514
"label-lesion_mask",
24832515
],
24842516
outputs={
2485-
"space-template_desc-preproc_T1w": {
2486-
"Description": "The preprocessed T1w brain transformed to "
2487-
"template space.",
2488-
"Template": "T1w-template",
2489-
},
2490-
"from-T1w_to-template_mode-image_desc-linear_xfm": {
2491-
"Description": "Linear (affine) transform from T1w native space "
2492-
"to T1w-template space.",
2493-
"Template": "T1w-template",
2494-
},
2495-
"from-template_to-T1w_mode-image_desc-linear_xfm": {
2496-
"Description": "Linear (affine) transform from T1w-template space "
2497-
"to T1w native space.",
2498-
"Template": "T1w-template",
2499-
},
2500-
"from-T1w_to-template_mode-image_desc-nonlinear_xfm": {
2501-
"Description": "Nonlinear (warp field) transform from T1w native "
2502-
"space to T1w-template space.",
2503-
"Template": "T1w-template",
2504-
},
2505-
"from-template_to-T1w_mode-image_desc-nonlinear_xfm": {
2506-
"Description": "Nonlinear (warp field) transform from "
2507-
"T1w-template space to T1w native space.",
2508-
"Template": "T1w-template",
2509-
},
2510-
"from-T1w_to-template_mode-image_xfm": {
2511-
"Description": "Composite (affine + warp field) transform from "
2512-
"T1w native space to T1w-template space.",
2513-
"Template": "T1w-template",
2514-
},
2515-
"from-template_to-T1w_mode-image_xfm": {
2516-
"Description": "Composite (affine + warp field) transform from "
2517-
"T1w-template space to T1w native space.",
2518-
"Template": "T1w-template",
2519-
},
2520-
"from-longitudinal_to-template_mode-image_desc-linear_xfm": {
2521-
"Description": "Linear (affine) transform from "
2522-
"longitudinal-template space to T1w-template "
2523-
"space.",
2524-
"Template": "T1w-template",
2525-
},
2526-
"from-template_to-longitudinal_mode-image_desc-linear_xfm": {
2527-
"Description": "Linear (affine) transform from T1w-template "
2528-
"space to longitudinal-template space.",
2529-
"Template": "T1w-template",
2530-
},
2531-
"from-longitudinal_to-template_mode-image_desc-nonlinear_xfm": {
2532-
"Description": "Nonlinear (warp field) transform from "
2533-
"longitudinal-template space to T1w-template "
2534-
"space.",
2535-
"Template": "T1w-template",
2536-
},
2537-
"from-template_to-longitudinal_mode-image_desc-nonlinear_xfm": {
2538-
"Description": "Nonlinear (warp field) transform from "
2539-
"T1w-template space to longitudinal-template "
2540-
"space.",
2541-
"Template": "T1w-template",
2542-
},
2543-
"from-longitudinal_to-template_mode-image_xfm": {
2544-
"Description": "Composite (affine + warp field) transform from "
2545-
"longitudinal-template space to T1w-template "
2546-
"space.",
2547-
"Template": "T1w-template",
2517+
**{
2518+
k: {"Description": v, "Template": "T1w-template"}
2519+
for k, v in [
2520+
(
2521+
"space-template_desc-preproc_T1w",
2522+
"The preprocessed T1w brain transformed to template space.",
2523+
),
2524+
(
2525+
"from-T1w_to-template_mode-image_desc-linear_xfm",
2526+
"Linear (affine) transform from T1w native space to T1w-template space.",
2527+
),
2528+
(
2529+
"from-template_to-T1w_mode-image_desc-linear_xfm",
2530+
"Linear (affine) transform from T1w-template space to T1w native space.",
2531+
),
2532+
(
2533+
"from-T1w_to-template_mode-image_desc-nonlinear_xfm",
2534+
"Nonlinear (warp field) transform from T1w native space to T1w-template space.",
2535+
),
2536+
(
2537+
"from-template_to-T1w_mode-image_desc-nonlinear_xfm",
2538+
"Nonlinear (warp field) transform from T1w-template space to T1w native space.",
2539+
),
2540+
(
2541+
"from-T1w_to-template_mode-image_xfm",
2542+
"Composite (affine + warp field) transform from T1w native space to T1w-template space.",
2543+
),
2544+
(
2545+
"from-template_to-T1w_mode-image_xfm",
2546+
"Composite (affine + warp field) transform from T1w-template space to T1w native space.",
2547+
),
2548+
(
2549+
"from-longitudinal_to-template_mode-image_desc-linear_xfm",
2550+
"Linear (affine) transform from longitudinal-template space to T1w-template space.",
2551+
),
2552+
(
2553+
"from-template_to-longitudinal_mode-image_desc-linear_xfm",
2554+
"Linear (affine) transform from T1w-template space to longitudinal-template space.",
2555+
),
2556+
(
2557+
"from-longitudinal_to-template_mode-image_desc-nonlinear_xfm",
2558+
"Nonlinear (warp field) transform from longitudinal-template space to T1w-template space.",
2559+
),
2560+
(
2561+
"from-template_to-longitudinal_mode-image_desc-nonlinear_xfm",
2562+
"Nonlinear (warp field) transform from T1w-template space to longitudinal-template space.",
2563+
),
2564+
(
2565+
"from-longitudinal_to-template_mode-image_xfm",
2566+
"Composite (affine + warp field) transform from longitudinal-template space to T1w-template space.",
2567+
),
2568+
(
2569+
"from-template_to-longitudinal_mode-image_xfm",
2570+
"Composite (affine + warp field) transform from T1w-template space to longitudinal-template space.",
2571+
),
2572+
]
25482573
},
2549-
"from-template_to-longitudinal_mode-image_xfm": {
2550-
"Description": "Composite (affine + warp field) transform from "
2551-
"T1w-template space to longitudinal-template "
2552-
"space.",
2553-
"Template": "T1w-template",
2574+
**{
2575+
f"from-{src}_to-{dst}_mode-image_desc-{xfm}_xfm": {
2576+
"Description": f"{desc} transform from {src.replace('longitudinal', 'longitudinal-template') if src == 'longitudinal' else src} native space to {dst.replace('longitudinal', 'longitudinal-template') if dst == 'longitudinal' else dst}-template space.",
2577+
"Template": "T1w-template",
2578+
}
2579+
for src in ["T1w", "longitudinal"]
2580+
for dst in ["template", "longitudinal"]
2581+
for xfm, desc in [
2582+
("initial", "Initial"),
2583+
("rigid", "Rigid"),
2584+
("affine", "Affine"),
2585+
]
2586+
if src != dst
25542587
},
25552588
},
25562589
)
@@ -2648,44 +2681,37 @@ def register_ANTs_anat_to_template(wf, cfg, strat_pool, pipe_num, opt=None):
26482681
"label-lesion_mask",
26492682
],
26502683
outputs={
2651-
"space-symtemplate_desc-preproc_T1w": {
2652-
"Template": "T1w-brain-template-symmetric"
2653-
},
2654-
"from-T1w_to-symtemplate_mode-image_desc-linear_xfm": {
2655-
"Template": "T1w-template-symmetric"
2656-
},
2657-
"from-symtemplate_to-T1w_mode-image_desc-linear_xfm": {
2658-
"Template": "T1w-template-symmetric"
2659-
},
2660-
"from-T1w_to-symtemplate_mode-image_desc-nonlinear_xfm": {
2661-
"Template": "T1w-template-symmetric"
2662-
},
2663-
"from-symtemplate_to-T1w_mode-image_desc-nonlinear_xfm": {
2664-
"Template": "T1w-template-symmetric"
2665-
},
2666-
"from-T1w_to-symtemplate_mode-image_xfm": {
2667-
"Template": "T1w-template-symmetric"
2668-
},
2669-
"from-symtemplate_to-T1w_mode-image_xfm": {
2670-
"Template": "T1w-template-symmetric"
2671-
},
2672-
"from-longitudinal_to-symtemplate_mode-image_desc-linear_xfm": {
2673-
"Template": "T1w-template-symmetric"
2674-
},
2675-
"from-symtemplate_to-longitudinal_mode-image_desc-linear_xfm": {
2676-
"Template": "T1w-template-symmetric"
2677-
},
2678-
"from-longitudinal_to-symtemplate_mode-image_desc-nonlinear_xfm": {
2679-
"Template": "T1w-template-symmetric"
2680-
},
2681-
"from-symtemplate_to-longitudinal_mode-image_desc-nonlinear_xfm": {
2682-
"Template": "T1w-template-symmetric"
2683-
},
2684-
"from-longitudinal_to-symtemplate_mode-image_xfm": {
2685-
"Template": "T1w-template-symmetric"
2684+
**{
2685+
k: {"Template": "T1w-template-symmetric"}
2686+
for k in [
2687+
"space-symtemplate_desc-preproc_T1w",
2688+
"from-T1w_to-symtemplate_mode-image_desc-linear_xfm",
2689+
"from-symtemplate_to-T1w_mode-image_desc-linear_xfm",
2690+
"from-T1w_to-symtemplate_mode-image_desc-nonlinear_xfm",
2691+
"from-symtemplate_to-T1w_mode-image_desc-nonlinear_xfm",
2692+
"from-T1w_to-symtemplate_mode-image_xfm",
2693+
"from-symtemplate_to-T1w_mode-image_xfm",
2694+
"from-longitudinal_to-symtemplate_mode-image_desc-linear_xfm",
2695+
"from-symtemplate_to-longitudinal_mode-image_desc-linear_xfm",
2696+
"from-longitudinal_to-symtemplate_mode-image_desc-nonlinear_xfm",
2697+
"from-symtemplate_to-longitudinal_mode-image_desc-nonlinear_xfm",
2698+
"from-longitudinal_to-symtemplate_mode-image_xfm",
2699+
"from-symtemplate_to-longitudinal_mode-image_xfm",
2700+
]
26862701
},
2687-
"from-symtemplate_to-longitudinal_mode-image_xfm": {
2688-
"Template": "T1w-template-symmetric"
2702+
**{
2703+
f"from-{src}_to-{dst}_mode-image_desc-{xfm}_xfm": {
2704+
"Description": f"{desc} transform from {src.replace('longitudinal', 'longitudinal-template') if src == 'longitudinal' else src} native space to {dst.replace('longitudinal', 'longitudinal-template') if dst == 'longitudinal' else dst}-template-symmetric space.",
2705+
"Template": "T1w-template-symmetric",
2706+
}
2707+
for src in ["T1w", "longitudinal", "symtemplate"]
2708+
for dst in ["symtemplate", "T1w", "longitudinal"]
2709+
for xfm, desc in [
2710+
("initial", "Initial"),
2711+
("rigid", "Rigid"),
2712+
("affine", "Affine"),
2713+
]
2714+
if src != dst
26892715
},
26902716
},
26912717
)
@@ -2762,21 +2788,32 @@ def register_symmetric_ANTs_anat_to_template(wf, cfg, strat_pool, pipe_num, opt=
27622788
"EPI-template-mask",
27632789
],
27642790
outputs={
2765-
"space-template_desc-preproc_bold": {"Template": "EPI-template"},
2766-
"from-bold_to-EPItemplate_mode-image_desc-linear_xfm": {
2767-
"Template": "EPI-template"
2768-
},
2769-
"from-EPItemplate_to-bold_mode-image_desc-linear_xfm": {
2770-
"Template": "EPI-template"
2771-
},
2772-
"from-bold_to-EPItemplate_mode-image_desc-nonlinear_xfm": {
2773-
"Template": "EPI-template"
2791+
**{
2792+
k: {"Template": "EPI-template"}
2793+
for k in [
2794+
"space-template_desc-preproc_bold",
2795+
"from-bold_to-EPItemplate_mode-image_desc-linear_xfm",
2796+
"from-EPItemplate_to-bold_mode-image_desc-linear_xfm",
2797+
"from-bold_to-EPItemplate_mode-image_desc-nonlinear_xfm",
2798+
"from-EPItemplate_to-bold_mode-image_desc-nonlinear_xfm",
2799+
"from-bold_to-EPItemplate_mode-image_xfm",
2800+
"from-EPItemplate_to-bold_mode-image_xfm",
2801+
]
27742802
},
2775-
"from-EPItemplate_to-bold_mode-image_desc-nonlinear_xfm": {
2776-
"Template": "EPI-template"
2803+
**{
2804+
f"from-{src}_to-{dst}_mode-image_desc-{xfm}_xfm": {
2805+
"Description": f"{desc} transform from {src} native space to {dst} template space.",
2806+
"Template": "EPI-template",
2807+
}
2808+
for src in ["bold", "EPItemplate"]
2809+
for dst in ["EPItemplate", "bold"]
2810+
for xfm, desc in [
2811+
("initial", "Initial"),
2812+
("rigid", "Rigid"),
2813+
("affine", "Affine"),
2814+
]
2815+
if src != dst
27772816
},
2778-
"from-bold_to-EPItemplate_mode-image_xfm": {"Template": "EPI-template"},
2779-
"from-EPItemplate_to-bold_mode-image_xfm": {"Template": "EPI-template"},
27802817
},
27812818
)
27822819
def register_ANTs_EPI_to_template(wf, cfg, strat_pool, pipe_num, opt=None):

CPAC/resources/configs/pipeline_config_blank.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ segmentation:
570570
WM_label: [2, 41]
571571

572572
registration_workflows:
573+
# sink native transform files to the output directory
574+
sink_native_transforms: Off
575+
573576
anatomical_registration:
574577
run: Off
575578
registration:

CPAC/resources/configs/pipeline_config_default.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ segmentation:
618618

619619

620620
registration_workflows:
621+
# sink native transform files to the output directory
622+
sink_native_transforms: Off
621623

622624
anatomical_registration:
623625

CPAC/resources/cpac_outputs.tsv

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,51 @@ from-template_to-longitudinal_mode-image_xfm xfm anat NIfTI
209209
from-template_to-T1w_mode-image_desc-linear_xfm xfm anat NIfTI
210210
from-template_to-T1w_mode-image_desc-nonlinear_xfm xfm anat NIfTI
211211
from-template_to-T1w_mode-image_xfm xfm anat NIfTI
212+
from-T1w_to-template_mode-image_desc-linear_xfm xfm anat MAT
213+
from-T1w_to-template_mode-image_desc-invlinear_xfm xfm anat MAT
214+
from-T1w_to-symtemplate_mode-image_desc-linear_xfm xfm anat MAT
215+
from-T1w_to-symtemplate_mode-image_desc-invlinear_xfm xfm anat MAT
216+
from-T1w_to-template_mode-image_desc-initial_xfm xfm anat MAT
217+
from-T1w_to-template_mode-image_desc-rigid_xfm xfm anat MAT
218+
from-T1w_to-template_mode-image_desc-affine_xfm xfm anat MAT
219+
from-T1w_to-template_mode-image_desc-initial_xfm xfm anat MAT
220+
from-T1w_to-template_mode-image_desc-rigid_xfm xfm anat MAT
221+
from-T1w_to-template_mode-image_desc-affine_xfm xfm anat MAT
222+
from-T1w_to-longitudinal_mode-image_desc-initial_xfm xfm anat MAT
223+
from-T1w_to-longitudinal_mode-image_desc-rigid_xfm xfm anat MAT
224+
from-T1w_to-longitudinal_mode-image_desc-affine_xfm xfm anat MAT
225+
from-longitudinal_to-template_mode-image_desc-initial_xfm xfm anat MAT
226+
from-longitudinal_to-template_mode-image_desc-rigid_xfm xfm anat MAT
227+
from-longitudinal_to-template_mode-image_desc-affine_xfm xfm anat MAT
228+
from-longitudinal_to-T1w_mode-image_desc-initial_xfm xfm anat MAT
229+
from-longitudinal_to-T1w_mode-image_desc-rigid_xfm xfm anat MAT
230+
from-longitudinal_to-T1w_mode-image_desc-affine_xfm xfm anat MAT
231+
from-T1w_to-symtemplate_mode-image_desc-initial_xfm xfm anat MAT
232+
from-T1w_to-symtemplate_mode-image_desc-rigid_xfm xfm anat MAT
233+
from-T1w_to-symtemplate_mode-image_desc-affine_xfm xfm anat MAT
234+
from-T1w_to-longitudinal_mode-image_desc-initial_xfm xfm anat MAT
235+
from-T1w_to-longitudinal_mode-image_desc-rigid_xfm xfm anat MAT
236+
from-T1w_to-longitudinal_mode-image_desc-affine_xfm xfm anat MAT
237+
from-longitudinal_to-symtemplate_mode-image_desc-initial_xfm xfm anat MAT
238+
from-longitudinal_to-symtemplate_mode-image_desc-rigid_xfm xfm anat MAT
239+
from-longitudinal_to-symtemplate_mode-image_desc-affine_xfm xfm anat MAT
240+
from-longitudinal_to-T1w_mode-image_desc-initial_xfm xfm anat MAT
241+
from-longitudinal_to-T1w_mode-image_desc-rigid_xfm xfm anat MAT
242+
from-longitudinal_to-T1w_mode-image_desc-affine_xfm xfm anat MAT
243+
from-symtemplate_to-T1w_mode-image_desc-initial_xfm xfm anat MAT
244+
from-symtemplate_to-T1w_mode-image_desc-rigid_xfm xfm anat MAT
245+
from-symtemplate_to-T1w_mode-image_desc-affine_xfm xfm anat MAT
246+
from-symtemplate_to-longitudinal_mode-image_desc-initial_xfm xfm anat MAT
247+
from-symtemplate_to-longitudinal_mode-image_desc-rigid_xfm xfm anat MAT
248+
from-symtemplate_to-longitudinal_mode-image_desc-affine_xfm xfm anat MAT
249+
from-bold_to-EPItemplate_mode-image_desc-initial_xfm xfm func MAT
250+
from-bold_to-EPItemplate_mode-image_desc-rigid_xfm xfm func MAT
251+
from-bold_to-EPItemplate_mode-image_desc-affine_xfm xfm func MAT
252+
from-EPItemplate_to-bold_mode-image_desc-initial_xfm xfm func MAT
253+
from-EPItemplate_to-bold_mode-image_desc-rigid_xfm xfm func MAT
254+
from-EPItemplate_to-bold_mode-image_desc-affine_xfm xfm func MAT
255+
from-bold_to-EPItemplate_mode-image_desc-linear_xfm xfm func MAT
256+
from-bold_to-EPItemplate_mode-image_desc-invlinear_xfm xfm func MAT
212257
space-template_label-CSF_mask mask template anat NIfTI
213258
space-template_label-WM_mask mask template anat NIfTI
214259
space-template_label-GM_mask mask template anat NIfTI

0 commit comments

Comments
 (0)