11. fMRI analysis - fahsuanlin/labmanual GitHub Wiki
These are procedures modeling the fMRI time series using General Linear Model (GLM). The scripts were tested at /space/maki7/1/users/fhlin/seeg/s026/fmri_analysis on September 7 2019.
NOTE: At Sunnybrook, the data and scripts are at /space_lin2/fhlin/seeg/s026/fmri_data and /space_lin2/fhlin/seeg/s026/fmri_analysis, respectively.
0. Background
This data is fMRI for an event-related experiment, where auditory and visual stimuli were presented briefly to the participant. So we expected to see auditory and visual hemodynamic responses. In this example, subject s026 had two runs of fMRI measurements at /space_lin2/fhlin/seeg/s026/fmri_data/unpack/bold/030 and /space_lin2/fhlin/seeg/s026/fmri_data/unpack/bold/032. The pre-processed data (after motion correction, slice-timing correction, and spatial smoothing) were sfmcprstc.nii in two folders. We also performed the pre-processing to transform these 4D (x,y,z, and time) data onto cortical surface as STC files. They are s026_2_fsaverage_sfmcprstc-lh.stc and s026_2_fsaverage_sfmcprstc-rh.stc in two folders.
0.1 Map fMRI time series from EPI volumnes on cortical surfaces
[This script] map the fMRI volumes (from EPI) on the cortical surfaces. Results are STC files for both left and right hemispheres (*lh.stc and *rh.stc). A transformation matrix file (register.dat) is needed.
0.2 Transform fMRI time series from individual's native space to MNI305 template
[This script] transform individual's fMRI volumes to the MNI305 atlas space. The output is a NII file.
The underlay image for morphed EPI data can be accessed at the mni305.cor.subfov2.mgz file in FreeSurfer. At MAC, it is /Applications/freesurfer/average/mni305.cor.subfov2.mgz.
1. Get confound information
Collect time series confound from motion correction and signals at non-gray matter areas.
1.1. Get confound information from motion correction
[This script file] collects the motion correction translation and rotation information in mc-sess as temporal confounds.
1.2. Get confound information from non-gray matter time series
[This script file] collects the time series at ventricles and white matter as temporal confounds. This is done by first creating a mask of ventricles and white matter by morphing the automatic segmentation/parcellation from the template subject 'fsaverage' to the subject of interest. Then time series based on this mask is used to get time series at ventricles and white matter.
2. Prepare the stimulus onset
[This script file] creates 'paradigm files', which are text files with each one indicating a stimulus onset and its numeric code. This is for the event-related fMRI design.
The script loads a Matlab data file 'SOA_s026.mat', which has the following variables. Each one of them codes the stimulus onset time (in second). Specifically, 'R1_' variabiles denote the stimulus onsets for run 1 and 'R2_` variabiles denote the stimulus onsets for run 2.
>> whos
Name Size Bytes Class Attributes
R1_Onset_A 1x43 344 double
R1_Onset_AM 1x4 32 double
R1_Onset_V 1x43 344 double
R1_Onset_VA 1x44 352 double
R1_Onset_VAM 1x5 40 double
R1_Onset_VM 1x5 40 double
R1_Onset_err 1x5 40 double
R1_Onset_missing 1x1 8 double
R2_Onset_A 1x45 360 double
R2_Onset_AM 1x4 32 double
R2_Onset_V 1x45 360 double
R2_Onset_VA 1x45 360 double
R2_Onset_VAM 1x5 40 double
R2_Onset_VM 1x5 40 double
R2_Onset_err 1x1 8 double
R2_Onset_missing 1x1 8 double
The script will convert the stimulus onsets of these two runs into two files: fmri_soa_01.para, and fmri_soa_02.para.
Each variable in one run is numerically coded by one number. For example, run 1 has six types of stimulus with onset times in soa_var{1} and their numerical code in soa_code{1}.
3. General linear modeling of the fMRI time series
[This script file] implements the General Linear Modeling of fMRI time series using data painted over a cortical surface (in STC format). The required stimulus onsets is here.
[This script file] implements the General Linear Modeling of fMRI time series using volumetric data (in NII format).
Both scripts can be changed to model the fMRI signals using a canonical hemodynamic response function or finite impulse response basis function. The fMRI time series residual can be modeled as an auto-regressive (AR) model.
4. Render results over the brain
This example shows how to paint values in a overlay volume file in both brain volume and surfaces of a subject. All data are shown in the native subject's anatomical space.
[A script file] can be downloaded from Google drive.
Here, we took a overlay file (f.mgz) and painted the first time point of it over the brain volume and surface. A registration file (register.dat) is needed to co-register between the overlay and anatomical underlay. Since this overlay is just an EPI volume, its values were rather homogeneous across the whole brain.
Note You may use the FreeSurfer command mri_convert to convert the overlay file into the .mgz format.
The essential part of the script is to prepare the overlay volume and surfaces matched to the anatomical volume and surfaces.
%%% volume overlay
f=MRIread(file_overlay_vol);
r=etc_read_xfm('file_xfm',file_overlay_register);
%prepare overlay volume matched to the underlay volume
vol = etc_MRIvol2vol(f,mri,r,'frames',[1]); %only the first volume
%prepare overlay surface
vol2surf = etc_MRIvol2surf(f,surf,r,'subject',subject,'frames',[1],'hemi',hemi);
etc_render_fsbrain('surf',surf,'hemi',hemi,'subject',subject,'vol',mri,'talxfm',(talxfm),'overlay_vol',vol,'overlay_value',vol2surf,'overlay_vertex',[1:size(vol2surf,1)]-1,'overlay_threshold',overlay_threshold);
https://github.com/fahsuanlin/labmanual/blob/master/images/etc_Render_fsbrain_overlay_vol_surf0.png https://github.com/fahsuanlin/labmanual/blob/master/images/etc_Render_fsbrain_overlay_vol_surf1.png
Overlaying data with multiple time points can be done by preparing volumes and surfaces.
In this example, if you calculated the hemodynamic responses for three hypotheses based on the data painted over the cortical surfaces, you will obtain the following STC files:
fmri_surf_soa_glm_h0?_beta-?h.stc
fmri_surf_soa_glm_h0?_tstat-?h.stc
These are the estimated "effect" (beta) and "significance" (tstat) for hypothesis h01, h02, h03 at left (-lh.stc) and right (-rh.stc) hemispheres, respectively. To visualize the results, you can try:
[stc,v]=inverse_read_stc('fmri_surf_soa_glm_h01_tstat-lh.stc');
etc_render_fsbrain('hemi','lh','overlay_stc',stc,'overlay_vertex',v,'overlay_threshold',[2 3]);
This will show strong auditory cortex activity (t-statistics threshold at (rather low) t=2.0).
https://github.com/fahsuanlin/labmanual/blob/master/images/etc_Render_fsbrain_overlay_h01_tstat.png