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.

Analyze MMN data with MNE-python

export PATH=/lena13/home_users/users/lemarechal/cluster_data/anaconda/bin:$PATH
source activate mne_python_0_10
export PYTHONPATH=/lena13/home_users/users/lemarechal/dev/SCRIPTS/MMN:/lena13/home_users/users/lemarechal/dev/SCRIPTS/meg_processing
ipython --pylab qt
import mmn_subjects
import tsss
tsss.tsss(mmn_subjects.subject_1.runs[0])
tsss.tsss(mmn_subjects.subject_1.runs[1])

Check visuel rapide du fichier aigu01_trans_tsss.fif pour détecter des bad channels
Si detection de bad channels, identifier les bad channels dans le fichier raw original: aigu01.fif, modifier les parametres de description du run (bad_channels, cf syntaxe dans SCRIPTS/meg_processing/subject.py) dans SCRIPTS/MMN/mmn_subjects.py et relancer tsss sur le run.
Check visuel des artefacts (muscle, jump) dans aigu01_trans_tsss.fif et mise à jour des parametres de description du run (bad_segments) dans SCRIPTS/MMN/mmn_subjects.py.
Pareil pour aigu02_trans_tsss.fif
Preprocessing : ICA to remove blink and cardiac artefacts

import mmn_subjects
import mne_preprocess_run
mne_preprocess_run.mne_preprocess_run( mmn_subjects.subject_1.runs[0] )
mne_preprocess_run.mne_preprocess_run( mmn_subjects.subject_1.runs[1] )

WARNING : sometimes, when looking for horizontal (or vertical?) blink component, I found the same IC as for ecg... and visually, the correction is not good. When this happens, I recompute the ICA...

Evoked potentials :

import mmn_subjects
import mne_average_subject
subj=mmn_subjects.subject_1
mne_average_subject.mne_create_epochs_subject( subj, mmn_subjects.evoked_parameters )
mne_average_subject.mne_average_subject      ( subj, mmn_subjects.evoked_parameters )
mne_average_subject.mne_review_subject_erp_2 ( subj, mmn_subjects.evoked_parameters ) # evoked butterfly plot

Evoked potentials (2) :
To get the same number of events in both conditions standard and deviants

import mmn_subjects
import mmn_average_subject
subj=mmn_subjects.subject_1
mmn_average_subject.mmn_average_subject( subj, mmn_subjects.evoked_parameters )

Statistical analysis :

# find significative clusters
mmn_average_subject.mmn_cluster_stats_sensor( subj, mmn_subjects.evoked_parameters )

Influence of the number of permutations for the significant clusters
Permutations repeated 10 times using 1000 or 10000 permutations
Code : /lena13/home_users/users/lemarechal/dev/SCRIPTS/MMN/test_mmn_average_subject.py
results are summarized here /lena13/home_users/users/lemarechal/dev/data/MMN/subject_1/laurent_l/151110/mne/images/tests in directories test_n_permut_1000 and test_n_permut_10000
with the files : README.txt 0.png 1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png
=> 10000 permutatons is a minimum

Prepare anatomy (mne_setup_source_space, mne_watershed_bem and mne_setup_forward_model):

export SUBJECTS_DIR=/lena13/home_users/users/datalinks/REFERENCE/laurent_l/anat/fs_segmentation
export SUBJECT=fs_segmentation
/lena13/home_users/users/lemarechal/dev/SCRIPTS/meg_processing/mne_process_subjects.sh

Source localization :

import mmn_subjects
import mne_localize_subject
subject=mmn_subjects.subject_1
mne_localize_subject.mne_coregister_subject( subject ) # saved in /lena13/home_users/users/lemarechal/dev/data/MMN/subject_1/laurent_l/151110/mne/subject_1-trans.fif
mne_localize_subject.mne_make_forward_solution( subject )
mne_localize_subject.mne_compute_noise_covariance( subject )
mne_localize_subject.mne_make_inverse_operator( subject )
mne_localize_subject.mne_source_estimate( subject, mmn_subjects.evoked_parameters )