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!