Skip to content

Latest commit

 

History

History
221 lines (194 loc) · 17.3 KB

8. EEG Source Analysis.md

File metadata and controls

221 lines (194 loc) · 17.3 KB

EEG Source Analysis

  1. read_erp_041019.m calculates evoked potentials
  2. eeg_source_coregister.m manual electrode registration
  3. show_eeg_mri_coregister.m displays electrode registration
  4. show_erp_scalp.m shows evoked responses
  5. eeg_mri_coregister_072922.m more detailed registration
  6. make_decimated_bem_052524.m simplifies surfaces
  7. make_bem_d10_eeg_042319.m generates .dip, .eegsensors, .tri, and, .cond files
  8. make_fwd_openmeeg_072922.m generates a eeg_rh_gain.mat and eeg_lh_gain.mat file
  9. make_eeg_fwd_042319.m generates a eeg_fwd_042319.mat file
  10. make_eeg_mne_052524.m generates 6 .stc files

1. Create Evoked Fields

  1. Download read_erp_041019.m and add it to your subjects eeg_raw folder. This script calculates evoked potentials.
  2. Change the header file to your .vhdr file location
headerFile = {
    '../eeg_raw/SSVEP_out_1.vhdr'
  1. Change the marker file to your .vmrk file location associated with your header file. It is important to have only one file listed as the script expects only one.
markerFile={
    '../eeg_raw/SSVEP_out_1.vmrk'

2. Prepare Brain/Head Geometries

  1. Open a new terminal window
  2. tcsh
  3. source .cshrc
  4. setenv SUBJECTS_DIR /Users/jessica/data_analysis/eegfmri/subjects
  5. cd /Users/jessica/data_analysis/eegfmri/subjects to your subject folder
  6. mne_setup_mri --subject 180330_SYH (there is a strong possibility that this file already exists)
  7. mne_setup_source_space --subject 180330_SYH --spacing 5 (there is a strong possibility that this file already exists)
  8. mne_watershed_bem --subject 180330_SYH (there is a strong possibility that this file already exists)
  9. cd $SUBJECTS_DIR/180330_SYH/bem
  10. ln -s watershed/041019_inner_skull_surface inner_skull.surf (there is a strong possibility that this file already exists)
  11. ln -s watershed/041019_outer_skull_surface outer_skull.surf (there is a strong possibility that this file already exists)
  12. ln -s watershed/041019_outer_skin_surface outer_skin.surf (there is a strong possibility that this file already exists)

High-Resolution Head Surface

  1. Make sure you are in the subjects folder directory.
  2. mkheadsurf -subjid 180330_SYH if done successfully, output should be "mkheadsurf done" and a lh.seghead file should be in /Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/surf
If Error "mkheadsurf: Command not found"
  1. cd home
  2. tcsh
  3. source .cshrc
  4. cd /Users/jessica/data_analysis/eegfmri/subjects
  5. setenv SUBJECTS_DIR /Users/jessica/data_analysis/eegfmri/subjects
  6. setenv FREESURFER_HOME /Applications/freesurfer/7.4.1
  7. source $FREESURFER_HOME/SetUpFreeSurfer.csh
  8. setenv FSL_DIR /Users/jessica/fsl
  9. echo $SUBJECTS_DIR /Users/jessica/data_analysis/eegfmri/subjects make sure you are in the correct subject directory
  10. cd /Users/jessica/data_analysis/eegfmri/subjects
  11. mkheadsurf -subjid 180330_SYH should now work
  1. cd /Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/surf to the location of your lh.seghead file
  2. mris_convert lh.seghead lh.seghead.tri if done successfully, output should be "Saving lh.seghead.tri as a surface in TKREGISTER space"

3. Co-register between MRI and EEG sensors

  1. Download the digitizer folder
  2. Download eeg_source_coregister.m and add it to your subjects eeg_raw folder
  3. Change line 4, 7, 8, and 9 to your subject ID, and line 12 and 13 to the name of your .eps and .ela files in your digitizer folder then run
  4. If done successfully, there should be a figure 1 pop-up of a head model
Figure 1 Example Screenshot 2024-05-23 at 10 26 05 AM
5. Click "k" to enable the manual registration GUI to move the electrodes around the head. Upon completing the registration, click the "Export + Save" button, select the fwd_prep_041618.mat file which is the output_name found in line 16, to save the registered electrode locations to the matlab data file. Registered electrode locations will be also exported as the variables, 'points' should in the matlab environment
Registration Example Screenshot 2024-05-23 at 10 40 50 AM Screenshot 2024-05-23 at 10 37 07 AM
  1. Download show_eeg_mri_coregister.m and add it to your subjects eeg_raw folder. This script displays the results of electrode co-registration.
  2. Change line 3 to your subject directory setenv('SUBJECTS_DIR','/Users/jessica/data_analysis/eegfmri/subjects/');
  3. Change line 6 to the location of your 5-src.fif file file_source_fif='/Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/bem/180330_SYH-5-src.fif';
  4. Change line 8 to the location of your lh.white file surfin_lh='/Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/surf/lh.white';
  5. Change line 9 to the location of your rh.white file surfin_lh='/Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/surf/rh.white';
  6. Change line 10 to the location of your outer_skin_surface file surf_outer_skin='/Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/bem/watershed/180330_SYH_outer_skin_surface';
  7. Change line 11 to the location of your outer_skull_surface file surf_outer_skull='/Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/bem/watershed/180330_SYH_outer_skull_surface';
  8. Change line 12 to the location of your inner_skull_surface file surf_inner_skull='/Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/bem/watershed/180330_SYH_inner_skull_surface';
  9. Change line 15 to the output name from the previous step eeg_output_name='fwd_prep_041618.mat';

Examine Evoked Fields on a Head Model

  1. Download show_erp_scalp.m and add it to your subjects eeg_raw folder. Change all variable names from erp_avg to erp (this step should only be done when you have the eeg_fwd_prep_042319.mat file). If done successfully, you should have Figure 1 of the scalp model and if you click on a region there should be a Figure 2 pop-up of the evoked response plot
Figure 1 & 2 Example Screenshot 2024-05-29 at 12 49 35 PM Screenshot 2024-05-29 at 12 49 47 PM

High-Resolution Head Surface

  1. setenv SUBJECTS_DIR /Users/jessica/data_analysis/eegfmri/subjects
  2. mkheadsurf -subjid 180330_SYH if done successfully, output should be "mkheadsurf done" and a lh.seghead file should be in /Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/surf
  3. cd /Users/jessica/data_analysis/eegfmri/subjects/180330_SYH/surf to the location of your lh.seghead file
  4. mris_convert lh.seghead lh.seghead.tri if done successfully, output should be "Saving lh.seghead.tri as a surface in TKREGISTER space"
  5. Download eeg_mri_coregister_072922.m and add it to your subjects eeg_raw folder
  6. Change line 3 to your subject directory setenv('SUBJECTS_DIR','/Users/jessica/data_analysis/eegfmri/subjects/');
  7. Change line 6 to the location of your fif file file_source_fif='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/180401_YTH-5-src.fif';
  8. Change line 9-11 to the location of your inner/outer skull and outer skin files
surf_outer_skull='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/watershed/180401_YTH_outer_skull_surface';
surf_inner_skull='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/watershed/180401_YTH_inner_skull_surface';
surf_outer_skin='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/surf/lh.seghead.tri';
  1. Change line 14 to file_elec_loc='../digitizer/YTH.DAT';
  2. If done successfully there should be a more detailed co-registration, press k to move the blue dots for manual registration. When complete, save and export to the eeg_fwd_prep_072922.mat file
Figure 1 Example Screenshot 2024-05-29 at 2 19 09 PM

4. Reduce the Resolution of Skull and Scalp Surfaces for Efficient Forward Model Calculation

  1. Download make_decimated_bem_052524.m and add this to your subjects eeg_raw folder
  2. Change lines 3-9, make sure these are the decimated files (_d10)
setenv('SUBJECTS_DIR','/Users/jessica/data_analysis/eegfmri/subjects/'); %for MAC/Linux

file_surface={
    '/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/outer_skin.surf_d10.surf';
    '/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/outer_skull.surf_d10.surf';
    '/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/inner_skull.surf_d10.surf';
};
  1. If done successfully, there should be a Figure 1 and 2 pop-up of the original (Figure 1) and simplified surface (Figure 2)
Figure 1 & 2 Example Screenshot 2024-05-29 at 1 33 23 PM Screenshot 2024-05-29 at 1 33 33 PM

5. Prepare Files for Forward Solution Calculation

  1. Download make_bem_d10_eeg_042319.m and add this to your subjects eeg_raw folder
  2. Change lines 3-13 make sure your file_eeg_mat file is the same as the one you populated in the previous detailed co-registration step (in this case eeg_fwd_prep_072922.mat)
setenv('SUBJECTS_DIR','/Users/jessica/data_analysis/eegfmri/subjects/'); %for MAC/Linux

%source space
file_source_fif='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/180401_YTH-5-src.fif';

%make sure these are the decimated files (_d10)
surf_outer_skin='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/outer_skin_d10.surf';
surf_outer_skull='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/outer_skull_d10.surf';
surf_inner_skull='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/inner_skull_d10.surf';

%sesnor info
file_eeg_mat='./eeg_fwd_prep_072922.mat';

output_stem='180401_YTH_d10';
  1. If done successfully, there should be a Figure 1 pop-up showing the inner skull, outer skull, and outer skill geometries, as well as source points (in red) and EEG sensor locations (in blue). You should also have 7 files generated in your eeg_raw folder: 041019_d10-{lh, rh}.dip (dipole current source), 041019_d10.eegsensors (locations of EEG sensors), scalp.tri, skull.tri, cortex.tri (description on geometry for skull and scalp boundaries), 041019_d10_bem.cond (conductivity of materials between boundaries), 041019_d10_bem.geom (wrapper file for boundary geometries)
Figure 1 Example Screenshot 2024-05-29 at 2 25 05 PM

6. Calculate the Forward Model

  1. Download OpenMEEG and add it to your fhlin_toolbox
  2. Download make_fwd_openmeeg_072922.m and add it to your eeg_raw folder
  3. Change line 3 to your subject ID subject='180401_YTH'; and run. This step may take a while. If done successfully, there should be a eeg_lh_gain.mat and eeg_rh_gain.mat in your subjetcs eeg_raw folder
Troubleshooting Error Zsh:1: command not found

Make sure OpenMEEG is correctly initiated in your vi .cshrc file in the settiing up environment step

Running Script on Server

Setting up folders

  1. Enter the server (seen in the useful commands page)
  2. cd /space_lin2/jdin
  3. mkdir eeg_source make a eeg_source folder in the jdin folder
  4. cd eeg_source inside this folder make a subjects folder mkdir subjects

Download data from local environement to server

  1. In another teriminal window cd /Users/jessica/data_analysis/eegfmri
  2. scp -r -P 2222 ./180401_YTH/* jdin@localhost:/space_lin2/jdin/eeg_source moves the 180401_YTH folder from your local computer to the specified folder location on the server
  3. In another teriminal window cd /Users/jessica/data_analysis/eegfmri/subjects
  4. cp -r -P 2222 ./180401_YTH/* jdin@localhost:/space_lin2/jdin/eeg_source` moves the 180401_YTH subject folder (with the T1 data) from your local computer to the specified folder location on the server

Run script on server

  1. tcsh
  2. matlab -nodisplay open MatLab in the terminal window you opened the server on (Note: to exit matlab type exit)
  3. setenv ('EDITOR', 'vi');
  4. setenv ('SUBJECTS_DIR','/space_lin2/jdin/eeg_source/subjects')
  5. cd /space_lin2/jdin/eeg_source/eeg_raw then ls and there should be all the files from 180401_YTH
  6. edit e8_make_fwd_openmeeg_072922 to edit this script, if needed
  7. e8_make_fwd_openmeeg_072922 to run the script (Note you can type 'e8' then tab to autocomplete the rest of the file name)
  1. Download make_eeg_forward_052524.m and add it to your eeg_raw folder
  2. Change line 9 to your subject directory and line 11 to your subject ID. Make sure the file_eeg_mat in line 13 is correct and run
  3. If done successfully, there should be a eeg_fwd_052524.mat file in your subjects egg_raw folder

7. Prepare the Forward Solution for Source Modeling

  1. Download make_eeg_fwd_042319.m and add it to your eeg_raw folder
  2. Change line 10 to the location of your subjects src.fif file file_source_fif='/Users/jessica/data_analysis/eegfmri/subjects/180401_YTH/bem/180401_YTH-5-src.fif';
  3. If done successfully, there should be a eeg_fwd_042319.mat file in your subjects eeg_raw folder

8. Estimate Sources by Minimum-Norm Estimates

  1. Download make_eeg_mne_052524.m and add it to your eeg_raw folder
  2. Change lines 3-4 to ensure you are using the correct eeg_fwd and fwd_prep files
file_fwd='eeg_fwd_052524.mat';
file_bem='fwd_prep_041618.mat';
  1. Change line 9 to your subject ID
  2. Change all erp_avg to erp in lines 29-31
  3. Make sure the number in 29-31 is the trigger with the event (in this case 10, which is the 2ed trigger).
Y=erp{2}.erp; %
timeVec=erp{2}.timeVec; 
label=erp{2}.electrode_name;
  1. If done successfully, there should be 6 .stc files, SSVEP_out_1_042124_15.0hz_dspm-lh/rh, SSVEP_out_1_042124_dspm-lh/rh, and SSVEP_out_1_042124_mne_abs-lh/rh

9. Examine Minimum-Norm Estimates

  1. Download make_eeg_mne_052524.m and add it to your eeg_raw folder
  2. Change line 3 to your subject directory and line 5 to your subject ID
  3. Change line 11 to the .stc file with an event with the trigger (in this case trigger 2, number 10)
[stc,v_idx,a,b,timeVec]=inverse_read_stc('SSVEP_out_1_042124_dspm-rh.stc');
  1. Run one hemisphere at a time (comment out the other)