Inter-Session Data & Align_epi_anat.py

Hi AFNI Team,

I am examining three sessions of data from a single subject (not warping to an atlas space). I used align_epi_anat.py to align the epi scans to the T1 from the first session and based on visual inspection it looks like they lined up fairly well. What are some other factors that I might not be taking into consideration?

Also, I discovered a script that seems to make an average T1 for inter-session registration. Is the advantage of this approach that you don’t have to shift the epi scans from certain sessions more than the others?

https://sscc.nimh.nih.gov/sscc/dglen/alignmentacross2sessions

Thanks for your time and advice.

That’s right. Both datasets get shifted and interpolated a similar amount. Even with just 3 sessions, there are still lots of options. Most should work well depending on how much change is expected. Age, surgery, disease, exercise, juggling,… - will have varying effects with time.

Take for example 3 sessions, each with an Anatomical and an EPI scan.

A1,E1 A2,E2, A3,E3

Multi-session data can be handled by aligning everything to any of the anatomical datasets. One could pick the first, middle or last for a desired relative measure.

E1->A1, E2->A1, E3->A1

Or if one were expecting larger physical changes, align everything to each session’s own anatomical and then that anatomical to a reference anatomical scan.

E1->A1, E2->A2->A1, E3->A3->A1

The reference anatomical scan could be an in-between anatomical dataset as in the script you linked instead.

A1 >< A2 → A12
E1->A12, E2->A12, E3->A12

For 3 sessions, you could extend this further with
A1 >< A2 → A12, A2 >< A3 → A23
A12><A23 → A123
E1->A123, E2->A123, E3->A123

or this variant using each session’s own anatomical as an intermediate:
A1 >< A2 → A12, A2 >< A3 → A23
A12><A23 → A123
E1->A1->A123, E2->A2->A123, E3->A3->A123

Or with a more sessions, make a new template out of the whole series of anatomical datasets in the same way we make templates out of multiple subjects:

A1,A2,…An → At
E1->A1->At, E2->A2->At, E3->A3->At

Another option, is to treat every session as a separate run in the same experiment. This requires some better alignment and motion correction across runs because shimming and distortions are likely to be different. These are some recent, useful options in afni_proc.py for dealing with multiple sessions as if they were runs in the same linear model:

-volreg_allin_cost lpa+zz                                                \
-volreg_post_vr_allin yes                                                \
-volreg_pvra_base_index MIN_OUTLIER                                      \

While this is likely a more complicated answer than what you might need, a lot depends on your particular set of experiments and research question.

Great thanks for this detailed response.

The last option is the route I am taking. As stated in my post I aligned all my runs regardless of session to the T1 from session 1 and things look good. I am plugging the runs from the different sessions into the same linear model treating them like runs from the same session. I can add the options you mentioned but how can I check to determine if I have problems with the motion correction stemming from having runs from different sessions? Also, what is lpa+zz? I found documentation for the other options you specified and I know lpa is local Pearson correlation absolute value cost function.

Thanks Again for your help

To check whether this works well, I would look at the time series in video and graph modes, just as with any EPI dataset, but I would pay special attention to the run breaks to see how well the alignment worked across runs. Also with afni_proc.py, you would use “-regress_motion_per_run” to regress motion parameters from each run separately.

The lpa+ZZ option is similar to the lpc+ZZ option and the lpa option. It blends the lpa option with a number of other cost function metrics for intermediate alignments but does final alignment with the lpa cost.

lpc :: nonlinear average of Pearson cc over local neighborhoods
lpa :: 1 - abs(lpc)
lpc+:: lpc + hel + mi + nmi + crA + overlap
lpa+:: lpa + hel + mi + nmi + crA + overlap

Great thanks again for your input

Hi Daniel,

I also have one question regarding alignment across two sessions.

Firstly, I aligned all epi datasets to each session’s own anatomical (E1->A1, E2->A2). Secondly, I used align_epi_anat.py to align the A2 from the second session to the A1 from the first session (A2->A1), and then computed their transformation matrix. Lastly, I used 3dAllineate and the transformation matrix to align E2 to A1. However, there is an warning related to 3dAllineate.

My script and Warning Message with 3dAllineate:

set anat1 = ‘anat1_final.xtexp+orig’
set anat2 = ‘anat2_final.xtexp+orig’

set epi2 = ‘pb02.xtexp.r01.volreg+orig’
set epi2_children = ls pb02.xtexp.r02.volreg+orig.HEAD \ pb02.xtexp.r03.volreg+orig.HEAD \ pb01.xtloc.r01.volreg+orig.HEAD \ pb02.xtexp.r04.volreg+orig.HEAD \ pb02.xtexp.r05.volreg+orig.HEAD \ pb02.xtexp.r06.volreg+orig.HEAD

# # align the two anatomical datasets (pre / post) and compute transformation matrix

align_epi_anat.py -anat anat2_final.xtexp+orig
-epi anat1_final.xtexp+orig
-epi_base 0 -prep_off
-anat_has_skull no
-epi_strip None
-giant_move -cost lpa
-overwrite -suffix _al

# # align epi2 to anat1

3dAllineate -base anat1_final.xtexp+orig -input pb02.xtexp.r01.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb02.xtexp.r07.volreg

3dAllineate -base anat1_final.xtexp+orig -input pb02.xtexp.r02.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb02.xtexp.r08.volreg

3dAllineate -base anat1_final.xtexp+orig -input pb02.xtexp.r03.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb02.xtexp.r09.volreg

3dAllineate -base anat1_final.xtexp+orig -input pb01.xtloc.r01.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb01.xtloc.r03.volreg

3dAllineate -base anat1_final.xtexp+orig -input pb02.xtexp.r04.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb02.xtexp.r10.volreg

3dAllineate -base anat1_final.xtexp+orig -input pb02.xtexp.r05.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb02.xtexp.r11.volreg

3dAllineate -base anat1_final.xtexp+orig -input pb02.xtexp.r06.volreg+orig
-1Dmatrix_apply anat2_final.xtexp_al_mat.aff12.1D -mast_dxyz 3
-prefix pb02.xtexp.r12.volreg

+ WARNING: Re-using final row of -1D_apply ‘anat2_final.xtexp_al_mat.aff12.1D’ for sub-brick #1
+ WARNING: Re-using final row of -1D_apply ‘anat2_final.xtexp_al_mat.aff12.1D’ for sub-brick #2

+ WARNING: Re-using final row of -1D_apply ‘anat2_final.xtexp_al_mat.aff12.1D’ for sub-brick #295

Thank you very much in advance!

-Xin

The warning is just to say it is applying the same matrix to many sub-brick volumes. The affine transformation matrix file allows for different affine transformations on each row to apply to a corresponding volume. This is typically used to apply motion correction in combination with the affine transformations of alignment to an anatomical dataset and alignment between anatomical datasets.