Afni into Analyze
Converting an AFNI brik to Analyze format using the afni 3dcalc command to divide the brik into sub-bricks.


1. On unix create the following script:

#-------------------cut here ---------------------
#afni2analyze
#where a is the number of runs and b,c are the number of reps and the scans.txt is a text file the contains the prefix for
the spm file name
@ a = 1
while ($a < 7)
@ b = 0
@ c = 1
set scans = `cat scans.txt`
while ($b < 156)
3dcalc -a$b run$a+orig -expr "a+300" -prefix run$a.$b.
mv run$a.$b.+orig.BRIK run$a$scans[$c].img
rm run$a.$b.+orig.HEAD
@ b++
@ c++
end
@ a ++
end
# --------------------- cut here --------------------

2. Change permission for the afni2analyze file to make executable
chmod 755 afni2analyze

3. create the scans.txt, which is a text file that has the prefix for the .img spm file names each in a separate line (such as time001, time002 etc)

4. Copy the afni brik along with the afni header to a separate subdirectory and run the script, which will create a volume for each time series

5. along with the image .img file, you need a hdr (spm header file), to create the header file you can use the spm function spm_hwrite using the following M-file, the afni command:

3dinfo -v can provide you with some of the needed info.

%----------------------cut here -----------------------
%setheaderparameter.m
numofruns = 7;
numoftimeseries = 157;
DIM(1)=64; % Matrix size
DIM(2)=64; % Matrix size
DIM(3)=20; % # of slices
VOX(1)=3.438; %voxel size in the x direction
VOX(2)=3.438; %voxel size in the y direction
VOX(3)=7.0; %voxel size in the z direction
SCALE =8; % Scale factor
TYPE =4; %returns the matlab int16 data type for short int.
OFFSET = 0; % offset
ORIGIN = [32; 32; 10]; % ORIGIN can be edited in this is example it is the middle x, y, z point.
DESCRIB = ['GE Echo Planar'];
for runcount = 1:numofruns
for count = 1:numoftimeseries
prefix = ['run' runcount 'time' ZeroPad('',3,numoftimeseries)];
spm_hwrite(prefix,DIM,VOX,SCALE,TYPE,OFFSET,ORIGIN,DESCRIB);
end;
end;
%----------------------cut here -----------------------

6. Also the ZeroPad.m file is needed for adding leading zeros to the header file if needed.

Last modified August 4, 2008
Produced by the Center for Functional MRI.
Main address: University of California, San Diego, 9500 Gilman Dr., Mail Code 0677, La Jolla, CA 92093
Phone: (858)-822-0513 FAX: (858)-822-0605 Web: http://fmri.ucsd.edu
Send questions, comments, and suggestions to: fmri-support@ucsd.edu
Copyright 2008 CFMRI. All rights reserved.