Hoffman2:MATLAB:EEGLAB

From Center for Cognitive Neuroscience
Jump to: navigation, search

Back to all things Hoffman2

Back to all things MATLAB

Three of the most recent versions of EEGLAB are maintained on Hoffman2 for the FMRI group in the directory

/u/home/FMRI/apps/eeglab


Adding EEGLAB to your MATLAB path

Choose one of the versions from

/u/home/FMRI/apps/eeglab

and add it to your MATLAB path by doing.

  1. Start MATLAB on Hoffman2
  2. Go to
    "File" > "Set Path..."
    • Click "Add with Subfolders..."
    • Navigate to
      /u/home/FMRI/apps/eeglab
      choose which version you'd like to use and click on it.
    • Click "Ok"
    • To save this for future sessions, click "Save."
    • If you don't want to save this path, click "Close" and then click "No" on the window that pops up.
  3. Go to the MATLAB command line and start EEGLAB by typing
    >> eeglab


Running jobs that involve EEGLAB

Normally, if you wanted to run something in EEGLAB, you start up MATLAB on Hoffman2, wait for a node to check out, wait for a license, and then start crunching numbers.

But what if your analysis in EEGLAB is going to take 10 hours, and you need to shut your computer down and leave in five hours? Or you don't want your MATLAB job to crash just because your flaky WiFi decides to die in hour nine of the analysis?

Well, if you have run this analysis before and have the "EEG.history" contents, you should be able to create a MATLAB script (*.m file) from said history and run it as a headless job on Hoffman2.

Pros and Cons of Running your EEGLAB analysis as a job
Pros Cons
Learn how to submit command line scripts and feel powerful controlling lots of computers Have to learn command line scripts and how to submit jobs correctly
Be able to have your analysis run without tying up your computer for hours or days at a time Have to run the analysis through at least once partially to create your script
Be able to run MATLAB jobs longer than 24 hours Have to be comfortable editing MATLAB code to create your *.m file
Be able to run MATLAB jobs that use way more memory than your laptop can.
Possibly be able to run multiple analyses at once if you make the extra step and compile your code (so it doesn't need a MATLAB license)

If you think the Pros outweigh the Cons, and they certainly do if you are processing more than one subject, then this is the solution for you.


CIDAR ADHD

For steps on how to process CIDAR data in EEGLAB, click here.


binica

If you want to run ICA decomposition on your data, it can often be a very time-intensive process. Doing this through the EEGLAB GUI (runica) is almost an order of magnitude slower than doing it with binica or via command line. So let's walk through how to do this the fastest (most parallelizable) way by submitting jobs on Hoffman2.


Export your data from NetStation

  1. If you are going to preprocess your data in NetStation, do so first.
  2. Export your data in the NetStation simple binary format which produces files with the .raw extension. Upload this to Hoffman2 by your choice method.


Prep your data for ICA

  1. Start up MATLAB on Hoffman2 and start EEGLAB
  2. Go to
    "File" > "Import data" > "From Netstation binary simple file"
    • Find your .raw file and select it.
    • Click "Ok" on the first pop up window, and in the second give your dataset a name before clicking "Ok.""
  3. When EEGLAB finishes importing your data Done will appear above the command line.
  4. At this time, do any preprocessing you'd like on the data in EEGLAB/MATLAB.
  5. Add this special directory to your MATLAB path,
    >> addpath('/u/home/FMRI/apps/examples/binica');
  6. Use the command,
    >> prep4binica(ALLEEG.data, ALLEEG.nbchan, ALLEEG.trials*ALLEEG.pnts, 'verbose', 'on', 'filenum', FILENAME);
  7. This will save out the necessary files to run ICA:
    • data in a float-point file, .fdt
    • parameters for ICA in a configuration file, .sc
  8. Exit out of EEGLAB ("File" > "Quit").
  9. Exit out of MATLAB


Run ICA

If you prepared multiple datasets for ICA, you could submit many jobs in parallel to speed up the processing time.

  1. Use a text editor to make a script (e.g. icaScript.sh) on Hoffman2 with the following contents
    #!/bin/bash
    &#13;/u/home/FMRI/apps/eeglab/current/functions/resources/ica_linux < path/to/sc/file 
    where you replace /path/to/sc/file with the full path to the .sc file created by prep4binica.
  2. Make the script executable
    chmod 750 /path/to/script
    replacing /path/to/script with the path to your script file.
  3. Submit this script as a job, we recommend demanding at least 8 hours (time=8:00:00) and 2GB of RAM (mem=2048M) for your job.
  4. Wait for the script to complete.


Import ICA data back to EEGLAB

  1. Start up MATLAB on Hoffman2 and start EEGLAB
  2. Go to
    "File" > "Import data" > "From Netstation binary simple file"
    • Find your .raw file and select it.
    • Click "Ok" on the first pop up window, and in the second give your dataset a name before clicking "Ok.""
  3. When EEGLAB finishes importing your data Done will appear above the command line.
  4. Go to
    "Edit" > "Dataset into"
    • Click "Browse" next to "ICA weights array or text/binary file (if any):" and find the ICA weight file (.wts extension).
    • Click "Browse" next to "ICA sphere array or text/binary file (if any):" and find the ICA sphere file (.sph extension).
    • Click "Ok".
  5. You should now be able to view the ICA information within EEGLAB.


Only Using EGI's "Good" Segments in EEGLAB

NetStation preprocessing has built in methods of classifying data segments as "good" or "bad" depending on a variety of criteria related to noise measurements. Please refer to their pertinent documentation to understand how this is done. In the case where you do your preprocessing in NetStation but would like to use EEGLAB's ICA tool, you probably don't want all those "bad" segments to be used for ICA calculations or other work.

Sadly, your only options for exporting only the "good" segments from NetStation directly to MATLAB is in the form of a .mat file. But EEGLAB doesn't play nicely with these files!

In comes the tedious translation process to make your data usable...

  1. Export your preprocessed data from NetStation as a "Net Station Simple Binary" file.
    Do not export them as "Net Station Simple Binary (Ignore Events)"
    Do not export them as "Net Station Simple Binary (Epoch Marked)"
  2. Import the data file into EEGLAB
  3. Open NetStation, and in the top menu bar go to "Tools" > "Browse Files..." which will open a new data explorer window.
  4. In Finder, locate your final preprocessed data (the one that you ran the Export tool on earlier).
  5. Drag this file into the left had bar labeled "Source Files."
  6. In the top right area of the window, click on the "Categories and Subjects" tab and you should see a grid of numbers and labels.
    The segment types will have their labels at the beginning of each row (e.g. Belief, Disbelief)
    Each source file will have a dedicated column labeled with something (I believe it to be the subject linked to the recording).
  7. Click on the first segment type label and in the bottom right area of the window you will see a list of all segments of that type.
  8. If you click on the column label "Time" it will order the segments chronologically which is the same way they are ordered when you export them as a "Net Station Simple Binary" file.
  9. Back in EEGLAB, use the menu to go to "Edit" > "Select data" which opens another window.
    In this window, you can use different criteria for selecting portions of data. The method pertinent here is by "Epoch range."
    I would recommend clicking the little check box to the right of the input box for "Epoch range" so you only have to specify which epochs you want removed. There should be fewer epochs to remove than there are epochs you want to keep...otherwise your data is really messy and using it might not be recommended...
  10. Have fun counting your way down the lines of the NetStation File Browser to determine exactly which segments are "bad."
  11. Say the sixth segment of the first category is bad (these are the ones with a red circle and line through them at the beginning of the line instead of a green circle). In the EEGLAB data selection window, you need to add "6" to the "Epoch range" input box.
  12. Once you've gone through and told EEGLAB all the epochs you want removed, click the "Ok" button and it will start making a new dataset.
  13. Run prep4binica on the resulting dataset.


Pro Tip

If you have two or more types of segments in NetStation, counting and adding can be a dangerous game. So make use of MATLAB to simplify things.

e.g.

  • You have two segment types: B and D
  • There are 40 type B segments, of which Net Station claims only 37 are good.
  • There are 60 type D segments, of which Net Station claims only 50 are good.
  • In the EEGLAB "Select data" window, you make sure to click the check box to the right of the "Epoch range" input box so that you only have to list the epochs you want removed from the dataset.
  • In the NetStation you click on the "B" category and scrolling through the segments you find that segments 1, 21, and 37 have the little red crossed circle indicating they are bad.
  • In the EEGLAB "Select data" window's "Epoch range" input box you type
1 21 37
  • In the NetStation you then click on the "D" category (since it would be the second category). Scrolling through the segments you find that the 40th through the 49th listed segments all have the red crossed circle indicating they are bad.
  • In the EEGLAB "Select data" window's "Epoch range" input box, you then edit it to read
1 21 37 40+[40:49]
  • This will work because MATLAB is going to process these numbers and see
1 21 37 80 81 82 83 84 85 86 87 88 89
  • The "40+[" part is important because the first "D" category segment is actually the 41st segment overall. If you have more than two categories, you'd have to do similar arithmetic to properly indicate which epochs you want removed.

Happy counting.


External Links