This is a collaborative space. In order to contribute, send an email to maximilien.chaumon@icm-institute.org
On any page, type the letter L on your keyboard to add a "Label" to the page, which will make search easier.

Analysis pipeline example

/lena13/home_users/users/datalinks/TMP_CALCUL/jd/FUSION/tuto

  1. 1_import_data.sh (MRI+MEG)
  1. 2_freesurfer_segmentation.sh

Check the segmentation: http://wiki.cenir.org/doku.php/segmentation_freesurfer

  1. 3_preprocess_meg.sh
  • run the script for all the subjects without specifying bad channels
  • review each tsss for each run of each subject and look for bad channels (maxfilter automatic detection of bad channels is OFF when running tsss). Also check the "cahier de manip" ! When a bad channel is detected in the TSSS file, you should identify the source in the RAW file. !!! IMPORTANT : Bad channels are identified from the RAW file !!!

subject1, run1_trans_tsss : ok
subject1, run2_trans_tsss : 88.766 (jump mag + grad) ok
subject2, run1_trans_tsss : MEG0121 (60-62) GRAD(18.7 60-62)
subject2, run2_trans_tsss : ok
subject3, run1_trans_tsss : BAD = MAG2621 GRAD2612 GRAD2632
=> review raw file to identify bad channels
subject3, run1 : BAD = MAG2621
=> rerun the script with bad channel = 2621
=> review tsss to chek no more bad channel
subject3, run2_trans_tsss : BAD = ...
=> rerun the script with bad channel = 2621
=> review tsss to chek no more bad channel

  • review magnetometers only then gradiometers only, note acquisition "incidents" (jump)
  • specify the bad channels for each run of each subject in the script
  • rerun the script
  • check each tsss


IMPORTANT: check no bad channel remains in tsss file. If any, go back to raw data, identify it and rerun maxfilter with bad channel specified.

Preprocessing with Fieldtrip


Before processing ICA for blink correction, main artefacts must be identified.
subject1, run1_trans_tsss : MAG and GRAD ok
subject1, run2_trans_tsss : 88.5-89 (jump mag + grad) 169-171 (muscle mag + grad)
These info can be retrieved in subject_1/MEG/stim01_trans_tsss.txt and subject_1/MEG/stim02_trans_tsss.txt
and must be updated in run_ica_all.m before running run_ica_all.m
Then you should select the ICA componenets to remove:
muse stim01_trans_tsss.fif ft/stim01_trans_tsss_ft_componentanalysis_runica_trial_1.mat to identify a single blink component : #2
muse stim02_trans_tsss.fif ft/stim02_trans_tsss_ft_componentanalysis_runica_trial_1.mat to identify two blink components : #3 and #4
and remove the identified components (script run_ica_all.m)
WARNING : the function ft_rejectcomponenet change the ordering of the channels !! ft_rejectcomponent is called inside remove_ica_components_base.m and followed by a call to the function reorder_channels.m
check each corrected run of each subject and note remaining artefats you want to remove for the average

Update (id of the conditions, run filenames, bad segments and ica components to remove for each subject) and run average_erp_all.m to create the ERP for the 2 conditions

To inspect visually the ERP :

Error rendering macro 'code': Invalid value specified for parameter 'lang'
review_erp('subject_1','SOM_L')
review_erp('subject_2','SOM_L')
review_erp('subject_1','SOM_R')
review_erp('subject_2','SOM_R')

Preparation of the anatomy with Freesurfer/MNE

source mne_process_subjects.sh
process_subject subject_1
process_subject subject_2
process_subject subject_3

mne_process_subjects.sh
http://martinos.org/mne/stable/manual/cookbook.html#setting-up-the-source-space
http://martinos.org/mne/stable/manual/cookbook.html#creating-the-bem-model-meshes
http://martinos.org/mne/stable/manual/cookbook.html#setting-up-the-head-surface-triangulation-files
http://martinos.org/mne/stable/manual/c_reference.html#mne-setup-forward-model

New Files :

[lemarechal@pclx12 tuto]$ s=1
[lemarechal@pclx12 tuto]$ diff -r subject_${s}/IRM/subject_${s} subject_${s}/IRM/subject_${s}_SAVE/
Only in subject_1/IRM/subject_1/bem: subject_1-5120-bem.fif
Only in subject_1/IRM/subject_1/bem: subject_1-5120-bem-sol.fif
Only in subject_1/IRM/subject_1/bem: subject_1-head.fif
Only in subject_1/IRM/subject_1/bem: subject_1-inner_skull-5120.pnt
Only in subject_1/IRM/subject_1/bem: subject_1-inner_skull-5120.surf
Only in subject_1/IRM/subject_1/bem: subject_1-inner_skull.surf
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-lh.dip
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-lh.pnt
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-lh.w
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-rh.dip
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-rh.pnt
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-rh.w
Only in subject_1/IRM/subject_1/bem: subject_1-oct-6-src.fif
Only in subject_1/IRM/subject_1/bem: subject_1-outer_skin.surf
Only in subject_1/IRM/subject_1/bem: subject_1-outer_skull.surf
Only in subject_1/IRM/subject_1/bem: watershed
Only in subject_1/IRM/subject_1/scripts: mne_setup_forward_model.log
Only in subject_1/IRM/subject_1/scripts: mne_setup_source_space.log
Only in subject_1/IRM/subject_1/scripts: mne_watershed_bem.log

Prepare the source space for BS:

# mne python
export PATH=/lena13/home_users/users/lemarechal/cluster_data/anaconda/bin:$PATH
source activate mne_python_dev
ipython create_cortex.py

Source Localization within BS

Export EP for BS : avg_FT_2_BS_all.m

Source Localization within BS

Error rendering macro 'code': Invalid value specified for parameter 'lang'
addpath /lena13/home_users/users/lemarechal/cluster_data/brainstorm/brainstorm_141210/brainstorm3
brainstorm

Creation of new protocol tuto_FUSION
New subject: subject_1
Anatomy
Import MRI: subject_1/IRM/subject_1/mri/T1.mgz
Import surfaces:

  • subject_1/IRM/subject_1/bem/watershed/subject_1_outer_skin_surface
  • subject_1/IRM/subject_1/bem/watershed/subject_1_outer_skull_surface
  • subject_1/IRM/subject_1/bem/watershed/subject_1_inner_skull_surface
  • subject_1/IRM/subject_1/bem/subject_1-oct-6-src.surf and Set surface type -> Cortex

Functional data:
subject_1 -> Import channel file -> subject_1/MEG/stim01_trans_tsss.fif and Refine registration
subject_1 -> Intra-subject -> Compute head model

Error rendering macro 'code': Invalid value specified for parameter 'lang'
s1_nc=load('subject_1/MEG/ft/noise_covariance_prestim.mat');
s1_nc=s1_nc.cov;

subject_1 -> Intra-subject -> Noise covariance -> Import from Matlab -> s1_nc

Error rendering macro 'code': Invalid value specified for parameter 'lang'
s1_l=load('subject_1/MEG/ft/avg_SOM_L_FT_2_BS.mat');
s1_r=load('subject_1/MEG/ft/avg_SOM_R_FT_2_BS.mat');

tuto_FUSION(subjects) -> Add condition -> SOM_L
tuto_FUSION(subjects) -> Add condition -> SOM_R

subject_1 -> SOM_L -> File -> Import from Matlab -> s1_l
subject_1 -> SOM_R -> File -> Import from Matlab -> s1_r

Copy subject_1 -> Intra-subject -> Neuromag channels (325), Overlapping spheres and Noise covariance (Matlab) to subject_1 -> SOM_L and subject_1 -> SOM_R
subject_1 -> Compute sources

:tuto_fusion_bs.png?200|
and same processing for subject_2:
:tuto_fusion_bs_subject2.png?200|
and subject_3:
:tuto_fusion_bs_subject3.png?200|

Group analysis:
In Functional data (sorted by conditions), select SOM_L -> subject_1 -> Average -> MN: MEG ALL(Constr), SOM_L -> subject_2 -> Average -> MN: MEG ALL(Constr) and SOM_L -> subject_3 -> Average -> MN: MEG ALL(Constr) and drag-drop them in Files to process: Results
Click RUN -> Average -> Average files and select By trial group (grand average) and Average absolute values: mean(abs(error))
SOM_L -> Group analysis -> Avg(abs): Average (3 files) is created.
and repeat for the SOM_R condition

:tuto_fusion_bs_group.png?200|

Preprocessing with MNE-Python

export PATH=/lena13/home_users/users/lemarechal/cluster_data/anaconda/bin:$PATH
source activate mne_python_0_10
ipython --pylab qt
import mne_subjects
import mne_preprocess_run
import mne_average_subject

subject = mne_subjects.subject_1

mne_preprocess_run.mne_preprocess_run  ( subject.runs[0] )
mne_preprocess_run.mne_preprocess_run  ( subject.runs[1] )
mne_average_subject.mne_average_subject( subject )
mne_average_subject.mne_review_subject_erp( subject )

Once the 3 subjects have been averaged, create a report : report_evoked_potentials.html

import mne_average_subject
# creates report_evoked_potentials.html
mne_average_subject.make_report()

Source Localization with MNE-Python

Coregistration:
http://martinos.org/mne/stable/generated/mne.gui.coregistration.html#mne-gui-coregistration\\
HOWTO:
http://fr.slideshare.net/mne-python/mnepython-coregistration\\

DON'T SPECIFY QT BACKEND !!! (maybe because Coregistration GUI works with vtk...)

ipython
import mne_localize
import mne_subjects
mne_localize.mne_coregister_subject(mne_subjects.subject_1)

In the "MRI Fiducials" panel:

  • select Lpa and click the fiducial in the 3D View
  • select Nasion and click the fiducial in the 3D View
  • select Rpa and click the fiducial in the 3D View

"Lock" the fiducials

In the "Head Shape to MRI Coregistration" panel, "Fit Head Shape"
"Save As..." the coregistration in default file : subject_1/MEG/subject_1-trans.fif

Create the forward solution:

mne_localize.mne_make_forward_solution(mne_subjects.subject_1)

Compute the noise covariance:
http://martinos.org/mne/stable/faq.html#how-should-i-regularize-the-covariance-matrix

mne_localize.mne_compute_noise_covariance(mne_subjects.subject_1)

Create inverse operator, compute source estimates and plot the results:

mne_localize.mne_make_inverse_operator(mne_subjects.subject_1)
mne_localize.mne_source_estimate(mne_subjects.subject_1)

Analyze of MMN data with MNE