Freesurfer BOLD files: Difference between revisions
Line 18: | Line 18: | ||
****4D.nii | ****4D.nii | ||
After this is done, you can use the MATLAB set_TR.m function to simultaneously rename the source files and set the TR to the correct value (you will, of course, have to know what the correct TR value is!). | After this is done, you can use the MATLAB set_TR.m function to simultaneously rename the source files and set the TR to the correct value (you will, of course, have to know what the correct TR value is!). Data coming from the CTRC currently have the TR header field intialized to a value of 1.0, corresponding to a 1-second TR. SPM doesn't make use of the TR value from the header field, so this isn't a problem. However Freesurfer '''does''' use this value, so you may want to ensure that the header contains the correct TR value. | ||
set_TR.m can be found in the ubfs Scripts/Matlab folder. Ensure that this file can be found somewhere in your MATLAB path (e.g., copy it to your Documents/MATLAB folder) | If you wish to simply inspect the values in a .nii file header, you can use a command-line FSL utility called <code>fsledithd</code>: | ||
fsledithd 4D.nii | |||
This will open up the header information in the default text editor (''nano''), and you can browse the values for various fields: | |||
<nifti_image | |||
nifti_type = 'NIFTI-1+' | |||
image_offset = '352' | |||
ndim = '4' | |||
nx = '64' | |||
ny = '64' | |||
nz = '29' | |||
nt = '256' | |||
dx = '3.3125' | |||
dy = '3.3125' | |||
dz = '4.1' | |||
'''dt = '1' ''' | |||
datatype = '16' | |||
nbyper = '4' | |||
byteorder = 'LSB_FIRST' | |||
scl_slope = '1' | |||
scl_inter = '0' | |||
xyz_units = '2' | |||
'''time_units = '8' ''' | |||
descrip = 'FSL5.0' | |||
aux_file = 'none' | |||
qform_code = '1' | |||
quatern_b = '0' | |||
quatern_c = '0' | |||
quatern_d = '0' | |||
qoffset_x = '-106' | |||
qoffset_y = '-94.133' | |||
qoffset_z = '-42.618' | |||
qfac = '1' | |||
sform_code = '1 | |||
sto_xyz_matrix = '3.3125 0 0 -106 0 3.3125 0 -94.133 0 0 4.1 -42.618 0 0 0 1' | |||
num_ext = '0' | |||
/> | |||
The above output gives information about the voxel dimensions in the x,y and z axes (dx, dy, dz are 3.3125, 3.3125 and 4.1 units, respectively). Those units are interpreted as millimeters, according to the xyz_units field value (2=mm). Similary, for the time dimension field, the value is set to 1 in this header, interpreted as seconds according to the time_units field (8=seconds; 16=milliseconds). Thus, according to this file header, the functional volumes were collected 1-second apart, which is not correct (the TR for this experiment was 2.047). This can be edited using <code>fsledithd</code> by simply changing the dt field value from 1 to 2.047 (if you do so, you would then type ^O (ctrl-O) to save the changes, then ^X (ctrl-X) to exit the editor). However, a MATLAB script exists that will update the fields for multiple files belonging to the same individual. | |||
This script, <code>set_TR.m</code> can be found in the ubfs Scripts/Matlab folder. Ensure that this file can be found somewhere in your MATLAB path (e.g., copy it to your Documents/MATLAB folder) | |||
First, open a terminal and start matlab: | First, open a terminal and start matlab: | ||
Line 35: | Line 76: | ||
Now you can run the set_TR command: | Now you can run the set_TR command: | ||
set_TR(2.047, [1 2 5 6], '4D.nii') | set_TR(2.047, [1 2 5 6], '4D.nii') | ||
The above command would look for a file called '4D.nii' in directories 001, 002, 005 and 006, modify the NIfTI header file information to have a TR of 2.047 seconds, and then save the changed files to 'f.nii', leaving the originals | The above command would look for a file called '4D.nii' in directories 001, 002, 005 and 006, modify the NIfTI header file information to have a TR of 2.047 seconds, and then save the changed files to 'f.nii', leaving the originals unchanged (if your files are already called ''f.nii'', they will be overwritten). |
Revision as of 11:05, 2 November 2016
Freesurfer, like SPM, can perform functional analyses on fMRI data. These analyses generally employ the general linear model (GLM) to assess the degree to which the blood-oxygen dependent (BOLD) signal correlates with different predictors (e.g., group, experimental condition, task or even nuisance regressors such as motion).
For Freesurfer and SPM, these files will start off as NIfTI (.nii) files. Each file contains a header, which contains important information directing the software how to interpret the data, and one or more 3D matrices of raw data, representing the signal at each voxel at a particular point in time, as measured by the scanner during the experiment. The data for a single run (e.g., a 5-minute scan of an experimental task) can be stored as a series of individual 3D volume files, with each file representing a single scan of the brain like a single frame of a 5-minute movie. Alternately, multiple volumes can be concatenated together and stored in a single 4D file. Whereas SPM operates on either 3D or 4D data, Freesurfer seems to require 4D data.
The header information is important because it provides the context required to interpret the data matrix. For example, an experiment looking at hippocampal processing might use a 32 x 32 x 24 array of 1mm voxels and look at a relatively small subcortical volume. Another experiment looking at global cortical processing might use a 32 x 32 x 24 array of 3mm voxels to look at the entire brain volume. Without knowing the voxel size, it would be impossible for any piece of software to interpret the data matrix. The NIfTI header includes information about how big the voxels are, the orientation, and many other important bits of information, though not all software makes use of all the header information.
Freesurfer expects the BOLD data to be organized into individual folders for each experimental run, and that each file is called "f.nii". Moreover, Freesurfer (but not SPM) appears to make use of the TR value stored in the NIfTI header. In order to ensure that the filename requirement is met and that the TR value is correctly set, a script called set_TR.m
can be found in the ubfs Scripts/Matlab folder.
Running set_TR.m
The first requirement is that the source files for a participant be organized into numbered folders, ideally in a directory called "bold":
- participant_id
- bold
- 001
- 4D.nii
- 002
- 4D.nii
- 003
- 4D.nii
- 001
- bold
After this is done, you can use the MATLAB set_TR.m function to simultaneously rename the source files and set the TR to the correct value (you will, of course, have to know what the correct TR value is!). Data coming from the CTRC currently have the TR header field intialized to a value of 1.0, corresponding to a 1-second TR. SPM doesn't make use of the TR value from the header field, so this isn't a problem. However Freesurfer does use this value, so you may want to ensure that the header contains the correct TR value.
If you wish to simply inspect the values in a .nii file header, you can use a command-line FSL utility called fsledithd
:
fsledithd 4D.nii
This will open up the header information in the default text editor (nano), and you can browse the values for various fields:
<nifti_image nifti_type = 'NIFTI-1+' image_offset = '352' ndim = '4' nx = '64' ny = '64' nz = '29' nt = '256' dx = '3.3125' dy = '3.3125' dz = '4.1' dt = '1' datatype = '16' nbyper = '4' byteorder = 'LSB_FIRST' scl_slope = '1' scl_inter = '0' xyz_units = '2' time_units = '8' descrip = 'FSL5.0' aux_file = 'none' qform_code = '1' quatern_b = '0' quatern_c = '0' quatern_d = '0' qoffset_x = '-106' qoffset_y = '-94.133' qoffset_z = '-42.618' qfac = '1' sform_code = '1 sto_xyz_matrix = '3.3125 0 0 -106 0 3.3125 0 -94.133 0 0 4.1 -42.618 0 0 0 1' num_ext = '0' />
The above output gives information about the voxel dimensions in the x,y and z axes (dx, dy, dz are 3.3125, 3.3125 and 4.1 units, respectively). Those units are interpreted as millimeters, according to the xyz_units field value (2=mm). Similary, for the time dimension field, the value is set to 1 in this header, interpreted as seconds according to the time_units field (8=seconds; 16=milliseconds). Thus, according to this file header, the functional volumes were collected 1-second apart, which is not correct (the TR for this experiment was 2.047). This can be edited using fsledithd
by simply changing the dt field value from 1 to 2.047 (if you do so, you would then type ^O (ctrl-O) to save the changes, then ^X (ctrl-X) to exit the editor). However, a MATLAB script exists that will update the fields for multiple files belonging to the same individual.
This script, set_TR.m
can be found in the ubfs Scripts/Matlab folder. Ensure that this file can be found somewhere in your MATLAB path (e.g., copy it to your Documents/MATLAB folder)
First, open a terminal and start matlab:
matlab &
Your startup.m
script should run automatically, setting your path to include the most commonly used toolboxes in the process. Nonetheless, you should ensure that set_TR and other needed functions are indeed in your path:
help load_untouch_nii help set_TR
If either of these commands return a command not found type of message, ask for help in getting them permanently in your path. It could be simple matter of running a startup script (e.g., startup_spm8
).
Assuming that these files are in your path, the next step is to use MATLAB to navigate to the directory containing your participant data. For example, working with a data set on ubfs:
cd ~/ubfs/cpmcnorg/openfmri/test/1001
Now you are in the directory for participant 1001. There should be a bold subdirectory with one or more numbered directories below it, as described above. Move into the bold directory:
cd bold
Now you can run the set_TR command:
set_TR(2.047, [1 2 5 6], '4D.nii')
The above command would look for a file called '4D.nii' in directories 001, 002, 005 and 006, modify the NIfTI header file information to have a TR of 2.047 seconds, and then save the changed files to 'f.nii', leaving the originals unchanged (if your files are already called f.nii, they will be overwritten).