Skip to content

Commit 15bde22

Browse files
authored
Edit workflow docs Fix #216 (#223)
1 parent fe3c61a commit 15bde22

2 files changed

Lines changed: 65 additions & 47 deletions

File tree

src/rbc/workflows/anatomical.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class AnatomicalOutputs(NamedTuple):
3737
gm_mask: GM tissue mask.
3838
wm_mask: WM tissue mask.
3939
wm_bbr_mask: WM boundary mask for BBR coregistration.
40-
forward_xfm: T1w -> template composite warp.
41-
inverse_xfm: Template -> T1w composite warp.
40+
forward_xfm: T1w-to-template composite warp.
41+
inverse_xfm: Template-to-T1w composite warp.
4242
"""
4343

4444
brain: Path
@@ -57,10 +57,15 @@ def single_session_preprocess(in_t1w: Path) -> AnatomicalOutputs:
5757
Pipeline steps:
5858
5959
1. Deoblique and reorient T1w to RPI.
60-
2. ANTs brain extraction (N4 bias correction + skull-stripping).
61-
3. FSL FAST tissue segmentation (CSF / GM / WM masks).
60+
2. ANTs brain extraction (via template; default is OASIS):
61+
a. N4 bias field correction
62+
b. Registration to template
63+
c. Warp brain probability mask to subject space
64+
d. Threshold mask to produce binary brain mask
65+
3. FSL FAST tissue segmentation on skull-stripped brain (CSF / GM / WM
66+
partial volume maps, thresholded at 0.95 for binary masks).
6267
4. WM boundary mask for BBR coregistration.
63-
5. ANTs registration to MNI152 template (forward + inverse transforms).
68+
5. ANTs registration to MNI152 template (forward + inverse composite warps).
6469
6570
Args:
6671
in_t1w: Raw T1w image to preprocess.
@@ -92,14 +97,20 @@ def single_session_preprocess(in_t1w: Path) -> AnatomicalOutputs:
9297

9398

9499
class AnatomicalLongOutputs(NamedTuple):
95-
"""Outputs from the anatomical preprocessing pipeline.
100+
"""Outputs from the longitudinal anatomical preprocessing pipeline.
96101
97102
Attributes:
98-
brain: Skull-stripped T1w brain.
99-
brain_mask: Binary brain mask.
100-
csf_mask: CSF tissue mask.
101-
gm_mask: GM tissue mask.
102-
wm_mask: WM tissue mask.
103+
brain: Skull-stripped T1w brain warped to longitudinal template space.
104+
brain_mask: Binary brain mask warped to longitudinal template space,
105+
or *None* if not provided.
106+
csf_mask: CSF tissue mask warped to longitudinal template space,
107+
or *None* if not provided.
108+
gm_mask: GM tissue mask warped to longitudinal template space,
109+
or *None* if not provided.
110+
wm_mask: WM tissue mask warped to longitudinal template space,
111+
or *None* if not provided.
112+
forward_xfm: Longitudinal template-to-MNI152 composite warp.
113+
inverse_xfm: MNI152-to-longitudinal template composite warp.
103114
"""
104115

105116
brain: Path
@@ -123,11 +134,12 @@ def longitudinal_process(
123134
) -> AnatomicalLongOutputs:
124135
"""Transform preprocessed anatomical outputs to longitudinal template space.
125136
126-
Assumes a template generated and transforms computed.
137+
Assumes a longitudinal template has been generated and a subject-to-template
138+
composite warp is available.
127139
128140
Args:
129141
template: Longitudinal template image.
130-
subj_to_template_xfm: Transform from subject to template space.
142+
subj_to_template_xfm: Subject-to-longitudinal-template composite warp.
131143
brain: Preprocessed brain image.
132144
brain_mask: Brain mask, if available.
133145
csf_mask: CSF partial volume mask, if available.

src/rbc/workflows/functional.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ class FunctionalOutputs(NamedTuple):
6969
distortion_warp: ANTs/ITK-compatible distortion warp field, or
7070
*None* if no fieldmap data was provided.
7171
stc_bold: Slice-timing corrected BOLD.
72-
preproc_bold: Motion-corrected + STC BOLD in native space
73-
(exported as desc-preproc_bold, not consumed downstream).
72+
preproc_bold: Motion-corrected + STC BOLD in native space.
7473
motion_params: Six-column motion parameter file.
7574
rms_rel: Frame-to-frame relative RMS displacement.
7675
rms_abs: Volume-to-reference absolute RMS displacement.
7776
mat_dir: Directory of per-volume motion matrices.
7877
bold_mask: Final binary BOLD brain mask.
7978
skull_stripped_bold: Skull-stripped BOLD reference.
80-
bold_to_anat_matrix: BOLD-to-T1w affine matrix (BBR).
81-
bold_to_anat_itk: BOLD-to-T1w affine in ITK format (for ANTs warping).
79+
bold_to_anat_matrix: BOLD-to-T1w affine matrix.
80+
bold_to_anat_itk: BOLD-to-T1w affine in ITK format.
8281
template_bold: BOLD resampled to template space.
83-
regressed_bold: Nuisance-regressed (non-bandpassed) BOLD.
82+
regressed_bold: Nuisance-regressed & non-bandpassed BOLD.
8483
cleaned_bold: Nuisance-regressed & bandpass-filtered BOLD.
85-
regressor_file: Nuisance regressor ``.1D`` file.
84+
regressor_file: Bandpass-filtered nuisance regressor ``.1D`` file.
8685
template_brain_mask: Brain mask warped to template space.
8786
"""
8887

@@ -154,24 +153,29 @@ def single_session_preprocess(
154153
Pipeline steps:
155154
156155
1. Deoblique & reorient BOLD to RPI.
157-
2. Truncate initial TRs.
156+
2. Truncate initial TRs (default: first 2 TRs).
158157
3. Despike BOLD.
159158
4. Extract motion reference from despiked BOLD.
160159
5. Susceptibility distortion correction (optional, requires fieldmaps).
161160
6. Motion correction on despiked BOLD (pre-STC, for .par estimates
162161
and per-volume .mat affines).
163162
7. Slice timing correction on despiked BOLD.
164-
8. Apply motion .mat to STC volumes -> desc-preproc_bold (native-space
165-
MC + STC output, exported but not consumed by later steps).
166-
9. BOLD brain masking (on motion reference volume).
167-
10. BBR coregistration (skull-stripped BOLD ref -> T1w).
168-
11. Warp tissue masks T1w -> BOLD space (inverse of bold_to_anat).
163+
8. Apply motion .mat affines to STC BOLD (native-space MC + STC,
164+
used for nuisance regressor computation).
165+
9. BOLD brain masking on motion reference volume.
166+
10. BBR coregistration of skull-stripped BOLD reference to T1w.
167+
11. Warp tissue masks (brain, CSF, WM) to BOLD space using inverse
168+
of BOLD-to-T1w affine.
169169
12. Compute nuisance regressors from native-space BOLD.
170-
13. Single-step resampling: STC volumes -> template space (motion +
171-
BBR + anat2template in one interpolation pass per volume).
170+
13. Single-step resampling of STC BOLD to template space: motion +
171+
BBR + T1w-to-template composite warp applied in one interpolation pass
172+
per volume to minimize resampling artifacts.
172173
14. Warp brain mask to template space.
173-
15. Nuisance regression without bandpass (for ALFF/fALFF).
174-
16. Simultaneous regression + bandpass (Hallquist 2013).
174+
15. Nuisance regression without bandpass on template-space BOLD
175+
(full frequency range preserved for ALFF/fALFF computation).
176+
16. Nuisance regression with simultaneous bandpass filtering
177+
on template-space BOLD (Hallquist 2013).
178+
17. Export bandpass-filtered regressors.
175179
176180
Args:
177181
in_bold: Raw BOLD timeseries to preprocess.
@@ -180,7 +184,7 @@ def single_session_preprocess(
180184
brain_mask: Binary brain mask from anatomical pipeline.
181185
csf_mask: CSF tissue mask from anatomical pipeline.
182186
wm_mask: WM tissue mask from anatomical pipeline.
183-
anat_to_template: T1w -> template composite warp.
187+
anat_to_template: T1w-to-template composite warp.
184188
start_tr: Number of initial TRs to discard.
185189
regressor_set: Nuisance regressor strategy.
186190
fieldmap: Fieldmap inputs for susceptibility distortion correction.
@@ -237,10 +241,10 @@ def single_session_preprocess(
237241
effective_ref = distortion.corrected_ref if distortion else motion_ref
238242
distortion_warp = distortion.warp_field if distortion else None
239243

240-
# 6. MC on despiked (pre-STC)
244+
# 6. MC on despiked BOLD (pre-STC)
241245
_logger.info("Motion correction (MCFLIRT)")
242-
# .par -> motion params for nuisance regression + QC
243-
# .mat -> per-volume affines used in steps 8 and 13
246+
# .par motion estimates used for nuisance regression + QC
247+
# .mat per-volume affines used in steps 8 and 13
244248
mc = fsl_motion_correction(in_file=despiked, ref_file=effective_ref)
245249

246250
# 7. Slice timing correction
@@ -251,8 +255,8 @@ def single_session_preprocess(
251255
tpattern=metadata.get("SliceTiming"),
252256
)
253257

254-
# 8. Apply pre-STC motion transforms to STC BOLD ->
255-
# desc-preproc_bold (native-space MC + STC, exported only)
258+
# 8. Apply pre-STC motion transforms to STC BOLD
259+
# native-space MC + STC BOLD used in step 12
256260
_logger.info("Applying motion transforms to STC BOLD")
257261
preproc_bold = apply_motion_transforms(
258262
stc_img=st_corrected,
@@ -276,7 +280,7 @@ def single_session_preprocess(
276280
wm_seg=wm_bbr_mask,
277281
)
278282

279-
# 11. Warp tissue masks T1w -> BOLD space (inverse of bold_to_anat)
283+
# 11. Warp tissue masks T1w-to-BOLD space (inverse of BOLD-to-T1w affine)
280284
bold2anat_fpath_str = str(generate_exec_folder("bold2anat") / "bold2anat.txt")
281285
bold_to_anat_itk = mat_to_itk(
282286
bbr.out_matrix_file, t1w_brain, masking.skull_stripped_bold, bold2anat_fpath_str
@@ -298,8 +302,8 @@ def single_session_preprocess(
298302
regressor_set=regressor,
299303
)
300304

301-
# 13. Single-step resampling (STC -> template)
302-
# All spatial transforms (motion + BBR + anat2template) applied in one
305+
# 13. Single-step resampling (STC BOLD to template)
306+
# All spatial transforms (motion + BBR + T1w-to-template) applied in one
303307
# interpolation pass per volume to minimize resampling artifacts.
304308
_logger.info("Resampling BOLD to template space (single-step)")
305309
template_bold = resample_bold_to_template(
@@ -374,13 +378,14 @@ def single_session_preprocess(
374378

375379

376380
class FunctionalLongOutputs(NamedTuple):
377-
"""Outputs from the functional preprocessing pipeline.
381+
"""Outputs from the longitudinal functional preprocessing pipeline.
378382
379383
Attributes:
380-
sbref:
381-
bold:
382-
bold_mask:
383-
forward_xfm:
384+
forward_xfm: BOLD-to-longitudinal-template composite warp.
385+
sbref: Motion reference volume warped to longitudinal template space.
386+
bold: Preprocessed BOLD warped to longitudinal template space.
387+
bold_mask: Brain mask warped to longitudinal template space,
388+
or *None* if no mask was provided.
384389
"""
385390

386391
forward_xfm: Path
@@ -400,13 +405,14 @@ def longitudinal_process(
400405
) -> FunctionalLongOutputs:
401406
"""Transform preprocessed functional outputs to longitudinal template space.
402407
403-
Assumes a template generated with transforms to anatomical, anatomical data already
404-
preprocessed to longitudinal.
408+
Assumes a longitudinal template has been generated, the subject-to-template
409+
composite warp is available, and anatomical data has already been processed
410+
to longitudinal template space.
405411
406412
Args:
407413
template: Longitudinal template image.
408-
anat_to_template_xfm: Transform from subject to template space.
409-
bold_to_anat_itk: Transformation from bold to preprocessed anatomical space.
414+
anat_to_template_xfm: T1w-to-longitudinal-template composite warp.
415+
bold_to_anat_itk: BOLD-to-T1w affine in ITK format.
410416
sbref: Motion reference (single-band reference) volume.
411417
bold: Preprocessed bold image.
412418
bold_mask: Bold brain mask, if available.

0 commit comments

Comments
 (0)