ROI analysis 2 (FSL)

#!/bin/sh

#This file is run following second level analyses to complete a ROI analysis.

#1. Extracts contrast values (runs featquery on a selected set of COPE images for a selected set of FEAT outputs).

#2. Summarizes these into a txt/xls document (currently takes 24 single subject directories).

#Chris Benjamin 08-20-2011

COPENUMS=”cope1 cope2″

#path name for the folder containing the ROI you’d like to interrogate

ROIPATH=’/path/ROI_rfx/’

#the roi themseleves. Name of both the roi, and the output forlder. Do not include .nii.gz

FQ_OUTPUTDIRNAMES=”roi_dir_name1

roi_dir_name2″

#the image format

IMAGEFORMAT=’.nii.gz’

#name of the folder you want all output folders spat into.

FOLDERFORDATA=’foi_output_fqengine’

echo ‘Starting featquery.’

#featquery script, batched.

for FQ_OUTPUTDIRNAME in $FQ_OUTPUTDIRNAMES ; do

echo ${FQ_OUTPUTDIRNAME}

date -u

for COPENUM in $COPENUMS ; do

echo ${COPENUM}

/usr/share/fsl/4.1/bin/featquery nparticipants PATH_TO_GFEAT_FOLDER_FOR_ALL_nparticipants 1 stats/cope1 ${FQ_OUTPUTDIRNAME} -p -s $ROIPATH${FQ_OUTPUTDIRNAME}$IMAGEFORMAT

done

done

echo ‘… featqueries finished. Summarizing data …’

#Now summarize all the actual cope values into text files.

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

mkdir $FOLDERFORDATA

cd $FOLDERFORDATA

#For each featqueried output

for FQ_OUTPUTDIRNAME in $FQ_OUTPUTDIRNAMES ; do

echo ${FQ_OUTPUTDIRNAME}

date -u

#create a summary file to hold all of the output from this featquery (region of interest)

SUMMARYFILE=”roi_summary_${FQ_OUTPUTDIRNAME}.xls”

touch ${SUMMARYFILE}

#For each cope…

for COPENUM in $COPENUMS ; do

echo $COPENUM

#Print cope number into summary file

echo $COPENUM ‘\t\n’ >> ${SUMMARYFILE}

#Input directories.

#controls

INPUTDIRS=”PATH_TO_GFEAT_FOLDER_FOR_ALL_nparticipants_group1

E.G. /path/PT_ID/task_folder.gfeat/${COPENUM}.feat”

#musicians

INPUTDIRS2=”PATH_TO_GFEAT_FOLDER_FOR_ALL_nparticipants_group2

E.G. /path/PT_ID/task_folder.gfeat/${COPENUM}.feat”

#CREATE SEPARATE OUTPUT FILE FOR WRITING DOCS TO

OUTPUTFILE=”${COPENUM}${FQ_OUTPUTDIRNAME}.txt”

#COMPILE ALL OF THE COPE VALUES.

touch ${OUTPUTFILE}

for INPUTDIR in $INPUTDIRS ; do

#print file location

echo $INPUTDIR ‘\t’ >> ${OUTPUTFILE}

#print cope mean

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

#print file location

echo $INPUTDIR ‘\t’ >> ${SUMMARYFILE}

#print cope mean

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

done

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

echo ‘\n\n’ >> ${SUMMARYFILE}

done

done

echo ‘finished.’

date -u

Leave a comment