This tutorial will guide you through your first MEG to BIDS conversion.
- meg2bids installed (Installation Guide)
- MEG FIF files from a Neuromag/Elekta/MEGIN system
- Basic familiarity with command line
Create the following directory structure:
mkdir -p sourcedata/mystudy-sourcedata/meg
mkdir -p sourcedata/mystudy-sourcedata/configsMove your MEG data into meg folders:
sourcedata/
mystudy-sourcedata/
meg/
meg_1001/ # Subject 1
250207/ # Session date (YYMMDD)
rest1.fif
rest2.fif
visual1.fif
meg_1002/ # Subject 2
250208/
rest1.fif
visual1.fif
Folder naming:
- MEG subject folders:
meg_XXXX(where XXXX is your MEG system ID) - Session folders:
YYMMDD(date format: 250207 = Feb 7, 2025)
Create sourcedata/mystudy-sourcedata/participants_complete.tsv:
participant_id meg_id
sub-01 1001
sub-02 1002Format:
- Tab-separated values (TSV)
participant_id: BIDS subject identifier (e.g., sub-01)meg_id: MEG system ID (4 digits, matches meg_XXXX folder)
Create sourcedata/mystudy-sourcedata/configs/meg2bids.json:
{
"dataset": {
"dataset_name": "MyStudy",
"datatype": "meg"
},
"file_patterns": [
{
"pattern": "*rest*.fif",
"task": "rest",
"run_extraction": "last_digits",
"description": "Resting state"
},
{
"pattern": "*visual*.fif",
"task": "visual",
"run_extraction": "last_digits",
"description": "Visual task"
}
],
"calibration": {
"system": "triux",
"auto_detect": true
},
"derivatives": {
"pipeline_name": "maxfilter",
"maxfilter_version": "v2.2.20"
},
"options": {
"allow_maxshield": true,
"overwrite": true
}
}Key settings:
file_patterns: Match your FIF filenames to BIDS taskscalibration.system: "triux" or "vectorview"run_extraction: "last_digits" extracts run numbers from filenames
Before converting, check your configuration:
cd "your/project/directory"
python meg2bids.py --dataset mystudy --check-configThis will show you:
- ✅ How many files were found
- ✅ How each file will be matched to a task
- ✅ Subject mapping validation
⚠️ Any warnings or errors
Example output:
═══════════════════════════════════════════════════════════════════
CONFIG CHECK SUMMARY
═══════════════════════════════════════════════════════════════════
Subjects discovered: 2
Subjects mapped: 2
Sessions: 2
Files: raw=5, derivatives=0
✓ Config check PASSED - ready to convert
Test conversion on a single subject first:
python meg2bids.py --dataset mystudy --subject sub-01Alternative subject formats:
python meg2bids.py --dataset mystudy --subject 01 # Without 'sub-' prefix
python meg2bids.py --dataset mystudy --subject 1001 # Using MEG IDCheck the BIDS output:
ls rawdata/mystudy-rawdata/sub-01/ses-01/meg/You should see:
sub-01_ses-01_task-rest_run-01_meg.fif
sub-01_ses-01_task-rest_run-01_meg.json
sub-01_ses-01_task-rest_run-01_channels.tsv
sub-01_ses-01_task-rest_run-02_meg.fif
...
sub-01_ses-01_task-visual_run-01_meg.fif
...
Once you're satisfied with the test:
python meg2bids.py --dataset mystudyThis will process all subjects found in your MEG data directory.
Run the BIDS validator to ensure compliance:
python meg2bids.py --dataset mystudy --validateOr use the official BIDS validator:
bids-validator rawdata/mystudy-rawdata/
# or
npx bids-validator rawdata/mystudy-rawdata/Problem: Session folders not detected. Solution: Ensure folders are named with dates (YYMMDD format, e.g., 250207).
Problem: Ambiguous file pattern matching. Solution: Make patterns more specific in your config:
{
"pattern": "rest_*.fif", // More specific
"task": "rest"
}Problem: MEG ID not mapped to BIDS subject.
Solution: Add mapping to participants_complete.tsv:
participant_id meg_id
sub-03 1003Problem: Auto-detection can't find calibration files. Solution: Either:
- Place calibration files in session folders, or
- Specify
maxfilter_rootin config to point to MEG/maxfilter directory
- Learn about Advanced Usage
- Read the Configuration Guide for all options
- Check out Examples for more patterns
- Questions: Post on Neurostars with
meg2bidstag - Bugs: Report on GitHub Issues
- Documentation: See README