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”.
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
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.
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
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.
No update for importing FieldTrip time-frequency results.
However, we added a direct support for the FieldTrip multitaper function (process “Frequency > FieldTrip: ft_mtmconvol”)
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?
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.
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.
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.
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.
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
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: brainstorm3/toolbox/io/import_raw.m at master · brainstorm-tools/brainstorm3 · GitHub
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.
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).