AnalyzingData/MNE_Labels - Meg Wiki

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Flind the wroneg tetters tin eaech wrord

location: AnalyzingData / MNE_Labels

Processing ROIs

ROIs in MNE are defined as "label" files. Freesurfer already creates a parcellation of the cortical surface in various regions of interest (see subdirectory "label" in your subjects' MRI directory). These can be converted to label files for MNE. You can then use mne_make_movie in order to extract amplitudes for these ROIs, e.g. for statistical analysis. You can also define your own ROIs. You can morph ROIs between different brains (e.g. from average brain to individual brains) using mne_morph_labels. The resulting amp-files can be processed in Matlab.

The parameters below are reasonable choices for standard analyses. However, these Wiki pages are not supposed to substitute the MNE manual, reading papers, and discussions with more experienced researchers.

Using Pre-defined Labels

If you've morphed all your individual STC-files to an average brain (called "average" in the example), you can create MNE-labels from these:

mne_annot2labels --subject average --parc aparc

This will result in files such as "fusiform-lh.label" in the MRI label subdirectory. These are text files that you can read into a text editor etc.

Then you can extract ROI information using mne_make_movie. The following script does it for multiple subjects, conditions, labels and both hemispheres. The resulting *.amp-files are text files that you can read into Excel, Matlab etc.


## Your variables:

MRIpath='/myMRIdirectory/'    # where your MRI subdirectories are

STCpath='/mySTCpath/'         # where your STC files are

outpath='/myoutputdirectory'  # where the results should go

#condition names as used in file names
conds=('cond1' 'cond2' 'cond3')

# subjects names used for MRI data
        'Subject1' \
        'Subject2' \
        'Subject3' \

# MEG IDs (your directory structure may differ)
        'meg10_0001' \
        'meg10_0002' \
        'meg10_0003' \

# MEG subdirectories (your directory structure may differ)      
         '100001' \
         '100002' \
         '100003' \

# labels to be processed        
        'lh' \
        'rh' \

# Processing:

lastsubj=`expr $nsubjects - 1`

lastcond=`expr $nconds - 1`

lastlabel=`expr $nlabels - 1`

lasthemisphere=`expr $nhemispheres - 1`

# Processing:

for ss in `seq 0 ${lastsubj}`
  echo " "
  echo " Computing movies  for SUBJECT  ${subjects[m]}"
  echo " "
        for cc in `seq 0 ${lastcond}`
          echo " "
          echo " Computing movies for condition  ${conds[c]}"
          echo " "
                        for bb in `seq 0 ${lastlabel}`
                          echo " "
                          echo " Computing movies  for label  ${labels[b]}"
                          echo " "                      
                                for hh in `seq 0 ${lasthemisphere}`
                                echo " "
                                echo " Computing movies  for hemisphere  ${hemispheres[h]}"
                                echo " "        
                                        mne_make_movie \
                                          --subject ${subjects[ss]} \
                                          --stcin ${STCpath}/${subj_pre[ss]}_0${subjects[ss]}_${conds[cc]}-${hemispheres[hh]}.stc \
                                          --label ${MRIpath}/average/label/${labels[bb]}-${hemispheres[hh]}.label \
                                          --labelverts \
                                          --labeltag -${subjects[ss]}_${conds[cc]}.amp \
                                          --labeloutdir ${outpath}

                                done # hemispheres
                        done # labels                   
        done # conditions

done # subjects

Create your own labels

If you create your own labels, the path name for the label files (--label) should be changed accordingly.

1) Display a cortical surface (and e.g. an STC file) in mne_analyze.

2) Define the borders of your ROI by defining points using your right mouse button.

3) Hold the "CTRL" key and click into the centre of your points with your right mouse button.

4) Save the label.

5) Use mne_make_movie to extract information for this label.

Note that you can use mne_morph_labels to morph labels between subjects, for example to the average brain.

This video shows how to load an existing STC file and use it to define your own ROI (you may have to download the movie and play it outside your browser).

Processing Amp-files in Matlab

The following Matlab script reads amp-files, and averages across vertices and within latency ranges. The output will be written to an Excel file or separate text files (note: Excel files can only be created under Windows, not Linux). As usual, there is not copyright but also no guarantee...

% Reads output of MNE label (ROI) analysis (i.e. amp-files)
% Computes averages across all vertices within amp-file, and for pre-defined latency ranges
% Output in Excel file (one worksheet per latency range) and text files (one file per latency range)
% output format: conditions fastest within labels
% OH, Dec 2010

% Latency ranges 
latranges(1,:) = [150 200];    % ms
latranges(2,:) = [400 500];    % ms
nr_rgs = size(latranges, 1);

baseline = [-100 0];  % baseline correction (leave empty [] if not needed)

AMPpath = '/PathOfAmpFiles/';  % input path for amp-files
resultpath = '/PathOfResults/'; % output path

resultfilestem = 'ResultFileStem';  % stem for output txt/xls-files

% Names of different condition names (if exist)
conds={'cond1', 'cond2'};
nr_conds = length(conds);

        's1', ... 
        's2', ... 
        's3', ... 
nr_sbs = length(subjects);

% Namels of label files (specify -lh and -rh separately)
labels = {
    'Angular-lh', ...
    'Angular-lh', ...
    'AntMidTemp-lh', ...
    'PostMidTemp-lh', ...
nr_lbls = length(labels);

%% Reading data from amp-files; computing mean across vertices and for separate latency ranges
clear alldata;
for rr = 1:nr_lbls, % for all labels
    fprintf(1, '%s\n', labels{rr});
    for ss = 1:nr_sbs,  % for all subjects
        fprintf(1, '%s\n', subjects{ss});
        for cc = 1:nr_conds,    % for all conditions
            fprintf(1, '%s\n', conds{cc});                        
            amp_in_file = fullfile( AMPpath, [labels{rr} '-' subjects{ss} '_' conds{cc} '.amp'] );      
            fprintf(1, 'File: %s\n', amp_in_file);

            % read current amp-file
            datain = dlmread( amp_in_file );
            lats = datain(1,2:end-1);   % latencies (ms in amp-file)   

            data = datain(2:end,2:end-1); % actual data for all vertices in file            

            % only if baseline interval specified: baseline correction
            if ~isempty(baseline),   
                [tmp, b1] = min ( abs( lats-baseline(1) ) );
                [tmp, b2] = min ( abs( lats-baseline(2) ) );
                meanbase = mean( data(:,b1:b2) , 2);
                [m,n] = size(data);
                repmeanbase = repmat(meanbase, 1, n);
                data = data - repmeanbase;

            meandata = mean( data );    % mean across vertices
            for tt = 1:nr_rgs,  % averages for time ranges
                [tmp, t1] = min ( abs( lats-latranges(tt,1) ) );
                [tmp, t2] = min ( abs( lats-latranges(tt,2) ) );
                alldata(tt,cc,rr,ss) = mean( meandata(t1:t2) ); % alldata contains all data values (lat ranges, conditions, labels, subjects)
            end; % tt

        end; % cc
    end;    % ss
end; % rr

%% Output result to Excel-file and text-files

% File name of Excel-file that will contain the output
xls_out = fullfile( resultpath, [resultfilestem '.xls']); % Excel file, one spread sheet per latency range

for tt = 1:nr_rgs,  % for all latency ranges

        file_out = fullfile( resultpath, [resultfilestem '_' num2str(latranges(tt,1)) '_' num2str(latranges(tt,2)) '.txt']);        
        % reorganise data matrix for output
        for rr = 1:nr_lbls,
            for cc = 1:nr_conds,            
                index = (rr-1)*nr_conds + cc;
                outmat(:,index) = squeeze( alldata(tt,cc,rr,:) );                
                outlabel{index} = [labels{rr} '_' conds{cc}];   % text label for first line in output file (one label per column)
            end; % cc
        end; % rr
        % Write to different worksheets in Excel-file (one worksheet per latency range)
        xlswrite(xls_out, outmat, [num2str(latranges(tt,1)) '_' num2str(latranges(tt,2))]);
        % Write to text files (one file per latency range)
        fprintf(1, 'Output: %s\n', file_out);
        fid = fopen( file_out, 'w' );
        for i = 1:index,
            fprintf( fid, '%s ', outlabel{i} ); % labels in first line
        fprintf(fid, '\n');
        for i = 1:nr_sbs,
            for j = 1:index,
                fprintf(fid, '%f ', outmat(i,j));
            fprintf(fid, '\n');

end; % tt