|
Size: 5751
Comment:
|
Size: 6619
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 12: | Line 12: |
| == 1. Converting Fiff-files to SPM images == This script has not been tested extensively, but it is based on the scripts at http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM. |
== 1. Converting Fiff-files to SPM images (for between-condition contrasts) == This script is based http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM. It converts magnetometer and gradiometer data to SPM image files, and computes RMS values for gradiometers (2 at each location) if requested. This is appropriate for statistical contrasts between conditions, but not for comparisons of one condition against zero. If that's what you're after, look under point 2 below. |
| Line 37: | Line 37: |
| % CONVERT FROM FIFF TO SPM FORMAT... | % CONVERT FROM FIFF TO SPM FORMAT (for between-condition contrasts)... |
| Line 91: | Line 91: |
| == 2. Sensor-level group analysis in SPM 5 == | == 2. Converting Fiff-files to SPM images (for single-condition contrasts against zero) == If you are testing a single condition against zero, computing the RMS for the two gradiometers at each sensor location increases the likelihood of false positives. Even the baseline noise will have RMS values above zero. One way of minimising this problem is computing the signal power for each gradiometer pair, and subtracting the mean baseline value afterwards. Unfortunately, this requires a different script at the moment: {{{ }}} == 3. Sensor-level group analysis in SPM 5 == |
Statistics in sensor space
A standardised way or running sensor-level statistics on your MEG data is implemented in SPM5:
http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSpm
But nothing prevents you from finding your own way...
The following two scripts will help you
- convert fiff-files to SPM images (if necessary)
- run group statistics on MEG data in signal space in SPM 5
1. Converting Fiff-files to SPM images (for between-condition contrasts)
This script is based http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM. It converts magnetometer and gradiometer data to SPM image files, and computes RMS values for gradiometers (2 at each location) if requested. This is appropriate for statistical contrasts between conditions, but not for comparisons of one condition against zero. If that's what you're after, look under point 2 below.
% Modified from http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSPM
% takes a list of Fiff-files (cell array "fifflist{}") and converts MEG data to SPM image files,
% which can then be subjected to 2nd-level statistics, for example
% "rootdir" can contain the directory path common to all files
% the script will produce subdirectories with img-files in the directories of the input fiff-files
% so far only tested on one data set
% OH, March 2009
% you can specify a list of fiff-files here, to be converted into SPM format
fifflist = {'/fullpath/file4subj1.fif', ...
'/fullpath/file4subj2.fif', ...
'/fullpath/file4subj3.fif'};
nr_fiffs = length(fifflist);
% root directory common to all input fiff-files (not required if full pathnames specified in fifflist{})
root_dir = '';
% GET GOING...
clear S;
for ff = 1:nr_fiffs, % for all Fiff-files...
% CONVERT FROM FIFF TO SPM FORMAT (for between-condition contrasts)...
S.Fchannels = fullfile(spm('dir'),'EEGtemplates','FIF306_setup.mat');
S.veogchan = [62]; % Channel 62 is (bipolar) VEOG, MAY NEED EDITING
S.heogchan = [61]; % Channel 61 is (bipolar) HEOG, MAY NEED EDITING
S.veog_unipolar = 0; % MAY NEED EDITING
S.heog_unipolar = 0; % MAY NEED EDITING
S.conds = 1; % conditions in fiff-file, MAY NEED EDITING
S.grms = 1; % so that the splitting outputs mags, grads and grad RMS (grms)
[fiffpath,fiffname,fiffext,fiffversn] = fileparts(fifflist{ff});
S.Fdata = fullfile(root_dir, fifflist{ff}); % Input Fiff-file before splitting
fileSPMout = fullfile(root_dir, fiffpath, [fiffname '_SPM.mat']); % Output SPM file (if not specified, will be 'myexp.mat')
S.Pout = fileSPMout; % output for conversion from Fiff to SPM format (before splitting)
D0 = spm_eeg_rdata_FIF(S); % convert fiff- to SPM-format
% SPLIT DATA INTO MAGS/GRADS/EEG...
S.D = fileSPMout; % structure for splitting
D1 = spm_eeg_splitFIF(S); % split SPM files
% WRITE TO IMAGE VOLUMES:
% Select options (see help for spm_eeg_convertmat2ana3D):
clear S
S.interpolate_bad = 0;
S.n = 32;
S.pixsize = 3;
% Select trial types:
S.trialtypes = [1];
img_outnames = '';
% Mags:
S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-mags.mat']);
tmpname = spm_eeg_convertmat2ana3D(S);
img_outnames(1,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-mags'], 'trialtype1', 'average.img');
% Grad magnitude:
S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-grds.mat']);
tmpname = spm_eeg_convertmat2ana3D(S);
img_outnames(2,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-grds'], 'trialtype1', 'average.img');
% GradRMS magnitude:
S.Fname = fullfile(root_dir, fiffpath, [fiffname '_SPM-grms.mat']);
tmpname = spm_eeg_convertmat2ana3D(S);
img_outnames(3,:) = fullfile(root_dir, fiffpath, [fiffname '_SPM-grms'], 'trialtype1', 'average.img');
% SMOOTH IMAGES
P = img_outnames;
SmoothKernel = [5 5 10]; % % Smoothness in x (mm), y (mm) and z (ms), MAY NEED EDITING
for n=1:size(P,1);
[pth,nam,ext] = fileparts(P(n,:));
Pout{n} = fullfile(pth,['s' nam ext]);
spm_smooth(spm_vol(P(n,:)),Pout{n},SmoothKernel);
Pin = strvcat(P(n,:),Pout{n});
spm_imcalc_ui(Pin,Pout{n},'((i1+eps).*i2)./(i1+eps)',{[],[],'float32',0});
end
%The final imcalc step above is just to reinsert NaN's for voxels outside space-time volume into which data were smoothed
end; %..ff
2. Converting Fiff-files to SPM images (for single-condition contrasts against zero)
If you are testing a single condition against zero, computing the RMS for the two gradiometers at each sensor location increases the likelihood of false positives. Even the baseline noise will have RMS values above zero. One way of minimising this problem is computing the signal power for each gradiometer pair, and subtracting the mean baseline value afterwards. Unfortunately, this requires a different script at the moment:
3. Sensor-level group analysis in SPM 5
% based on http://imaging.mrc-cbu.cam.ac.uk/meg/SensorSpm
% to be run in SPM 5 EEG
% runs group statistics on files in "imgfiles"
% output written into directory "outdir"
% OH, March 2009
addpath /imaging/local/meg_misc; % for meg_batch_anova
% output directory
outdir = '/youroutputwillgohere/;
% Here: One group of subjects, 2 conditions
% You can also specify more groups of subjects, or test one condition against zero:
% More groups of subjects: Vary first cell index of imgfiles (imgfiles{1}{cc}...imgfiles{2}{cc}...)
% One-sample t-test against zero mean: just specify one file per line,
% e.g. imgfiles{1}{cc} = ['/thispath/subj1_con1.img']; cc=cc+1; etc.
if exist('imgfiles')~=1,
cc = 1;
imgfiles{1}{cc} = ['/thispath/subj1_con1.img'; 'thispath/subj1_con2.img']; cc=cc+1;
imgfiles{1}{cc} = ['/thispath/subj2_con1.img'; 'thispath/subj2_con2.img']; cc=cc+1;
imgfiles{1}{cc} = ['/thispath/subj3_con1.img'; 'thispath/subj3_con2.img'];
end;
nr_subjects = cc;
% root directory common to all input fiff-files (not required if full pathnames specified in imgfiles{})
root_dir = '';
% Attach root directory
clear Panova;
for i=1:nr_subjects, % create full image file names, including root directory etc.
[m,n] = size(imgfiles{1}{i});
for j=1:m,
Panova{1}{i}(j,:) = fullfile( root_dir, imgfiles{1}{i}(j,:) );
end; %..j
end; %..i
meg_batch_anova(Panova,imgset(ss).outdir); % Run SPM stats