This tutorial illustrates how to convert Micromed .TRC files into SPM format, then how to process these files in ImaGIN: bad channels, bipolar montage, event management… We will import three TRC files, corresponding to three seizures of the same patient. With the interactive interface, we can process the files only one after the other, all the operations illustrated below will have to be repeated three times.
Start ImaGIN
- Download zip: https://git.f-tract.eu/ftract_dev/ImaGIN2/tree/master/
- Unzip on your computer, rename to "ImaGIN2"
- Start MATLAB, go to the ImaGIN2 folder
- Run script: ImaGIN.m
Convert to SPM .mat/.dat
-
Select menu Import > Convert: ImaGIN_spm_eeg_converteeg2mat.m
-
Select the first seizure SZ1.TRC:
Navigate to the folder tutorial_epimap/seeg/ with the left panel, then click on SZ1.TRC in the right list so it gets selected in the bottom panel, then click [Done].
- Note: If you change the current MATLAB directory to tutorial_epimap/seeg/, it would make the file selections easier in the rest of the tutorial as you wouldn't have to change folder every time.
-
Check in your file explorer the new files that were created for this first seizure:
• SZ1.mat/SZ1.dat: Recordings converted in SPM format
• SZ1_log.txt: Text file that lists the names of the channels that were kept or deleted during this conversion. - This conversion function assumes the recordings are sEEG recordings with specific nomenclatures: the label of a channel must start with the name of the depth electrode and end with the index of the contact on the electrode (numbering starting from 1).
Add 3D positions
The 3D locations of the sEEG contacts are not available in the .TRC files. They are saved in a separate text file that we need to add manually to the SPM .mat/.dat file.
-
Select menu Import > Electrodes positions: ImaGIN_Electrode.m
-
Interactive options:
• Select data file: SZ1.mat
• Select text file for electrode names: anat/implantation/Electrodes_Name.txt
• Select text file for electrode positions: anat/implantation/Electrodes_Pos_MNI.txt - This does not produce any new file in output but adds the contacts locations in the SPM .mat file (field D.sensors.eeg.elecpos and .chanpos). The positions added to the file are in normalized MNI coordinates.
You can display the positions of the contacts:
-
Click on the button Electrodes. ImaGIN_DispElectrodes.m
-
Interactive options:
• Select SEEG data file: SZ1.mat
• T1 Overlay: Subject
• Select image: tutorial_epimap/anat/MRI/wBrainPre.nii -
The prefix "w" indicates this volume in normalized in MNI space. We select the normalized MRI because the coordinates of the SEEG contacts were imported in MNI coordinates.
Bipolar montage
The sEEG recordings are commonly represented and processed as bipolar recordings, but the data is usually acquired using a reference common to all the electrodes. To convert it to a bipolar montage, we compute the difference between pairs of adjacent contacts.
-
Select menu Import > Bipolar montage: ImaGIN_BipolarMontage.m
- Select data file: SZ1.mat
- This function creates a new dataset with the prefix "b" for "bipolar": bSZ1.mat / bSZ1.dat
- Additionally, the log file bSZ1_log.txt documents the bipolar channels that are saved in the new file (eg. "b'2b'1" represents the difference between signals "b'2" and "b'1").
Review the signals
You can use the SPM, ImaGIN or Brainstorom viewers to review the recordings.
-
Review file bSZ1.mat with the options available in the the Display menu: ImaGIN_DispData.m / spm_eeg_load.m / ImaGIN_DispDataBst.m
- The goal is to identify the bad channels and the seizure onset for each file.
-
Bad channels found for file bSZ1.mat: f'2f'1 (#28), v'2v'1 (#74)
-
Onset of seizure in file bSZ1.mat: 120.8s after the beginning of the file.
- In the ImaGIN viewer, you can browse through all the channels with the arrow buttons at the bottom-right of the figure, and edit the time window with the text boxes at the bottom-left.
-
You can also use the Brainstorm file viewer, documented in the online tutorials #5 and #7:
Set bad channels
- If you used the Brainstorm viewer to mark the bad channels, you don't have to do this and can directly use bSZ1_bst.mat.
-
Select menu Import > Bad channels: ImaGIN_BadChannelSet.m
-
Interactive options:
• Select data file: bSZ1.mat
• Bad channels: 28 74
• Alternatively, you can enter the channel names: f'2f'1 v'2v'1 - This function doesn't produce any new file, it updates the field D.channels(:).bad in the input .mat file.
Add seizure onset event
- If you used the Brainstorm viewer to add the onset marker, you don't have to do this and can directly use bSZ1_bst.mat.
-
Select menu Import > Bad channels: ImaGIN_BadChannelSet.m
-
Interactive options:
• Select data file: bSZ1.mat
• Events: Add
• Number of events to add: 1
• Type of event 1: Onset
• How to specify the timing: Manual
• Timing of the event [sec]: 120.8 - This function updates the field D.trials.events in the input .mat file.
Set time origin
-
Select menu Import > Set time origin: ImaGIN_TimeZero.m
-
Interactive options:
• Select data file: bSZ1.mat
• Name of reference event: Onset
• Duration [sec] before reference: 0 -
This function updates the field D.timeOnset in the input .mat file. After the execution, the time reference (t=0) becomes the seizure onset, while previously it was the beginning of the file.
Import baseline
In the next tutorial, we will compute a time-frequency decomposition of the seizure and normalize it with respect to a baseline level. We will identify and import this baseline now. The baseline could be a segment of 5s to 30s of recordings before the seizure that contains as little interictal epileptiform activity as possible.
The duration of the baseline influences the computation time for the following steps of this tutorial. We will work here with short segments of 5s for illustration purposes, between 48s and 43s before the seizure onset ([72.8, 77.8]s from the beginning of the file). Use longer segments for more accurate results.
-
Click on the button [Epoch]: ImaGIN_Crop.m
-
Interactive options:
• Method: Manual
• Select data file: bSZ1.mat
• Type of start event: Onset
• Duration [sec] before start event: 48 (corresponds to -48s)
• Type of end event: Onset
• Duration [sec] after end event: -43 (corresponds to -43s, do not forget the "-")
• Prefix of new file: Baseline_ - This function creates a new file in the seeg folder: Baseline_bSZ1.mat/.dat
Repeat for the other files
We need now to process the other epileptic seizures in the same way: SZ2.TRC and SZ3.TRC.
SZ2.TRC
- Bad channels: 74 (v'2v'1)
- Seizure onset: 143.510s
- Baseline: From -40s to -35s wrt the onset marker ([103.51, 108.51]s from the beginning of the file)
SZ3.TRC
- Bad channels: 54 (o'2o'1)
- Seizure onset: 120.287s
- Baseline: From -75s to -70s wrt the onset marker ([45.287, 50.287]s from the beginning of the file)
Scripting
Corresponding MATLAB script:
https://git.f-tract.eu/ftract_dev/ImaGIN2/blob/master/tutorial/tutorial_epimap.m#L97
Next tutorial: Tutorial 4: Time-frequency