Import time-frequency data from fieldtrip

Hi everyone,
I would like to analyse an EEG dataset that was processed with Fieldtrip. I have now problem to import the individual ERP data (one file per subject and per condition), but when I try to do the same for the time-frequency data I get the following error message :
** This file is not a valid FieldTrip recordings structure (timelocked or raw).
** Missing fields: “time”, “label”, “avg” or “trial”.

Do you know what I can do to import these files ?

Thanks a lot

Thomas

Hi Thomas,

The import of FieldTrip time-frequency structures has not been developed yet. It’s in the todo list:
http://neuroimage.usc.edu/brainstorm/Next#Input_.2F_output

If you are interested in contributing to it, I can guide you. What we need is a function that converts a FieldTrip structure in a Brainstorm timefreq structure, similarly to what is done in in_data_fieldtrip.m
The export function already exists but is not fully functional (see the forum post in the todo list): out_fieldtrip_timefreq.m

Francois

Hi François,
With my modest scripting skills we are happy to help !
Tell me what I can do.

Thomas

Ok! Then you can get started with this:

  • Create a function in_timefreq_fieldtrip that converts a FieldTrip structure in a Brainstorm timefreq structure, similarly to what is done in in_data_fieldtrip.m (the corresponding export function is out_fieldtrip_timefreq.m)
  • Create a function that saves new files in the database, similar to import_results.m or import_dipoles.m

Then I will add the corresponding menus to make this function available from the interface.

Have fun :slight_smile:
Francois

Whoa I think this is beyond what I am able to do ^^.
Good luck with that, maybe someone else in the forum could contribute.

Thomas

We’ll do it at some point, but I cannot tell you when precisely.

Hello,
I am also trying to import time-frequency data obtained with fieldtrip to brainstorm.
Has this function been developed already? (fingers crossed…!!)
Thanks,
Mariana

Hi Mariana,

No function to import a time-frequency file from fieldtrip, but the possibility to compute directly the time-frequency decomposition using FieldTrip’s multitaper functions. Process Frequency > FieldTrip: ft_mtmconvol.

If your goal is to review in Brainstorm files computed with FieldTrip, a simple solution is to compute the equivalent file in Brainstorm, and replace the data matrix with your own results:
http://neuroimage.usc.edu/brainstorm/Tutorials/Scripting#Custom_processing

Cheers,
Francois

Great, thank you François!

Hi Francois,

is there any update to this function, or is replacing the data matrix in brainstorm with the one from fieldtrip still the best way to to go about it?

Thank you,
Paul

Hi Paul,

No update for importing FieldTrip time-frequency results.
However, we added a direct support for the FieldTrip multitaper function (process “Frequency > FieldTrip: ft_mtmconvol”)

Francois

Hello everyone,

I also regularly work with fieldtrip timefreq structures, essentially for statistics.
I made a small script that allows me to convert a file list containing fieldtrip structures into a brainstorm compatible database.
I will be able to develop a brainstorm-compatible script to facilitate the brainstorm-fieldtrip data exchange when I have some time to develop it if you are interested.
Tell me what it necessary, do you just need a function that converts a fieldtrip file into a brainstorm compatible file, or rather transforms a file list into a database?

Sincerely,

Alexandre

Hi Alexandre,

Thank you for offering your help.

Can you describe more precisely what your code does, so I can give better integration advices?
What kind of structures does it convert? Is it built on top of the brainstorm functions in_..._fieldtrip.m?

About importing generic lists of FieldTrip files as a Brainstorm protocol, I’m not sure how generic it could be. There is no standard naming for FieldTrip files, and they don’t include either informations such as subject names... It might be better to improve the single file import and make sure it can be automated with scripts generated from the pipeline editor.

The best way for submitting your contributions is to push it directly to our GitHub repository. Open a pull request, we will review it, merge it and it we be added to the main Brainstorm distribution.

Thanks
François

Hi Francois,

Indeed the function is quite simple since it converts a structure containing the :

  • powspctrm in TF
  • freq in Freq
  • time in Time
  • label in RowNames

Where it actually gets a little more complicated is how to manage the automatic creation of subjects and conditions.
For my part, I use the filename to manage it.
For example SubName_CondName_FileName.mat
It can be complicated to make this code generic, since it is adapted to the way I label my files.

Kind regards,

Alexandre

Indeed, there is nothing to convert FieldTrip time-frequency structures into Brainstorm structures.
We have only an export function Brainstorm to FieldTrip: https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/io/out_fieldtrip_timefreq.m

What would be interesting would be to add:

  • A function toolbox/io/in_timefreq_fieldtrip.m, similar to in_data_fieldtrip.m, to simply do the structure conversion
  • A function toolbox/io/import_timefreq.m, similar to import_matrix.m, to register new time-frequency files into the database (examples to register new TF files can be found in process_ft_mtmconvol.m)
  • Someting to make this function available in the interface: maybe a new item in the popup menu of the database explorer similar to the menu "Import source maps"

It means more or less splitting your conversion function in two and adding it to the GUI.
Let me know if you need more information about this.

For the database structure, let's not try to make it generic. Your script could be posted in the user scripts repository (https://github.com/brainstorm-tools/bst-users) but would be too complicated to integrate in the Brainstorm distribution. For the moment, we put all our standardization efforts on setting up the BIDS specification (https://bids.neuroimaging.io/), which will eventually allow exchanging structured data between programs.

Hello Francois,

I started trying to implement my script, here's where I am.
I created a function in_timefreq_fieldtrip.mat, which converts the fieldtrip struct data (powspctrm, time, freq, label) into a DataMat structure (generated by db_add('timefreqmat').

It seems to me that doing a function like import_matrix.m is not necessary because in the function in_timefreq_fieldtrip.mat I have all the elements in order to be able to create a file compatible with brainstorm.
However, I didn't do any code to create a channel.mat file and I don't know how to save the file in the database with db_add.

Do you have any suggestions?

Thank you.

Kind regards,

Alex

I created a function in_timefreq_fieldtrip.mat, which converts the fieldtrip struct data (powspctrm, time, freq, label) into a DataMat structure (generated by db_add('timefreqmat').

The function in_timefreq_fieldtrip should not copy the files into the database, it should simply convert the structure, therefore it should not call db_add(). But I guess you meant db_template('timefreqmat').

It seems to me that doing a function like import_matrix.m is not necessary because in the function in_timefreq_fieldtrip.mat I have all the elements in order to be able to create a file compatible with brainstorm.

Not necessary for you, but necessary for the other people who would like to use your code :slight_smile:
The goal of this function would be only to call the conversion function and save it into the database.

However, I didn't do any code to create a channel.mat file and I don't know how to save the file in the database with db_add.

To create a default channel file, you can use something like this:
https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/io/import_raw.m#L221
Or you can consider that it is not the job of this function to create a channel file... One option could be to load a piece of recordings of the initial recordings (which creates a channel file), and then import the TF file using this existing channel file.

Does this help?

Thank you Francois,

So I did a first commit on GitHub (first time I used GitHub...), so it is a basic function that need to be improved.

Kind regards,
Alex

Hi Alex,

I guess you committed your changes to your github fork.
When you are ready to submit your modifications to the Brainstorm repository, you can open a pull request.
(learning how to use git is a bit painful at the beginning, but really worth it on the long run).

Francois

Hi Francois,

I just pulled a request, can you tell me if you receive ?

Alex