Finding clusters for a group

Hi, Dave-

There are 2 parts of this. Firstly, having your FS atlas/parcellation of interest on the same grid as the cluster dataset. I will start by assuming you have that, which can be verified with either:

# detailed output, should be five '1' values output 
# if all tested grid props match
3dinfo -same_all_grid -prefix DSET_ATLAS DSET_CLUST

# single number output, should be one '1' value output 
# if all tested grid props match (simpler for programming evaluation)
3dinfo -same_grid -prefix DSET_ATLAS DSET_CLUST

We can discuss getting to the same grid later. The simplest way to do this while processing is to use the 'follower ROI dataset' functionality in afni_proc.py, like in this Example 11:

afni_proc.py                                                         \
    -subj_id                  FT.11.rest                             \
    -blocks                   despike tshift align tlrc volreg blur  \
                              mask scale regress                     \
    ...
    -anat_follower_ROI        aaseg anat                             \
                              aparc.a2009s+aseg_REN_all.nii.gz       \
    -anat_follower_ROI        aeseg epi                              \
                              aparc.a2009s+aseg_REN_all.nii.gz       \

That way everything gets to the same space directly and happily with minimal interpolation.

The script I used for making the table from the "Highlight, Don't Hide" paper is called do_06_clust_olap.tcsh, and I guess I should add it to the github repo for the paper. In this case, one has to turn the FS parcellation dataset into atlasized form, which I just did on my computer separately for a follower dset:

# turn a FS follower parcellation into an atlasized reference for whereami
3dcopy follow_ROI_aaseg+tlrc.HEAD follow_ROI_aaseg_ATLIZE.nii.gz
@MakeLabelTable -atlasize_labeled_dset follow_ROI_aaseg_ATLIZE.nii.gz

Now, the above dataset can be referenced in a whereami call, as follow_ROI_aaseg_ATLIZE (note there is no file extension present). If you have an example cluster map output called Clust_mask+tlrc.HEAD, such a call to get the overlap list of ROI #1 could look like:

whereami -omask Clust_mask+tlrc.HEAD'<1>' -atlas follow_ROI_aaseg_ATLIZE

To make the table in the above Highlight paper, I scripted around this functionality, keeping a list of the maximal overlapping ROI and any others that have at least 10% of the ROI volume. The script to do this with the above dset is:

#!/bin/tcsh

# NB: this makes a table of whereami results when a Clust_table.1D is
# input.  It rearranges information with some awk-ward fun.

# This script is run from a directory with the Clust_table.1D file (at
# present).

# ---------------------------------------------------------------------------

setenv AFNI_WHEREAMI_NO_WARN YES

#set ref_atl = MNI_Glasser_HCP_v1.0
#  3dcopy follow_ROI_aaseg+tlrc.HEAD follow_ROI_aaseg_ATLIZE.nii.gz
#  @MakeLabelTable -atlasize_labeled_dset follow_ROI_aaseg_ATLIZE.nii.gz
#
#
set ref_atl = follow_ROI_aaseg_ATLIZE   # note: no file extension

set all_type = ( olap )

set min_olap = 10    # minimum percentile for overlap to be included in table

foreach ii ( `seq 1 1 ${#all_type}` )
    set type   = "${all_type[$ii]}"

    echo "++ Make table for: ${type}"

    # start the output file and formatting
    set ofile  = info_table_clust_wami_${type}.txt
    printf "" > ${ofile}
    printf "%5s  %5s   %7s  %s  \n"                       \
            "Clust" "Nvox" "Overlap" "ROI location"     \
        |& tee -a ${ofile}

    set idset  = Clust_mask+tlrc.HEAD            # dumped by GUI-Clusterize
    set nclust = `3dinfo -max "${idset}"`

    set tfile  = __tmp_file_olap.txt

    # go through the dset, int by int, to parse a bit
    foreach nn ( `seq 1 1 ${nclust}` )
        # create zero-based index
        @ mm = $nn - 1

        set nvox = `3dROIstats -nomeanout -quiet -nzvoxels \
                        -mask "${idset}<${nn}>"            \
                        "${idset}"` 

        whereami                                          \
            -omask "${idset}<${nn}>"                      \
            -atlas "${ref_atl}"                           \
            | grep --color=never '% overlap with'         \
            > ${tfile}

        set nrow = `cat ${tfile} | wc -l`

        set NEED_ONE = 1
        foreach rr ( `seq 1 1 ${nrow}` )
            set line = `cat ${tfile} | sed -n ${rr}p`
            set perc = `echo "${line}" | awk '{print $1}'`

            set roi = `echo "${line}"                           \
                        | awk -F'% overlap with' '{print $2}'   \
                        | awk -F, '{print $1}'`


            if ( ${NEED_ONE} ) then
                printf "%5d  %5d  %7.1f%%  %s  \n"             \
                    "${nn}" "${nvox}" "${perc}" "${roi}"       \
                    |& tee -a ${ofile}
                set NEED_ONE = 0
            else if (`echo "${perc} > ${min_olap}" | bc` ) then
                printf "%5s  %5s  %7.1f%%  %s  \n"             \
                    "" "" "${perc}" "${roi}"       \
                    |& tee -a ${ofile}
            endif
        end
    end
end

\rm ${tfile} 

cat <<EOF
------------------------------
DONE.

Check out:
${ofile}

EOF

It assumes 2 files in the same directory here: follow_ROI_aaseg_ATLIZE.nii.gz (atlasized FS-parcellation dset) and Clust_mask+tlrc.HEAD (3dClusterize cluster map of ROIs).

When I ran the above on my test case (essentially a seedbased correlation map after that afni_proc.py example 11 on the Bootcamp data), I got a table that looked like this in a file called info_table_clust_wami_olap.txt:

Clust   Nvox   Overlap  ROI location  
    1   7218      9.6%  Right-Cerebral-White-Matter  
    2    837     16.4%  ctx_rh_G_front_middle  
                 15.7%  ctx_rh_S_front_sup  
    3    295     18.6%  ctx_lh_G_precentral  
                 17.6%  ctx_lh_S_central  
                 11.7%  ctx_lh_G_postcentral  
    4    285     15.3%  Right-Cerebral-White-Matter  
                 13.1%  ctx_rh_G_front_middle  
                 11.8%  ctx_rh_G_front_sup  
    5    263     20.0%  ctx_lh_S_front_sup  
                 19.8%  ctx_lh_G_front_sup  
                 13.0%  ctx_lh_G_front_middle  
    6    233     21.2%  ctx_rh_G_and_S_cingul-Ant  
                 16.1%  ctx_lh_G_front_sup  
                 10.4%  ctx_rh_G_front_sup  
    7    164     26.3%  ctx_rh_S_temporal_sup  
                 22.5%  ctx_rh_G_temp_sup-Lateral  
                 22.2%  ctx_rh_G_temporal_middle  
                 11.3%  Right-Cerebral-White-Matter  
    8    111     18.6%  ctx_lh_G_front_middle  
                 10.8%  ctx_lh_G_front_sup  
    9     92     47.8%  ctx_rh_S_central  
                 16.4%  ctx_rh_G_precentral  
                 15.4%  Right-Cerebral-White-Matter  
   10     91     31.1%  ctx_lh_S_front_inf  
                 14.6%  ctx_lh_G_front_middle  
                 12.4%  Left-Cerebral-White-Matter  
   11     89     36.5%  ctx_lh_G_front_middle  
                 16.5%  Left-Cerebral-White-Matter  
                 10.8%  ctx_lh_S_front_middle  
   12     63     48.3%  ctx_lh_G_and_S_cingul-Mid-Post  
                 14.1%  ctx_lh_G_front_sup  
   13     60     43.0%  ctx_rh_S_front_inf  
                 39.0%  Right-Cerebral-White-Matter  
   14     46     35.6%  ctx_lh_G_and_S_occipital_inf  
   15     43     39.5%  ctx_lh_G_front_sup  
   16     42     32.2%  ctx_rh_G_temporal_inf  
                 24.9%  Right-Cerebral-White-Matter  
                 22.8%  ctx_rh_S_temporal_inf  
   17     42     53.5%  ctx_rh_G_temporal_middle  
                 13.1%  Right-Cerebral-White-Matter  

--pt