Instructions for Analyzing a fMRI Data Set using Logical AND, Logical OR, and Exclusive OR

Preparing the Data for Analyzing

  1. Write all AFNI anatomical and functional datasets to Talairach orientation (+tlrc)

  2. Create a directory structure for data within the projects directory
    [fMRI@wilder]$ mkdir analysis
    [fMRI@wilder]$ mkdir ./analysis/baseline ./analysis/calcs
    [fMRI@wilder]$ mkdir ./analysis/baseline/means ./analysis/calcs/means
  3. Rename the Talairached 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

  1. Clustering
    #!/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
  2. Blurring

Creating Subtraction and Intersection Maps

  1. Zero out the voxels with negative intensities using 3dmerge
    #!/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
  2. Calculating the difference maps for each subject from the noneg data.
    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
    1. 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.

    2. 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.

    3. 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.

    4. 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.

  3. As with the Baseline maps now cluster and blur the data
    #!/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
  4. Run ANOVA on the dataset (also in calcs directory)

Creating 3D Brains

  1. Download the 3D anatomical brain (astrip+tlrc.BRIK and astrip+tlrc.HEAD)
  2. Make a duplicate of your dataset's header file (*.HEAD)
    #!/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
  3. Open AFNI
  4. Load astrip as the underlay
  5. Load dup_${stim}${mtype}${task}_mean as the overlay
  6. Write out the dataset
  7. Many datasets after the ANOVA will have two-sub-bricks with different data types for each sub-brick.
    #!/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

  8. Record the t-value
  9. Using AFNI to Render the 3D brain
  10. 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
  11. Save the 3D image
Back to U of S fMRI web page.