Flipping BioSemi EEG layout

Hello Brainstorm community,

I am currently using ICBM152 > BioSemi > BioSemi 64 10-10 for my EEG montage.
However, due to my test population who are unilaterally deaf due to surgery, during analysis, I need to flip the electrodes to one hemisphere for all participants consistently for averaging.

Flipping the electrodes consistently to one hemisphere is necessary otherwise the neural plasticity effects of unilateral deafness due to surgery will be averaged out as half of my participants have left-sided deafness and half have right-sided deafness due to the surgery.

Therefore this process requires not just flipping the channel names to its hemispheric counterpart (e.g. Fp1 to Fp2) but the specific EEG measurement that the channel recorded as well.

What would be the fast and easy way to do this?
Many thanks in advance. Hope my explanation made sense.

Maybe you could rename the channels for the patients you want to flip?

Right-click on the channel file > Edit channel > Edit the labels manually to exchange all the pairs of symmetric electrodes (eg. rename Fp1=>Fp2 and Fp2=>Fp1), then save the modifications. Do not keep two channels with the same label, this would cause lots of problems.

If you do this, you wouldn't be able to average directly the EEG measurements for all the participants together because the list of channels would be different. You'd need to rewrite all the modified patients files to actually exchange the EEG signals in the data files. You can do this by selecting in Process1: first one unmodified patient, and then all the modified patients, then run the process "Standardize > Uniform list of channels > Use first channel file in the list".

Does this help?

Thank you Francois!
By your statement below, does this also mean that if I select one modified (that is, patient that has the flipped EEG montage) patient and all the unmodified patients and go through your suggestion, the resulting EEG channels of all the unmodified patients will be the same as the original modified patient EEG montage?

Yes, it should work exactly in the same way. The objective is to rewrite all the data files to have the channels in the same order, in order to be able to average them together.

The actual order of the channels doesn't matter much as long as this order matches exactly between the channel file and all the data files.

Thanks for your response to this Francois.
I've been working on this for the past few days and I am currently facing some obstacles.

It looks like the process "Standardize>Uniform list of channels" cannot process links to raw files.
Is there no other way to do this other than manually changing the channels?
I have 7 people with left intact ears and 6 people with right intact ears. Each participant goes through 8 different conditions therefore if I want to flip the 6 (right intact ear) people to the left, I would have to do this 48 times.

The electrode positioning comes first before my analysis pipeline (e.g. bandpass filter and DC offset) therefore whatever process that would require must be able to process links to raw files (which the above process cannot handle).

Indeed. It needs to rewrite completely the channel and data files, and this is only possible with imported data.
If you want to rewrite the entire recording sessions, a possible hack would be to import the entire session as one file (do not use the events or split options in the Import window, apply the process "Uniform list of channels", and then right-click on the imported+edited files > Review as raw.

Is there no other way to do this other than manually changing the channels?

You can write a script to do it: https://neuroimage.usc.edu/brainstorm/Tutorials/Scripting
What else do you have in mind?

I have 7 people with left intact ears and 6 people with right intact ears. Each participant goes through 8 different conditions therefore if I want to flip the 6 (right intact ear) people to the left, I would have to do this 48 times.

For each subject, if all the sessions are acquired with the same setup, you just need to this once, and the copy-paste the channel file to the other conditions.
If the various subjects in the group you want to modify have all the same list of recorded channels (in the exact same order) and you use the same default positions for all of them, then you could probably copy-paste the edited channel file to all the subjects. In this case you'd need to edit the channel file only once.

The electrode positioning comes first before my analysis pipeline (e.g. bandpass filter and DC offset) therefore whatever process that would require must be able to process links to raw files (which the above process cannot handle).

If you copy-paste channel files between recording sessions or subjects, you should do it prior to any other ICA or re-referencing procedure (which result in linear operators saved in the Projector field of the channel file).
Band-pass filters and baseline correction do not cause any modification of the channel file, so there is no particular order in which you should do it. You can do the follwoing: 1) filter, 2) import/epoch, 3) replace the channel file, 4) Rewrite the files with the process "Uniform channel file".

bandpass filter and DC offset

If you apply a band-pass or high-pass filter to your data, you probably don't need to do any DC correction.

Hello Francois,

Thank you for this answer.
So it seems like "Standardize > Uniform list of channels > Use first channel file in the list" option seems to work well upto a certain point.

I first used the "Edit channel file" to manually flip the electrodes from one side to another.
The below diagram is the result of such a process. Double-clicking on the "BDF channels (67)" shows the below diagram. You can see that the even numbers are now on the left and the odd numbers are now on the right which is what I expected from the manual process of switching the sides of the electrodes.

Now, I then used the "First file" of the below Brainstorm tree as the "Use first channel file in the list" option by dragging this file down to the process box. Then I dragged all other "Avg: 1...." files down below the first file and ran the "Standardize > Uniform list of channels > Use first channel file in the list" process.
This definitely did change the "Channel editor" file to how I wanted it to look. As in, if you go into the "Edit channel file" through "BDF channels (67)" I can see that the electrodes are flipped.

HOWEVER, the resulting electrode positioning was still in its original position (i.e. even number on the right and the odd numbers on the left) and the corresponding topography was the same. Therefore in effect, even though the below Brainstorm has the labels "stdchan", they were incompletely flipped as the process only had an effect on the "Channel editor" file.

What are your suggestions for this observation?
Thanks so much for your help.

You did the complicated part: flipping the channels of data in the recordings.
(you should still make sure that this worked correctly)

Now, you can just copy-paste the edited channel file to all the other folders, in order to have the same positions everywhere.

Hello Francois,

Thank you for this suggestion. The copy-paste method worked and the channel files and the 2D topography discs are showing the flipped electrode locations.

Unfortunately, even though the electrode locations are flipped the resulting topographies are NOT.
The below figure is BEFORE the flipping of the electrodes. As you can see the electrode locations are correctly labeled (even numbers on the right and the odd numbers on the left).

The below figure is AFTER the flipping of the electrodes. As you can see the electrode locations are properly labeled as you'd expect (even numbers on the left and the odd numbers on the right). However, you will also see that the resulting topographies are still the SAME.

What can I do in this situation?

At this stage, you flipped both the labels of the electrodes AND the channels of data. This was necessary to find a solution to allow moving the order of the channels in the ERP file.
But indeed, if you stop here, it produces the same topographies as before.

I think that the only last step that you need is to replace the "flipped" channel file with the original channel file, and you would obtain a flipped topography, that you can average/compare with the non-flipped ERPs.

Maybe there was a simpler solution to do that from the interface.
Scripting it in Matlab, as suggested above, would have been relatively easy I think.

Thanks for the reply Francois,

I decided that the easiest way to do this is just to make a new "EEG position" based on the ICBM152 > BioSemi > BioSemi 64 10-10. This way I can incorporate it into my data analysis pipeline. I've attached what I made here. It is essentially the same BioSemi 64 10-10 EEG position except that the locations are all flipped so that I can use it for R to L flipping of electrodes. I think this way is the easiest to get around all the issues that I've been having with this.

channel_BioSemi_64_10-10_RtoL.mat (3.7 KB)

However... this method causes issues when used within an analysis pipeline.
Firstly I used my custom EEG position within the following data analysis pipeline (shown immediately below) and this is what I get (shown below)


Interestingly, if you use the below method my custom EEG position works (shown below).
In this case the EEG electrode locations are exactly where I would expect them to be (flipped from right to left). However the top example is just all over the place.


How can I fix this issue so that I can use my custom EEG position file in an analysis pipeline?

Additionally, if I take the grand average of the participants (consisting of both flipped and un-flipped EEG positions from the method described above) the resulting EEG positions become something like this (shown below). I imagine this is because Brainstorm is trying to take the average point of flipped and unflipped EEG positions and take the middle point between the two (because the Flipped electrode positions are due to due EEG Position channel files). This certainly seems to be the case when I looked into "Edit Channel files".
image

Therefore what I've done is, I just reloaded the ICBM152 > BioSemi > BioSemi 64 10-10 EEG positions to the BDF channels under Group analysis. This then returned the EEG positions to their appropriate locations.

Do you have any other suggestions to resolve this issue?

You must uncheck the option "Apply voxel=>subject transformation from the MRI".
I've tried importing the file you posted on the ICBM152 template, and it works...

Since you made it a new template, you can also select it in the line "Or use default", instead of selecting the .mat file.

Additionally, if I take the grand average of the participants (consisting of both flipped and un-flipped EEG positions from the method described above) the resulting EEG positions become something like this (shown below). I imagine this is because Brainstorm is trying to take the average point of flipped and unflipped EEG positions and take the middle point between the two (because the Flipped electrode positions are due to due EEG Position channel files).

Indeed, it indicates that your channel files do not match across subjects.
You need to flip the rows in the ERP data file and THEN replace the flipped channel file with the original channel file.

Thanks for that suggestion Francois - but it looks like I'll just settle for the solution below that I posted above. I mean all I need to do is just reload the BioSemi 64 10-10 EEG position back into the grand average ERP data which does not seem difficult.

But just to make sure, do YOU see any potential issues that could arise from using this method?
I haven't found any so far but just wanted your expert opinion.

I'm sorry, I did not manage to follow what this "simpler" solution entails.

If you do not use the process "Uniform list of channels" anywhere, then the rows of EEG data (from the F matrix of the subject-level ERPs) that you want to average together are not aligned. In you grand average, the original subject-level ERPs would be averaged as if you had not changed the channel file.
If you don't call this process, you have to edit manually the subject-level ERPs to permute the channels left-right in the F matrices of the flipped subjects.

When averaging "data" files (EEG recordings), the channels are not matched by name. The matrices F in these files are averaged without any modification, regardless of the information contained in the channel file.

Apologies for not being specific.
I just meant that I will follow the steps below which to me seem simpler.

  1. Use the uploaded custom ICBM152 EEG position channel for R to L-sided flipping when required.
  2. Analysis pipeline.
  3. Take the grand average across participants (which will cause the EEG electrodes to be positioned midline due to averaging) and just reload the EEG channel file ICBM152 > BioSemi > BioSemi 64 10-10 under Group analysis to the grand average ERP file. This will return the EEG positions to their appropriate locations.

I double-checked to see that this method still ensures correct data grand averaging.
Therefore I do not see anything wrong with this method - unless you can see anything wrong?

I didn't quite understand what you were trying to say here though.

I repeat what I wrote previously:

If you do not use the process "Uniform list of channels" anywhere, then the rows of EEG data (from the F matrix of the subject-level ERPs) that you want to average together are not aligned. In you grand average, the original subject-level ERPs would be averaged as if you had not changed the channel file.
If you don't call this process, you have to edit manually the subject-level ERPs to permute the channels left-right in the F matrices of the flipped subjects.

The function bst_avg_files.m does match the signals by name, if averages the "F" matrices as is.
If you only modify the channel files, without rewriting the data files (i.e. permute the rows of the "F" matrix), then your grand averaged cannot have the the appropriate subjects flipped left-right. If would produce the same average as if you had not flipped anything.

But maybe your step "2. Analysis pipeline" includes a call to "Uniform list of channels"? Or a manual modification of the F matrices?

Anyway, if you get the results you need, this is what matters.

To better illustrate what I'm trying to explain here, please see this simple example protocol, that you can load with the menu File > Load protocol > Load from zip file.
TutorialEpilepsy_test_flip.zip (707.0 KB)

  • 01: I took one second from the epilepsy tutorial
    image
  • 02: Right-click on the channel file > Edit channel file, and I edited the channel labels to flip left-right (e.g. C3<=>C4, Cz unchanged)
  • 03: I edited manually the positions of the channel file in 02, with the following script, so that in appearance, the channel files in 01 and 03 look the same when displayed on the scalp, but with a different channel order:
    for i=1:length(c01.Channel)
        iChanLoc = find(strcmpi(c02.Channel(i).Name, {c01.Channel.Name}));
        c03.Channel(i).Loc = c01.Channel(iChanLoc).Loc;
    end
  • 04: Average of data in 01 and 03: channel file shows all the electrodes on the midline (indicating that the positions where correctly flipped), but the EEG data is unchanged (the F matrix was not flipped)
    image
  • 05: Result of selecting data 01 and data 03 in Process1 and running "Uniform list of channels > Use the first channel file in the list" => This uses the original channel file, but the topography is flipped left-right with respect with 01.
    image
  • 06: Average of data in 01 and 05: channel file is identical in both and therefore unchanged, data file is average with its flipped version, resulting in a symmetrical left-right topography.
    image image

What you should get for each subject is what is 05, before averaging across subjects.