Complete a region of interest (ROI) analysis in FSL (FEATQUERY) and summarize the output for analysis (FSL)

You want to do a region of interest analysis, and you want it be automated. FSL is great here as it has a number of in-built structural regions of interest, or you can choose a point (coordinates) and put a sphere of a given size around this. FSL then projects this ROI into the participant’s native space and extracts the average value from this region. The following will let you batch your ROI analysis. Before you begin, a great review of the rationale for ROI analysis and some key conceptual issues is provided by Russell Poldrack here. Also before you begin, don’t forget to keep your data organized in a common structure to allow easy scripting; for e.g. with the output path for analyses being something like /disk/researcher/study/SUBJECT/task.feat for every participant.

1. First, define your region of interest.

STRUCTURAL ROI: With respect to the ROI you use, you have the options of the in-built structural ROI which you can select from multiple different atlases (run the fsl gui, then choose ‘featquery’ from the ‘misc’ menu, and choose input ROI). For instance, the Harvard-Oxford cortical atlas has many good regions.

You can also save ROI out of another program such as the WFU pickatlas, which runs within matlab. You can also draw the ROI manually using other software.

FUNCTIONAL ROI: You can define functional ROI in multiple ways. One good way is to find a consensus opinion of where the functional region you are looking at is. Find a good review, and look at the coordinates of the region most typically quoted. Alternately, find a canonical study and take the coordinates from that. For instance, for the network of brain regions involved in “self projection” Spreng and colleagues ran a meta-analysis, and gave coordinates for the point of overlap between these networks. They offer coordinates for this region. For your study, you need to make sure the coordinates are in MNI-152 space not Talairach space, as FSL uses MNI-152 space (see discussion here; as an aside, always use MNI-152 rather than Talairach).

An alternative is to take a functional region from your own dataset. To do this, you have to be careful not to “double dip”, define a region where you see differences then interrogate this region to see if a difference exists (because you will of course see a difference). To do this appropriately, if you are have one group and are looking at activation across a range of three language tasks, you may first define the contrast “all language tasks > baseline/rest”, and do a second level analysis. This second level analysis can give you the point of greatest activation. You could then take this point for further analysis (i.e., use this point as your functional ROI) to see which of the conditions demonstrates the most activation in this area.

2. Run your analysis using the GUI in one participant.

When running your analysis you want to select the contrast images (COPE iamges( rather than the thresholded statistical maps.

After doing this you will copy the command line output from featquery into a shell script and modify it, with the below template, in a shell file, to batch the analysis. The script iteratively runs the analysis on a series of ROI then summarizes the output into a single (excel labelled) file. You can then complete (e.g.) t-tests or ANOVAs in excel, matlab etc. to examine group differences in blood flow within the ROI.

The below takes as input a list of cope folder numbers and a list of roi images. At the moment you also need to edit the actual feat folder paths for (a) featquery and (b) the later data summation [these are organized by group to make things easier].

I’ve tried to comment everything to explain it, and to clearly indicate in CAPS how you can modify it. If you use this, please let me know when you find things that are unclear.

#########################

#!/bin/sh

. /etc/fsl/fsl.sh

#This file runs featquery on a selected set of COPE images for a selected set of FEAT outputs.
#currently setup for 24 directories of data for a specific study.
#Chris Benjamin 08-20-2011

#list of the contrast images you want to extract the ROI blood-flow values from
COPENUMS=”cope7 cope8 cope9 cope10 cope22 cope24 cope25 cope26 cope27 cope29 cope31 cope33 cope35 cope37″

#path name for the folder containing the ROI you’d like to interrogate
ROIPATH=’/net/rc-fs-nfs/ifs/data/Shares/directory/data/STUDY/second_levels/roi/2_functional_ROI_rfx/’

#the names of the roi themselves, as named in the directory you just defined

FQ_OUTPUTDIRNAMES=”1a_pfc_L_rfx_fn_plus_struc
2a_sma_L_rfx_fn_plus_struc
3a_par_L_rfx_fn_plus_struc
1b_pfc_R_rfx_fn_plus_struc
2b_sma_R_rfx_fn_plus_struc
3b_par_R_rfx_fn_plus_struc
1c_pfc_BI_rfx_fn_plus_struc
2c_sma_BI_rfx_fn_plus_struc
3c_par_BI_rfx_fn_plus_struc”

#the image format. This is the file suffix for the ROI you just listed in the above step.
IMAGEFORMAT=’.nii.gz’

#name of the folder you want output spat into.
FOLDERFORDATA=’foi_output_fqengine’

#Print to screen that the processing is now starting
echo ‘Starting featquery.’

#Now run the featquery script.
#”Repeat the following for each ROI you defined above…”
for FQ_OUTPUTDIRNAME in $FQ_OUTPUTDIRNAMES ; do

#”… first print the name of the current directory to screen, as well as the current time…”
echo ${FQ_OUTPUTDIRNAME}
date -u

#”… then, for the current ROI, I want you do the following for each of the contrast images I defined…”
for COPENUM in $COPENUMS ; do

#”… print the current contrast image number to screen… ”
echo ${COPENUM}

#”… run this FEATquery command…”
#… THIS IS WHERE YOU PASTE IN YOUR FEATQUERY OUTPUT. A few important things.
# 1. First, after triggering featquery and listing the number of images (24) the location of each COPE image is listed. As you are taking your featquery template from the last time you ran it, you need to change the cope feat output to ${COPENUM}.feat.
# 2. Change the output file name to ${FQ_OUTPUTDIRNAME} … this means that each time featquery is run on a different ROI (on all your subjects) the output will be put into a file with the name of the current ROI that you listed above.
# 3. You also need to change the final part of the command, the output name, to $ROIPATH${FQ_OUTPUTDIRNAME}$IMAGEFORMAT This is the ROI file that will be used when featquery is run.

/usr/share/fsl/4.1/bin/featquery 24 /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR003/d_shifting_fsl/f4.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR004/d_shifting_fsl/f4.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR012/d_shifting_fsl/f4.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR021com/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR023/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR025/d_shifting_fsl/f.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR027/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR028/d_shifting_fsl/f.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR030/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR032/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR034/d_shifting_fsl/f.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR037/d_shifting_fsl/f.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR005/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR006/d_shifting_fsl/f4.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR011/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR013/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR015/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR016/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR017/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR019/d_shifting_fsl/f2.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR022/d_shifting_fsl/f1.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR024/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR026/d_shifting_fsl/f3.gfeat/${COPENUM}.feat /net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR029/d_shifting_fsl/f3.gfeat/${COPENUM}.feat 1 stats/cope1 ${FQ_OUTPUTDIRNAME} -p -s $ROIPATH${FQ_OUTPUTDIRNAME}$IMAGEFORMAT

done

done

#”now please summarize the actual values from this analysis into a text file for me.”
echo ‘… featqueries finished. Summarizing data …’

#make a folder for the cope values to be spat out into, and move into it.
mkdir $FOLDERFORDATA
cd $FOLDERFORDATA

#”… now, for each ROI… ”
for FQ_OUTPUTDIRNAME in $FQ_OUTPUTDIRNAMES ; do

#”… output to the screen which ROI you are working on, and the time…”
echo ${FQ_OUTPUTDIRNAME}
date -u

#”…first, create a summary file to hold all of the output from this featquery (region of interest)…”
SUMMARYFILE=”roi_summary_${FQ_OUTPUTDIRNAME}.xls”
touch ${SUMMARYFILE}

#”…Now, for each contrast image that we looked at…”
for COPENUM in $COPENUMS ; do

#”… print the current contrast you are summarizing to screen…”
echo $COPENUM

#”…Print the cope number into summary file, with tab and newline…”
echo $COPENUM ‘\t\n’ >> ${SUMMARYFILE}

#”… now I’m going to list the input directories, and tell you how set up how you should output the data into the excel file.
#First I want the controls’ data.
# FOR EACH SUBJECT, PUT THE ENTIRE PATH TO THEIR FEAT DIRECTORY (.FEAT OUTPUT), AND AFTER LISTING THAT DIRECTORY PUT ${COPENUM}.feat
# THIS WILL BE REPEATEDLY UPDATED AS THE SCRIPT RUNS THROUGH TO TAKE THE VALUE OUT FOR EACH CONTRAST (COPE)

INPUTDIRS=”/net/rc-fs-nfs/ifs/data/Shares/LAB/data/STUDY/GR003/d_shifting_fsl/f4.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR004/d_shifting_fsl/f4.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR012/d_shifting_fsl/f4.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR021com/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR023/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR025/d_shifting_fsl/f.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR027/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR028/d_shifting_fsl/f.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR030/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR032/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR034/d_shifting_fsl/f.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR037/d_shifting_fsl/f.gfeat/${COPENUM}.feat”

#”…Now I want the patient data listed in the excel file. …”
#IF YOU ONLY HAVE ONE GROUP, DELETE THIS SECTION, ELSE ENTER NAMES FOR GROUP TWO, AS IN PREVIOUS STEP”
INPUTDIRS2=”/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR005/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR006/d_shifting_fsl/f4.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR011/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR013/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR015/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR016/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR017/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR019/d_shifting_fsl/f2.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR022/d_shifting_fsl/f1.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR024/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR026/d_shifting_fsl/f3.gfeat/${COPENUM}.feat
/net/rc-fs-nfs/ifs/data/Shares/LAB/data/DATA/GR029/d_shifting_fsl/f3.gfeat/${COPENUM}.feat”

#”… now, create a separate output file for writing the current summary to (this is redundant cf. the excel file you created above)… ”
OUTPUTFILE=”${COPENUM}${FQ_OUTPUTDIRNAME}.txt”

#”… now compile all the COPE values…”
touch ${OUTPUTFILE}

for INPUTDIR in $INPUTDIRS ; do

# GROUP 1
#”…print file location, in the summary file…”
echo $INPUTDIR ‘\t’ >> ${OUTPUTFILE}

#”…print cope mean into summary file for THIS SPECIFIC person/contrast [i.e., ${OUTPUTFILE}]…”
awk ‘NF{printf(“\t%f\n”, $6)}’ ${INPUTDIR}/$FQ_OUTPUTDIRNAME/report.txt >> ${OUTPUTFILE}

#”…print file location to screen…”
echo $INPUTDIR ‘\t’ >> ${SUMMARYFILE}

#”…print cope mean into the EXCEL summary file [i.e., ${SUMMARYFILE}]… ”
awk ‘NF{printf(“\t%f\n”, $6)}’ ${INPUTDIR}/$FQ_OUTPUTDIRNAME/report.txt >> ${SUMMARYFILE}

done

#GROUP 2. DELETE THIS SECTION IF YOU ONLY WANT TO DO THE DATA FOR A SINGLE GROUP.
echo “\nGroup 2\n” >> ${OUTPUTFILE}

for INPUTDIR2 in $INPUTDIRS2 ; do

#print file location
echo $INPUTDIR2 ‘\t’ >> ${OUTPUTFILE}

#print cope mean
awk ‘NF{printf(“\t%f\n”, $6)}’ ${INPUTDIR2}/$FQ_OUTPUTDIRNAME/report.txt >> ${OUTPUTFILE}

#print file location
echo $INPUTDIR2 ‘\t’ >> ${SUMMARYFILE}

#print cope mean
awk ‘NF{printf(“\t%f\n”, $6)}’ ${INPUTDIR2}/$FQ_OUTPUTDIRNAME/report.txt >> ${SUMMARYFILE}

done

#”put a few spaces into the summary file, before printing the new values”
echo ‘\n\n’ >> ${SUMMARYFILE}

done

done

echo ‘finished.’

date -u

Leave a comment