• Blog
  • About
  • Publications
  • Videos
  • Workshops
  • CV
  • Contact Me
  • Hall of Fame
Menu

Andy's Brain Blog

Street Address
City, State, Zip
Phone Number
fMRI, Neuroimaging, and More

fmri, neuroimaging, and more

Andy's Brain Blog

  • Blog
  • About
  • Publications
  • Videos
  • Workshops
  • CV
  • Contact Me
  • Hall of Fame

fMRI Lab: ROI Analysis with AFNI

April 16, 2017 Andrew Jahn

I'm updating some of the old videos I had on ROI analysis, this time with AFNI. I'm trying a new format, in which I have a separate video introducing the topic (in this case, ROI analysis), and then a "lab" video or two showing how to do it in different software packages. I'm trying to have the intro videos be on the shorter side, around 5 minutes, while the lab videos are a little longer and more in-depth, around the 10-minute mark. I hope the figures and animations make this technique more understandable.

Here was the code I used in the tutorial:

1. Create a 5mm spherical mask around the coordinates 0, 30, 30: 

echo "0 30 30" | 3dUndump -prefix ACC -srad 5 -orient LPI -master sub001/stats.sub001+tlrc. -xyz -

Explanation: This uses something in Unix called a pipe (the vertical slash, or "|"), which allows the code on the right side of the pipe to use the output on the left side of the pipe. The -srad option specifies the radius of the sphere, while the -orient option specifies which coordinates are positive and which coordinates are negative. In this example, LPI stands for Left-to-Right/Posterior-to-Anterior/Inferior-to-Superior. In other words, the x-coordinates are negative to the left and positive to the right of the x-axis midline; the y-coordinates are negative in back and positive in front of the y-axis midline; and the z-coordinates are negative below and positive above the z-axis midline. The code "-xyz -" means to feed into the -xyz option the output of echo "0 30 30", which will reduce to 0 30 30. The result is a 5-mm spherical mask of voxels filled in with the value 1, while all voxels outside the mask are set to 0.

2. Resample the mask to the statistical dataset you will extract from:

3dresample -master sub001/stats.sub001+tlrc -inset LeftPostCentral+tlrc -prefix LeftPostCentral_rs

Explanation: In this example, the dataset I used to create the mask was a template with 1x1x1mm resolution; my statistical datasets had a final voxel resolution of 2.5x2.5x2.5mm. In order to use the mask with the dataset, they need to have the same resolution and have the same boundaries in the x-, y-, and z-directions. I didn't want to interpolate the statistical datasets, so I chose to use a sample statistical dataset as the master, and to resample the mask to conform to the subjects' datasets. The whole issue of resampling is something I plan to cover more in-depth in the future.

3. Combine two masks:

3dcalc -a LeftPostCentral+tlrc -b RightPostCentral+tlrc -expr ‘(a+b)’ -prefix LeftRightPostCentral

Explanation: 3dcalc can be used for simple addition, subtraction, multiplication, and other basic arithmetical operations on functional data - which are just huge 3D matrices of numbers. Assign a dataset to each variable (in this case, "a" and "b"), and then sum them together to get a combined mask. In this example, the LeftPostCentral mask had values of 1's in the mask, and the RightPostCentral mask had values of 2's. If there were any overlap between the masks, those voxels would have a value of 3.

4. Extract the beta weights for each regressor for each subject and combine them into separate datasets:

foreach subj (`cat subjList.txt`)

3dbucket -aglueto Left+tlrc {$subj}/stats.{$subj}+tlrc’[31]’

3dbucket -aglueto Right+tlrc {$subj}/stats.{$subj}+tlrc’[64]’

end

Explanation: This requires a few Unix tricks, but once you master them it will make scripting much easier. In this example, each subject's directory has the same structure: subjectName/stats.subjectName+tlrc. I had 12 subjects, with the names sub001, sub002...sub012. I put those names into a file subjList.txt, and then fed that into a foreach loop by typing `cat subjList.txt`, which expands all the directory names in the list and iteratively assigns them to the variable "subj". I use this, along with the knowledge that my beta weights for Left button presses are in sub-brik 31 and right button presses in sub-brik 64, to create a separate dataset for each regressor which contains each subject's beta weight. The -aglueto option for 3dbucket appends a new brik to the current dataset as the loop iterates over each subject. When using the -aglueto command, don't forget to include the space suffix (e.g., "tlrc"), or else it will crash.

5. Create a dataset with each sub-brik containing a contrast for each subject:

3dcalc -a Left+tlrc. -b Right+tlrc. -expr '(a-b)' -prefix Left-Right

Explanation: Similar to the 3dcalc operation above, this will simply take the difference between each beta weight for each subject, and put the resulting contrast into the dataset Left-Right.

6. Extract data with 3dmaskave and 3dROIstats:

3dmaskave -quiet -mask LeftPostCentral_rs+tlrc Left-Right+tlrc; 3dmaskave -quiet -mask RightPostCentral_rs+tlrc Left-Right+tlrc

OR

3dROIstats -quiet -mask LeftRightPC_rs+tlrc. Left-Right+tlrc.

Explanation: Both commands extract data averaged over the entire mask, but 3dROIstats can do it from multiple masks simultaneously. The -quiet command prints only the numerical results.

 

What do you think about the new format? Are the figures helpful? Does the background music drive you nuts? If you have an opinion, I'd love to hear about it in the comments section below!

← ABB Podcast #3: Ken Pugh (President, Haskins Laboratories)Comments Section Upgrade →
Archive
  • September 2024
  • June 2024
  • March 2024
  • January 2024
  • June 2023
  • May 2023
  • April 2023
  • February 2022
  • January 2022
  • January 2021
  • December 2020
  • April 2020
  • December 2018
  • April 2018
  • January 2018
  • December 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • January 2017
  • November 2016
  • August 2016
  • July 2016
  • February 2016
  • January 2016
  • September 2015
  • August 2015
  • July 2015
  • May 2015
  • April 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • April 2012
  • March 2012

What's on Andy's Brain this month?

Connect with Andy!

Powered by Squarespace