Bidsify
To promote the use of BIDS and simplify the implementation on the data collected at NatMEG this pipeline was created.
The source scripts are available on the cir server (TBA), but can also be downloaded from the NatMEG-utils GitHub repository
This bidsify.py
script converts data from NatMEG (MEG, EEG, OPM) to BIDS format and organizes the data into a BIDS-compliant folder structure. The script is designed to work with data collected at NatMEG and uses the MNE-BIDS library.
Prerequisits
Ensure you have the following non-defualt libraries installed in your Python environment: mne
, mne_bids
, numpy
, pandas
Install requirements
- Make sure python modules are installed in the environment. If not, install them using the following commands:
conda install mne mne-bids
Process
Components
Generally there are three steps in the conversion process:
- Create a configuration file: The script will prompt you to create a configuration file if it does not exist. This file contains paths to the raw data, BIDS folder, calibration and crosstalk files, and other parameters needed for the conversion.
- Create a conversion table: The script creates a conversion table that estimates task names, processing, and other parameters to create the BIDS-compliant file name. Before running the conversion you should check task names and other parameters in the conversion table.
- Convert the data: The script converts the data to BIDS according the to the conversion table. The script will also create a
dataset_description.json
file and aparticipants.tsv
file if they do not already exist.
Usage
python bidsify.py [--help] [--config CONFIG] [--edit] [--conversion CONVERSION] [--overwrite]
Options
--help
: Show help message and exit.--config
: Path to the configuration file. If not provided, a you will be promted in the terminal to create a new or open an existing one.--edit
: Open a dialog to edit the configuration file before running the script.--conversion
: Path to the conversion file. If not provided, the latest conversion file will be used.--overwrite
: Overwrite last conversion file and create a new one. This will not overwrite the conversion table but create a new one with the same name as the last one with a timestamp.
Config file
A configuration file is needed and you will be prompted to create a defaul file if it does not exist. You will be promted to open an existing config file or create a new one. The default template will be created in the current working directory. You can also point to an existing config file the --config
flag. Edits can be made to the config file by using the --edit
flag or by opening the json-file in a text editor.
Default config file
{
"Tasks": [""],
"squidMEG": "/neuro/data/sinuhe/<project_on_sinuhe>",
"opmMEG": "/neuro/data/kaptah/<project_on_kaptah>",
"BIDS": "/neuro/data/local/<project_on_local>",
"Calibration": "/neuro/databases/sss/sss_cal.dat",
"Crosstalk": "/neuro/databases/ctc/ct_sparse.fif",
"Dataset_description": "dataset_description.json",
"Participants": "participants.tsv",
"Participants mapping file": "/neuro/data/local/<project>/mapping.csv",
"Original subjID name": "old_subject_id",
"New subjID name": "new_subject_id",
"Original session name": "old_session_id",
"New session name": "new_session_id",
"Overwrite": "off"
}
Description
Tasks
: List of tasks to be included in the conversion. This is used as a check to match the intended task names with the task names in the raw data. If a task is misspelled or missing it will be flagged in the conversion table and you will be prompted to edit the conversion table before continuing.squidMEG
: Path to the raw data folder for SQUID MEG dataopmMEG
: Path to the raw data folder for OPM MEG dataBIDS
: Path to the BIDS folder where the data will be savedCalibration
: Path to the calibration fileCrosstalk
: Path to the crosstalk fileDataset_description
: Path to the dataset_description.json file in the BIDS folderParticipants
: Path to the participants.tsv file in the BIDS folderParticipants mapping file
: Path to the mapping file that contains the original and new subject IDsOriginal subjID name
: Name of the column in the mapping file that contains the original subject IDNew subjID name
: Name of the column in the mapping file that contains the new subject IDOriginal session name
: Name of the column in the mapping file that contains the original session IDNew session name
: Name of the column in the mapping file that contains the new session IDOverwrite
: If set to "on", the script will overwrite existing files in the BIDS folder
The conversion table
A conversion table will be created when running bidsify.py
. This conversion file estimates task names, processing, and other parameters to create the bidsified file name. The conversion table is then looped through, skipping split-files and already converted files. By editing the lates file, you can change deviant task names, and decide to whether to run the conversion on a specific file or not. The conversion table is saved in the conversion_logs folder as conversion_logs/<date_of_creation>_bids_conversion.tsv
. By default the latest file will be used but you can also select your own file by adding the --conversion
flag to the command line.
Header description
time_stamp
: The timestamp when the original conversion file was created.run_conversion
: Indicates whether the conversion should be executed (yes
orno
). Will automatically changed tono
after file conversion.task_flag
: Flagok
if task name matches expected task name, elsecheck
.participant_from
: The original participant ID.participant_to
: The new participant ID after mapping.session_from
: The original session ID.session_to
: The new session ID after mapping.task
: The task name associated with the file.split
: Indicates if the file is a split file.run
: If more than one occurence of a task in the same session this should be set modifided manually.datatype
: The type of data according to BIDS (e.g.,meg
,eeg
).acquisition
: Acquisition device.processing
: Pre-processing details for the data, eg. MaxFilter.raw_path
: The path to the raw data file.raw_name
: The name of the raw data file.bids_path
: The path where the BIDS-compliant file will be saved.bids_name
: The name of the BIDS-compliant file. This will be adjusted after the conversion.
Run script examples
Run the script without flags
python bidsify.py
open
: Open an existing config file (default)
- new
: Create a new config file from a default template using the dialog
- cancel
: Cancel the operation
Given all tasks in the conversion passes the checks, the script will run and create a BIDS-compliant folder structure in the specified BIDS folder. The script will also create a dataset_description.json
file and a participants.tsv
file if they do not already exist.
If task_flag
is check
. You will be prompted to edit the conversion table before continuing. This is to ensure that the task name is correct and that the file is not a split file. If you are sure that the task name is correct, you can set the task_flag to ok
and continue with the conversion.
Common changes to the conversion table are:
EmtpyRoom
. Noise recordings should include the wordempty
ornoise
in the filename. Correct spelling mistake and set task_flag took
.WorkingMemory1
. You probably needed to stop the recording in the middle of a paradigm. The first one might be namedWorkingMemory
. Change both task names toWorkingMemory
and setrun
to1
or2
depending on the order of the recordings. Change the task_flag took
and run the conversion.
Run the script with config flag
python bidsify.py --config=my_project/my_bids_config_file.json
Given all tasks in the conversion passes the checks, the script will run and create a BIDS-compliant folder structure in the specified BIDS folder.
Edit config file before running the script
python bidsify.py --config=path/to/name_of_config.json --edit
Given all tasks in the conversion passes the checks, the script will run and create a BIDS-compliant folder structure in the specified BIDS folder.
Run the script with a specific config and conversion file
python bidsify.py --config=path/to/name_of_config.json --conversion=path/to/conversion_file.csv
Given all tasks in the conversion passes the checks, the script will run and create a BIDS-compliant folder structure in the specified BIDS folder.
Run the script with a specific config and conversion file and overwrite the conversion table
python bidsify.py --config=path/to/name_of_config.json --conversion=path/to/conversion_file.csv --overwrite
Given all tasks in the conversion passes the checks, the script will run and create a BIDS-compliant folder structure in the specified BIDS folder.
Naming conventions
Although the script is written to handle various breaches of naming convensions, it is not yet water tight. The following naming conventions are recommended:
- Do not use numbers in your task name when saving your raw data.
- Do not use
_
in the file-name. Tasks namedmy_great_task
will be renamed toMyGreatTask
. - Empty room recordings should include the word
empty
ornoise
in the filename followed bybefore
orafter
to indicate if it was recorded before or after the experiment. - Resting state should be begin with
rest
, conversions for resting state names likeRS
is not yet implemented.
Special features
- EEG data will be placed in an
eeg
folder in the BIDS root directory according to BIDS specifications. However, as EEG data is collected through the TRIUX system a.fif
file will be created and the.json
sidecare will be copied to themeg
folder.