Some problems about align_epi_anat.py

Hello,I have met some problems about align_epi_anat.py
Every subject in my research will scan 2 times(every time the subject will scan epi and T1 weighted image) and now I want to check the difference between sessions in individual level.
Instead average the anat1 and anat2,I try to align epi1(the first session) to the anat2(the second session) cause the second scanning result is more meaningful to me.

Here are my script:

anat1=$input1/anat1+orig
anat2=$input2/anat2+orig

# pick one epi dataset as the main one to which to align
# and the others from the same condition as the children
# Usually one picks the dataset that is closest in time to the anatomical dataset but that's not very important really

epi1=$input1/run1+orig
epi1_children=`ls $input1/run2+orig.HEAD \
                  $input1/run3+orig.HEAD \
                  $input1/run4+orig.HEAD \
                  $input1/run5+orig.HEAD \
                  $input1/run6+orig.HEAD`
epi2=$input2/run1+orig
epi2_children=`ls $input2/run2+orig.HEAD \
                  $input2/run3+orig.HEAD \
                  $input2/run4+orig.HEAD \
                  $input2/run5+orig.HEAD \
                  $input2/run6+orig.HEAD`

# skullstripping 
3dSkullStrip -prefix anat1_ns -input $anat1
3dSkullStrip -prefix anat2_ns -input $anat2

##align anat1 to anat2 (default: align anat to epi)

align_epi_anat.py       -anat anat1_ns+orig    \
                        -epi anat2_ns+orig     \
                        -epi_base 0  -prep_off \
                        -anat_has_skull no     \
                        -epi_strip None        \
                        -giant_move -cost lpa  \
                        -overwrite -suffix _al

#align epi to anat
#align epi1 to anat1
align_epi_anat.py -anat anat1_ns+orig
-epi $epi1 -epi_base 0 -volreg_base 2 -epi2anat -master_epi MIN_DXYZ
-suffix _al
-anat_has_skull no -overwrite
-giant_move -child_epi $epi1_children
#align epi1# to anat2, epi1# generated form aligning epi1 to anat1
#‘-pre_matrix’ need input 3*4 matrix but the matrix generated from anat1 align to anat2 is oneline so I replaced with ‘-post_matrix’
for run in run{1…6}
do
align_epi_anat.py -anat anat2_ns+orig
-epi $input1/${run}_al+orig -epi_base 0 -volreg_base 2 -epi2anat -master_epi MIN_DXYZ
-post_matrix anat1_ns_al_mat.aff12.1D
-anat_has_skull no
-giant_move
-overwrite -suffix _2post
done
done

My problems:
1.I am not sure whether the script is proper although the result seems not bad to me.
2.Also I want to use ‘-pre_matrix’ because this option seems more accurate than ‘-post_matrix’ ,but I don’t know how to transpose the matrix by afni command.
Looking forward to your advice
Thank you !!!

Hi-

Have you considered using afni_proc.py for your full processing, which includes align_epi_anat.py for this intermediate EPI->anatomical alignment step? That will greatly facilitate combining all alignment steps (motion correction, EPI-> anatomical, anatomical-> template) correctly and with minimal smoothing to your EPI…

My problems:
1.I am not sure whether the script is proper although the result seems not bad to me.
2.Also I want to use ‘-pre_matrix’ because this option seems more accurate than ‘-post_matrix’ ,but I don’t know how to transpose the matrix by afni command.
Looking forward to your advice
Thank you !!!

Re. your particular alignment questions
Q1a) How far apart are your dsets to start? If you have a current AFNI, what does, say, the sagittal and coronal images of the following look like (just over/underlays the EPI and anatomical in their initial positions).


@djunct_overlap_check -ulay DSET_ANAT -olay DSET_EPI

An example of good initial alignment is attached-- the two datasets have a close starting point. It is quite possible that because you are aligning scans from different days, the coordinate grids of each are unfortunately far away.

Q1b) 1) is any of your data oblique? What is the output of:


3dinfo -obliquity -prefix DSET_EPI DSET_ANAT

Q2a) By “transpose”, do you mean “invert”? To invert a matrix,


cat_matvec MATRIX_FILE -I > MATRIX_FILE_NEW

Q2b) To transpose a 1D file,


1dtranspose FILE_IN > FILE_OUT_TRANSPOSED

–pt

Adding on to Paul’s advice - alignment across sessions can be done a few ways.

If you want to remove a bias from one session or the other, you can follow the method proposed here.
https://sscc.nimh.nih.gov/sscc/dglen/alignmentacross2sessions

Variations of that aligning each EPI to its own anatomical if there is one available. Then transform that to the in-between anat, then possibly to a standard space.

You can also use an approach that uses separate epi bases for each session. Then it aligns the EPI data across sessions with an affine alignment. Note that our typical motion correction program, 3dvolreg, assumes the same grid (origin, voxel sizes, number of voxels,…) between the base dataset and input datasets. Use “-volreg_post_vr_allin yes” and see the other “-volreg_allin…” options for more details.

Hi,thank you for your help
Every subject was scanned two times across 2 weeks. Each session has both anatomical and EPI datasets.The head motion is a big problem, the oblique warning always appeared when I run the afni_proc.py.

My research is mainly about language learning,and I concentrate more on the post-test results. So I am trying to align the data with a bias.
I have read Daniel Glen’s script before, and I try to imitate his method to align EPI datasets across days (but with a bias )before I really start to run afni_proc.py.

I’m not sure if there’s still a question. Overall, you may be making this more complicated than needed for your situation. Generally, you can use afni_proc.py’s standard procedures for most analyses. You could simply analyze these separately with a common anatomical dataset between the two sessions.

The post and pre-xform options from align_epi_anat.py are not “pre” and “post” session transformations. They are intended as affine transformations for adjustment of the coordinate system for obliquity or center transformation (pre-xform) or for transformation to a standard space (post-xform). You can use the post-xform for this case, I think, but you will have to be careful about the direction of the transformations.