Fixing Alignment and Installing PyQt4

It’s a long story how I got here. I was studying MRIs on AFNI and noticed that with some of my scans, the resting and functional alignment was very, very bad. I worked with Rick Reynolds to revise the processing script, and that worked for a while, but most of our last few scans have terrible alignment and the new script doesn’t fix it. I noticed the following error messages in the badly aligned data runs:

Center of mass shifts (-cmass) are turned off, but would be large
-at least one is more than 20% of search range
Cmass xyz shifts = [numbers varied depending on the dataset]
Shift search range is +/- = [numbers varied]
Center of mass shifts turned off, but would be TERRIBLY large!
At least 1 is more than 50% of search range
Cmass xyz shifts = [numbers varied depending on the dataset]
Shift search range is +/- = [numbers varied]
Cmass was turned off, but might have been needed :frowning:
Please check your results – PLEASE PLEASE PLEASE
No output dataset will be calculated

I also saw multiple messages about considering running “3dWarp -deoblique” if I am “performing spatial transformations on an oblique dset or viewing/combining it with volumes of differing obliquity.”
My colleague suggested I run uber_subject.py, which would allow me to insert the suggested lines, e.g. -cmass. But when I tried to run uber_subject.py, I was told I need python-qt4.

Relevant information, perhaps: the patients range from infant to 13 years old, male and female. My work involves finding connectivity networks, so I open resting and anatomical data in AFNI and they should overlap more or less exactly. I didn’t write the processing scripts.

I tried using anaconda to install python-qt4, and that didn’t work.

Is there an updated version of python-qt4? How do I work around this? Or, more simply, is there a way to fix this alignment?

Howdy-

I think the best way to go would be to paste your current afni_proc.py (AP) command here, and we can recommend tweaking options from there. The PyQt4 dependencies are really difficult nowadays. We have let uber_subject.py lapse because, in general, working with the AP script directly is clearly and easier to discuss, particularly on the Message Board here. (All uber_subject.py did was wrap around filling in fields within the AP command anyways—when writing back and forth, simply adjusting text is most straightforward.)

Some things that should help diagnose issues, as well, are the automatically created QC HTML by afni_proc.py, too. That will even make images of initial EPI-anatomical overlap, which might suggest how to add options.

It would be good to verify that you have a current/modern AFNI version, too. What is your “afni -ver”? You can always run “@update.afni.binaries -d” to update it, if you are using a binary distribution.

–pt

Here is the new version of the script:


#!/bin/sh

# To run this script, use the following arguments in the specified order:
#
# argument 1 - subject ID
# argument 2 - resting state dataset
# argument 3 - anatomical dataset

afni_proc.py                                                                 \
    -subj_id                  $1                                             \
    -dsets                    $2                                             \
    -copy_anat                $3                                             \
    -blocks                   despike tshift align tlrc volreg blur mask     \
                              scale regress                                  \
    -tcat_remove_first_trs    3                                              \
    -align_opts_aea           -cost lpc+zz                                   \
                              -Allineate_opts  -source_automask+4        \
    -tlrc_base                MNI152_T1_2009c+tlrc                           \
    -tlrc_NL_warp                                                            \
    -volreg_align_e2a                                                        \
    -volreg_tlrc_warp                                                        \
    -mask_epi_anat            yes                                            \
    -blur_size                6                                              \
    -regress_anaticor                                                        \
    -regress_censor_motion    0.2                                            \
    -regress_censor_outliers  0.05                                           \
    -regress_bandpass         0.01 0.1                                       \
    -regress_apply_mot_types  demean deriv                                   \
    -regress_est_blur_epits                                                  \
    -regress_est_blur_errts

The old version doesn’t have the line starting with -align_opts_aea -cost…

Hi-

Thanks for posting that.

OK, I would update the align_opts_aea option (for controling anatomical-EPI alignment, AEA) to be:


-align_opts_aea           -cost lpc+zz -giant_move -check_flip     \

That is our general starting point—from the options you cited above, the “-giant_move” might be necessary to open up the parameter search space for the alignment. The “-check_flip” is generally useful as a quick check against left-right flip badness, which happens:
https://www.frontiersin.org/articles/10.3389/fninf.2020.00018/full
You can also keep the “-Allineate_opts -source_automask+4” part, too (though I am not sure it is necessary in the updated case—I think the -giant_move might have that as part of it). I also realize I am not sure what previous iterations you might have had of the command overall…

I would also add this new option:


-align_unifize_epi local

… which often helps overcome EPI brightness inhomogeneity.

I would add this for letting the program pick the EPI volume with minimal numbers of outliers to be the EPI-anatomical reference volume, as well as “motion correction” reference volume:


-volreg_align_to          MIN_OUTLIER                              \

That is the most secure way to go for those processes.

You should state whether the anatomical has a skull on or not, so the program knows:


-anat_has_skull           no                                       \

(adjust “no”/“yes”, as necessary). In my comment below about using @SSwarper before afni_proc.py, you would be able use a skullstripped output from that former program and then put “no”, as here.

I see you have: “-regress_anaticor”. To do anaticor, I would typically suggest running FreeSurfer first to get higher specificity segmentations of tissue for defining where to get the tissue-based signals from.

For nonlinear alignment, we would generally recommend running @SSwarper first, and then passing the results into afni_proc.py to be used. How does that sound? It combines the nonlinear alignment with anatomical skullstripping, as a bonus.

I would add in this option for some more QC items:


-radial_correlate_blocks  tcat volreg                              \
     -volreg_compute_tsnr      yes                                      \

You might only have one EPI run, but I generally include this option, include this option, so I don’t forget to in cases that I have more than one:


-regress_motion_per_run                                            \

–pt

I tried -giant_move and -ginormous_move at someone else’s suggestion with -check_flip, but without any other suggested revisions, just to see if they made a difference. The alignment looked the same–that is, just as bad.
If it helps, I noticed in the bad alignment cases, even when I did giant and ginormous move, the following warning messages popped up:

Center of mass shifts (-cmass) are turned off, but would be large
-at least one is more than 20% of search range
Cmass xyz shifts = [numbers varied depending on the dataset]
Shift search range is +/- = [numbers varied]
Center of mass shifts turned off, but would be TERRIBLY large!
At least 1 is more than 50% of search range
Cmass xyz shifts = [numbers varied depending on the dataset]
Shift search range is +/- = [numbers varied]
Cmass was turned off, but might have been needed :frowning:
Please check your results – PLEASE PLEASE PLEASE
No output dataset will be calculated
I also saw multiple messages about considering running “3dWarp -deoblique” if I am “performing spatial transformations on an oblique dset or viewing/combining it with volumes of differing obliquity.” This message appeared several times, listing several datasets—it would mention one set a few times, another set at different times, if that makes sense. Then when I opened the data in AFNI, I get a message saying the underlay/overlay pair of datasets have oblique angle differences of x degrees (x varies; I’ve seen 6.898816 and 14.807095) and again suggesting I run 3dWarp -deoblique on this and other oblique datasets in the same session. I don’t know where I would put the 3dWarp -deoblique command, though.
Thanks to everyone who offered suggestions so far.