It is probably incorrect to label this as a timeseries extraction tool, because it is currently configured to extract a list of activation values for each subject in a group analysis, as opposed to a series of mean activations for a single subject over time. The name comes from the fact that the SPM VOI tool can be used to do either. The broad goal of this script is to create a consistent standard for extracting group BOLD values that might e used with another application that deals with genetic, behavioral, and clinical data.
This script can be used to automatically extract a list of BOLD activation values from a group map, and print those values with a list of subjects from the analysis to a user specified output folder. This would be equivalent to loading a group SPM.mat into the results editor, selecting a contrast, threshold type, threshold, and mask, and then clicking “eigenvariate” to create a VOI (volume of interest) based on the same mask. Running this manually, a VOI_name.mat would be created in the group analysis directory, and the list of extracted values spit out into the MATLAB window.
The script is currently set up to extract based on a mask, meaning that we first threshold the SPM.mat with the mask, and THEN pull the mean across the mask. If you want to threshold with a wholebrain analysis and then extract from the mean within a specified mask, please use SPM Timeseries Wholebrain.
It should be noted that the equivalent might be done for a single subject SPM.mat, except we would be extracting a timeseries (mean activation over time). The script is currently set up to check that the selected SPM.mat is for a group, and NOT a single subject analysis. It could be adapted to support single subject timeseries, if needed.
Broadly, the script collects all user input, including an optional id lookup table that can match any sort of study ID with the exam ID (associated with the data). These inputs can come either from command line or, if the script is called with zero input arguments, selected via a GUI. After all input is selected and checked for accuracy, the script hijacks the function wfu_spm_getSPM from Pickatlas to threshold and mask the input data, and then feeds this thresholded and masked SPM.mat output into the spm_jobman, with a job configured to use the VOI tool to extract based on a this thresholded SPM and a mask. For empty regions it catches these as errors, and records the job ID to print to a error_log.txt file. It then, for each successful VOI extraction, goes to the user specified output folder, and prints a .csv file with the list of subject id’s from the lookup file, the exam ids embedded with the data, and the values extracted for the particular mask.
For detailed comments about functionality, please refer to the documentation in the script itself. If anything is unclear, please don’t hesitate to ask! SPM Timeseries
You need MATLAB installed, with SPM8 and Pickatlas 3.0 installed on the computer and added to the path. The script will check for your spm installation, and the file “wfu_spm_getSPM()” to check for Pickatlas. Note that I did not test this for other versions of SPM or Pickatlas.
You can run it either with zero, seven, or eight arguments, as follows:
% Will prompt user for all input, allows one or more runs, and the selection of a common output folder
dns_timeseries
% Will do one extraction with no lookup table
dns_timeseries(spmmat,threshtype,thresh,extent,output,mask,contrast)
% Will do one extraction with a lookup table
dns_timeseries(spmmat,threshtype,thresh,extent,output,mask,contrast,lookup)
The input parameters are as follows:
You could set up a simple script to run many iterations of dns_timeseries, perhaps for multiple masks/contrasts/tasks at a data freeze. An example is provided below.
% Setup global (nonchanging) variables for each run:
threshtype = 'FWE';
thresh = '.05';
extent = 0;
contrast = 1;
lookup = 'L:\Path\to\TIMESERIES\lookup.xls';
output = 'L:\Path\to\output\TIMESSERIES\masked\XXXs';
%% TASK1 EXTRACTIONS
spmmat = 'L:\Path\to\task1\group\map\SPM.mat';
% Contrast > One Mask1
mask = 'L:\Path\to\Mask1.nii';
dns_timeseries(spmmat,threshtype,thresh,extent,output,mask,contrast,lookup);
% Contrast > Two Mask2
contrast = 2;
mask = 'L:\Path\to\Mask2.img';
dns_timeseries(spmmat,threshtype,thresh,extent,output,mask,contrast,lookup);
%% TASK2 EXTRACTIONS
spmmat = 'L:\Path\to\task2\group\map\SPM.mat';
% Contrast > One Mask3
mask = 'L:\Path\to\Mask3.img';
dns_timeseries(spmmat,threshtype,thresh,extent,output,mask,1,lookup);
% etc...