Instructions for Analyzing a fMRI Data Set using Logical AND, Logical OR, and Exclusive OR
- Before beginning ensure that the data has been converted from dicoms and BOLDfold
has been run. This is usually done at the end of each fMRI session.
- You should have files with .BRIK, .HEAD, .spr, .sdt and files with BF in the name.
- this example uses the Gaze data set. There are 9 subjects (184 185 186 187 188 189 192 198 202) and 3 stimuli (schem arrow real)
- You can run this analysis from the command line but to make it
easier scripts have been created which use loops to run each command
multiple times for each subject and stimuli combination required (for
more information on how loops work see the Getting Looped tutorial)
- for each script you will have to change the subject numbers
(sub) and the stimulus (stim) to the ones for your data set and save
the file
- to change the file to an executable (commands in this
tutorial that are to be run from the command line with begin with a
command prompt ex.[fMRI@wilder]$)
[fMRI@wilder]$ chmod a+x script_name
- you can download all the scripts here or copy the text into gedit
Preparing the Data for Analyzing
- Write all AFNI anatomical and functional datasets to Talairach orientation (+tlrc)
- Create a directory structure for data within the projects directory
- these directories are required to run the scripts
[fMRI@wilder]$ mkdir analysis
[fMRI@wilder]$ mkdir ./analysis/baseline ./analysis/calcs
[fMRI@wilder]$ mkdir ./analysis/baseline/means ./analysis/calcs/means
- Rename the Talairached files and move them into the analysis directory
- run rename.sh script to add the subject number to the tlrc files and move them into the analysis directory
#!/bin/tcsh
foreach sub ( 184 185 186 187 188 189 192 198 202 )
foreach stim ( schem arrow real )
echo $sub $stim
cp ./${sub}/${stim}_BFmap+tlrc.HEAD ./analysis
cp ./${sub}/${stim}_BFmap+tlrc.BRIK ./analysis
mv ./analysis/${stim}_BFmap+tlrc.HEAD ./analysis/${sub}_${stim}_BFmap+tlrc.HEAD
mv ./analysis/${stim}_BFmap+tlrc.BRIK ./analysis/${sub}_${stim}_BFmap+tlrc.BRIK
end
end
Creating Relax Baseline Mean Maps
- Clustering
- cd to the analysis directory
- run cluster_baseline.sh script to 'clip' any voxels that are not found within clusters
- this is done so we only compare significantly activated areas
- -1noneg removes all voxels that are negative
- -1thresh 0.60 defines the threshold value - this may change depending on your analysis
- -1clust 1.1 100 removes all voxels that are not in clusters of at least 100 microliters
#!/bin/tcsh
foreach stim ( arrow schem real )
foreach sub ( 184 185 186 187 188 189 192 198 202 )
echo $stim $sub
3dmerge -1noneg -1thresh 0.60 -1clust 1.1 100 -session ./baseline
-prefix ${sub}_${stim}_BFmap_clip1 ${sub}_${stim}_BFmap+tlrc
end
end
- Blurring
- cd baseline
- run the blur_baseline.sh script to blur the data. Run in you baseline directory.
- this maximizes the chances of corresponding regions of activation, in corresponding anatomical areas, overlapping in the ANOVA
- 1blur_fwhm 3.91 - defines the blur as full width half mass at 3.91 <
/ul>
#!/bin/tcsh
foreach stim ( arrow schem real )
foreach sub ( 184 185 186 187 188 189 192 198 202 )
echo $stim $sub
3dmerge -1noneg -1blur_fwhm 3.91 -prefix ${sub}_${stim}_blur3.91_BFmap ${sub}_${stim}_BFmap_clip1+tlrc
end
end
- Create the Relax Baseline Mean Maps using ANOVA
- you
are using the ANOVA program to get mean values and associated t-values
indicating whether the average intensity is significantly greater than
0.
- since we can't run ANOVA in a loop there is more that needs to be changed in the anova_baseline.sh script to match your dataset
- run this in the baseline directory too
- -dset defines the datasets (in our example dset1 is all the arrow maps)
- -levels defines the number of stimuli (in our example 3)
- -mean # defines the file name for the final maps
#!/bin/tcsh
3dANOVA -session ./means -levels 3 \
-dset 1 184_arrow_blur3.91_BFmap+tlrc -dset 1 189_arrow_blur3.91_BFmap+tlrc \
-dset 1 185_arrow_blur3.91_BFmap+tlrc -dset 1 192_arrow_blur3.91_BFmap+tlrc \
-dset 1 186_arrow_blur3.91_BFmap+tlrc -dset 1 198_arrow_blur3.91_BFmap+tlrc \
-dset 1 187_arrow_blur3.91_BFmap+tlrc -dset 1 202_arrow_blur3.91_BFmap+tlrc \
-dset 1 188_arrow_blur3.91_BFmap+tlrc \
-dset 2 188_schem_blur3.91_BFmap+tlrc -dset 2 184_schem_blur3.91_BFmap+tlrc \
-dset 2 189_schem_blur3.91_BFmap+tlrc -dset 2 185_schem_blur3.91_BFmap+tlrc \
-dset 2 192_schem_blur3.91_BFmap+tlrc -dset 2 186_schem_blur3.91_BFmap+tlrc \
-dset 2 198_schem_blur3.91_BFmap+tlrc -dset 2 187_schem_blur3.91_BFmap+tlrc \
-dset 2 202_schem_blur3.91_BFmap+tlrc \
-dset 3 184_real_blur3.91_BFmap+tlrc -dset 3 189_real_blur3.91_BFmap+tlrc \
-dset 3 185_real_blur3.91_BFmap+tlrc -dset 3 192_real_blur3.91_BFmap+tlrc \
-dset 3 186_real_blur3.91_BFmap+tlrc -dset 3 198_real_blur3.91_BFmap+tlrc \
-dset 3 187_real_blur3.91_BFmap+tlrc -dset 3 202_real_blur3.91_BFmap+tlrc \
-dset 3 188_real_blur3.91_BFmap+tlrc \
-mean 1 arrow_mean \
-mean 2 schem_mean \
-mean 3 real_mean
Creating Subtraction and Intersection Maps
- Zero out the voxels with negative intensities using 3dmerge
- i.e. change the intensity values for these voxels to zero
- cd ../../ to get back to the analysis directory
- run the volcode_noneg.sh script
#!/bin/tcsh
foreach stim ( arrow real schem )
foreach sub ( 184 185 186 187 188 189 192 198 202 )
echo $stim $sub
3dmerge -1noneg -prefix ${sub}_${stim}_BFmap_noneg ${sub}_${stim}_BFmap+tlrc
end
end
- Calculating the difference maps for each subject from the noneg
data.
- since
3dmerg -1noneg writes the maps out with one subbrick(subbrick 0 which
is intensity), we use subbrick 1 from the original maps to get the eta
value
- the maps_calc.sh script will do the calculations for 5 sets
of maps and write them to the calcs directory, since the script is
quite long you can download it here
- if
you have more than 3 stimuli you will need to change the script further
to define more tasks and add another section of calculations
- our example calculates the maps for real vs arrow, arrow vs schem and real vs schem
- For each calculation the 3dcalc command
- -a "${sub}_${task1}_BFmap+tlrc[1]" defines the eta value of the voxels in
${sub}_${task1}_BFmap+tlrc dataset as a in the expression
- -b defines the same for ${sub}_${task2}_BFmap+tlrc[1]
- -c
"${sub}_${task1}_BFmap_noneg+tlrc[0]" defines the intensity value of
the voxels in ${sub}_${task1}_BFmap+tlrc dataset as c in the expression
- -d defines the same for ${sub}_${task2}_BFmap_noneg+tlrc[0]
- -prefix ${sub}_${task1cap}subLogOr${task2cap}_ETA0.60 sets the name of the new dataset that will result from the calculation
- -section ${directory} tells the computer which directory to write the dataset to
- -expr
is the calculation that will be done on the dataset. Note that 3dcalc
does the calculation in the -expr expression once for each voxel
- Explanation of each map
- Logical OR, AND/OR Map
- also known as traditional map or dominance map
- shows
the activations that are significant in either tasks, however if there
is significant activation in both, the dominant task activation shows
up
- 3dcalc
- -a "${sub}_${task1}_BFmap+tlrc[1]" \
- -b "${sub}_${task2}_BFmap+tlrc[1]" \
- -c "${sub}_${task1}_BFmap_noneg+tlrc[0]" \
- -d "${sub}_${task2}_BFmap_noneg+tlrc[0]" \
- -prefix ${sub}_${task1cap}subLogOr${task2cap}_ETA0.60 \
- -session ${directory} \
- -expr "((step(a-0.60)*c)-(step(b-0.60)*d))"
- The expression breaks down to this:
- step(a-0.60) tells
the computer to return 1 if 'a' (the eta value) is greater than 0.60,
or 0 if 'a' is less than or equal to 0.60. The value returned by the
step function is then multiplied by the intensity of the voxel (which
is the value you assigned to 'c').
- Essentially what this means is that the intensity is only
used in the rest of the calculation if it meets the required eta
threshold. Otherwise it's treated as a zero value in the rest of the
calculation.
- The same thing is done with the threshold and intensity of the second dataset.
- After
the values have been cut off at the appropriate eta value, one dataset
is subtracted from the other, leaving you with a difference map showing
the difference in intensities between the two datasets for each voxel.
- Exclusive OR
- shows the significant activation in one task or the other
- activations that are significant in both tasks are not included
- 3dcalc
- -a "${sub}_${task1}_BFmap+tlrc[1]" \
- -b "${sub}_${task3}_BFmap+tlrc[1]" \
- -c "${sub}_${task1}_BFmap_noneg+tlrc[0]" \
- -d "${sub}_${task3}_BFmap_noneg+tlrc[0]" \
- -prefix ${sub}_${task1cap}subExcOr${task3cap}_ETA0.60 \
- -session ${directory} \
- -expr "(((step(a-0.60)*c)-(step(b-0.60)*d))*(1-(step(a-0.60)*step(b-0.60))))"
For this one you'll notice that the first part of the expression is the
same as the expression for logical or above. So that part gives you a
difference map as above. The second half of the expression breaks down
like this:
- step(a-0.60)*step(b-0.60) - using the step function described above, this returns 1
only if the intensity meets the threshold cutoff in both datasets. If this is
the case, that means the voxel is on in both datasets and should be
eliminated from this map.
- 1-(step(a-0.60)*step(b-0.60)) ensures that this will happen by returning 0, which
is then multiplied by the difference map, resulting in no intensity being
returned for the resulting map.
- Intersection
- shows the only the activations that are significant in both tasks
- 3dcalc
- -a "${sub}_${task1}_BFmap+tlrc[1]" \
- -b "${sub}_${task2}_BFmap+tlrc[1]" \
- -c "${sub}_${task1}_BFmap_noneg+tlrc[0]" \
- -d "${sub}_${task2}_BFmap_noneg+tlrc[0]" \
- -prefix ${sub}_${task1cap}int${task2cap}_ETA0.60 \
- -session ${directory} \
- -expr "((step(a-0.60)*step(b-0.60))*((c+d)/2))"
(step(a-0.60)*step(b-0.60)) returns one only if the voxel is on in both
datasets. If this is the case, the calculation is to return the average
of the intensities from the two datasets.
- A NOT B/ B NOT A
- shows what activations are in task A but not B and visa versa
- useful for volume counts
- Note: the command will say that c or d isn't used in this expression and it shouldn't be a problem as it isn't being used here.
- 3dcalc
- -a "${sub}_${task1}_BFmap+tlrc[1]" \
- -b "${sub}_${task2}_BFmap+tlrc[1]" \
- -c "${sub}_${task1}_BFmap_noneg+tlrc[0]" \
- -d "${sub}_${task2}_BFmap_noneg+tlrc[0]" \
- -prefix ${sub}_${task1cap}not${task2cap}_ETA0.60 \
- -session ${directory} \
- -expr "((step(a-0.60)-(step(a-0.60)*step(b-0.60)))*c)"
- 3dcalc
- -a "${sub}_${task1}_BFmap+tlrc[1]" \
- -b "${sub}_${task2}_BFmap+tlrc[1]" \
- -c "${sub}_${task1}_BFmap_noneg+tlrc[0]" \
- -d "${sub}_${task2}_BFmap_noneg+tlrc[0]" \
- -prefix ${sub}_${task2cap}not${task1cap}_ETA0.60 \
- -session ${directory} \
- -expr "((step(b-0.60)-(step(b-0.60)*step(a-0.60)))*d)"
These two codes produce a map of voxels that are active in one map but
not the other - essentially the exclusive or broken down into two maps
instead of having both sets of activation on the same map.
- As with the Baseline maps now cluster and blur the data
- cd calcs
- use cluster.sh first and then blur.sh. Both should be in the calcs directory.
#!/bin/tcsh
# clusher.sh
foreach sub ( 184 185 186 187 188 189 192 198 202 )
foreach stim1 ( ARROW REAL SCHEM )
foreach stim2 ( ARROW REAL SCHEM )
foreach mtype ( int subLogOr subExcOr )
echo $stim1 $stim2 $sub $mtype
3dmerge -1clust 1.1 100 -prefix ${sub}_${stim1}${mtype}${stim2}_ETA0.60_clip1 ${sub}_${stim1}${mtype}${stim2}_ETA0.60+tlrc
end
end
end
end
#!/bin/tcsh
# blur.sh
foreach sub ( 184 185 186 187 188 189 192 198 202 )
foreach stim1 ( ARROW REAL SCHEM )
foreach stim2 ( ARROW REAL SCHEM )
foreach mtype ( int subLogOr subExcOr )
echo $stim1 $stim2 $sub $mtype
3dmerge -1blur_fwhm 3.91 -prefix
${sub}_${stim1}${mtype}${stim2}_ETA0.60_clip1_blur3.91
${sub}_${stim1}${mtype}${stim2}_ETA0.60_clip1+tlrc
end
end
end
end
- Run ANOVA on the dataset (also in calcs directory)
- download the anova.sh script from here. Make sure you change the file names and the number of levels to match your dataset. This is also run in the calcs directory
Creating 3D Brains
- some steps are taken from 3D Rendering with AFNI. To see the full tutorial click here.
- Download the 3D anatomical brain (astrip+tlrc.BRIK and astrip+tlrc.HEAD)
- this brain has slightly different dimensions than the dataset that you have been working with.
- to correct this, you will need to make a copy of the average dataset map from the ANOVA.
- Make a duplicate of your dataset's header file (*.HEAD)
- use the dup_means.sh script run in ./calcs${stat}${statvalue}/mean
- Note that this spits out a lot of errors (this is normal as long as it gives you dup files)
#!/bin/tcsh
foreach stim ( ARROW SCHEM REAL )
foreach task ( ARROW SCHEM REAL )
foreach mtype ( int subLogOr subExcOr )
echo $stim $task $mtype
3ddup -prefix dup_${stim}${mtype}${task}_mean ${stim}${mtype}${task}_mean+tlrc
end
end
end
- Open AFNI
- Load astrip as the underlay
- Switch Anatomy
- choose astrip
- set
- Load dup_${stim}${mtype}${task}_mean as the overlay
- Switch Function
- choose a file that starts with dup
- set
- Write out the dataset
- Define Datamode
- Write Many
- highlight the dup files
- set
- exit afni
- Many datasets after the ANOVA will have two-sub-bricks with different data types for each sub-brick.
- you need to convert each subbrick to floats
- change the floatcode.sh script to match your files and run
- This also goes in ./calcs${stat}${statvalue}
- Note that this sometimes doesn't work as the file size (activation) is too little so the analysis has to be redone with the ETA/F-value brought down
#!/bin/tcsh
3dcalc -a 'dup_SCHEMintARROW_mean+tlrc[0]' -expr "a" -prefix sub0 -datum float
3dcalc -a 'dup_SCHEMintARROW_mean+tlrc[1]' -expr "a" -prefix sub1 -datum float
3dbuc2fim -prefix float_SCHEMintARROW_mean sub0+tlrc sub1+tlrc
3dcalc -a 'dup_SCHEMsubLogOrARROW_mean+tlrc[0]' -expr "a" -prefix sub2 -datum float
3dcalc -a 'dup_SCHEMsubLogOrARROW_mean+tlrc[1]' -expr "a" -prefix sub3 -datum float
3dbuc2fim -prefix float_SCHEMsubLogOrARROW_mean sub2+tlrc sub3+tlrc
3dcalc -a 'dup_SCHEMsubExcOrARROW_mean+tlrc[0]' -expr "a" -prefix sub4 -datum float
3dcalc -a 'dup_SCHEMsubExcOrARROW_mean+tlrc[1]' -expr "a" -prefix sub5 -datum float
3dbuc2fim -prefix float_SCHEMsubExcOrARROW_mean sub4+tlrc sub5+tlrc
3dcalc -a 'dup_REALintSCHEM_mean+tlrc[0]' -expr "a" -prefix sub6 -datum float
3dcalc -a 'dup_REALintSCHEM_mean+tlrc[1]' -expr "a" -prefix sub7 -datum float
3dbuc2fim -prefix float_REALintSCHEM_mean sub6+tlrc sub7+tlrc
3dcalc -a 'dup_REALsubLogOrSCHEM_mean+tlrc[0]' -expr "a" -prefix sub8 -datum float
3dcalc -a 'dup_REALsubLogOrSCHEM_mean+tlrc[1]' -expr "a" -prefix sub9 -datum float
3dbuc2fim -prefix float_REALsubLogOrSCHEM_mean sub8+tlrc sub9+tlrc
3dcalc -a 'dup_REALsubExcOrSCHEM_mean+tlrc[0]' -expr "a" -prefix sub10 -datum float
3dcalc -a 'dup_REALsubExcOrSCHEM_mean+tlrc[1]' -expr "a" -prefix sub11 -datum float
3dbuc2fim -prefix float_REALsubExcOrSCHEM_mean sub10+tlrc sub11+tlrc
3dcalc -a 'dup_REALintARROW_mean+tlrc[0]' -expr "a" -prefix sub12 -datum float
3dcalc -a 'dup_REALintARROW_mean+tlrc[1]' -expr "a" -prefix sub13 -datum float
3dbuc2fim -prefix float_REALintARROW_mean sub12+tlrc sub13+tlrc
3dcalc -a 'dup_REALsubLogOrARROW_mean+tlrc[0]' -expr "a" -prefix sub14 -datum float
3dcalc -a 'dup_REALsubLogOrARROW_mean+tlrc[1]' -expr "a" -prefix sub15 -datum float
3dbuc2fim -prefix float_REALsubLogOrARROW_mean sub14+tlrc sub15+tlrc
3dcalc -a 'dup_REALsubExcOrARROW_mean+tlrc[0]' -expr "a" -prefix sub16 -datum float
3dcalc -a 'dup_REALsubExcOrARROW_mean+tlrc[1]' -expr "a" -prefix sub17 -datum float
3dbuc2fim -prefix float_REALsubExcOrARROW_mean sub16+tlrc sub17+tlrc
- Record the t-value
- open AFNI
- define function
- choose an original map file
- change click down box under p value to 1 (Power-of-10 range of slider)
- adjust T slider bar so p = 0.05 (this may be different for your experiment)
- record T-value
- check the T-value for each condition because it may change
- Using AFNI to Render the 3D brain
- Define Datamode -> Plugins -> Render[new]
- Choose Underlay Dataset - use astrip+tlrc
- Choose Overlay Dataset - use one of the float files
- change Power-of-10 slider to 1
- adjust Thresh to match previously recorded T-value
- set colour bar to 4 options
- adjust so the lines are at +0.05, 0, and -0.05
- set 'see overlay' and 'remove small clusters' on
- You will now create a 3D Brain in 3 views
- Left View
- set cutouts to 1
- Choose TT Ellipsoid and set its percentage at 90%
- set Roll = 265 Pitch = 95 and Yaw = 0
- set accumulate on
- draw
- Right View
- set Roll = 100 Pitch = 100 and Yaw = 0
- draw
- Ventral View
- set cut overlay on
- set cutouts to 3
- Choose TT Ellipsoid, 100% as the first cutout
- set must do on for TT Ellipsoid
- Choose Inferior To, -15 as the second cutout
- Choose Below AL-PS, 30 as the third cutout
- set Roll = 0 Pitch = 175 and Yaw = 180
- Save the 3D image
- you should now have 3 brains rendered
- to see all of them choose a 3x1 montage (this depends on the number of brains in your image)
- Mont -> 3 across 1 down
- sharpen the images by Disp -> Sharpen
- right click Sav1.ppm
- choose Save.jpg (or which ever file type you want)
- Sav1.jpg -> 'file_name' to save
Back to U of S fMRI web page.