Tutorial

Run MEEGqc on a BIDS dataset.

Pick a sample dataset, then run MEEGqc three ways: from the GUI, from the command line, and from a Python notebook. This page also carries the full CLI flag reference and the settings.ini section reference.

Pick a dataset

Two small BIDS datasets are provided to follow the rest of the tutorial: one MEG, one EEG. Pick either to exercise the full pipeline; use both to also exercise the multi-dataset-level reports.

MEG · MEGIN Vectorview

Logical reasoning study (MEG)

2 subjects · 1 session each · 2 tasks (deduction, induction) · ~20 min per run · 2.4 GB total.

BIDS-organised slice of the public OpenNeuro ds003483 ("Logical reasoning study") from the Cognitive and Computational Neuroscience Lab (UPM–UCM, Madrid). Recorded on an Elekta / Neuromag Vectorview 306-channel system (102 magnetometers + 204 planar gradiometers) plus dedicated ECG and EOG reference channels, at 1 kHz sampling, 50 Hz line frequency, with continuous head localisation (cHPI) on. The two subjects (sub-009, sub-012) give just enough multi-subject material to exercise both subject-level reports and the dataset-level QA / QC views; the two tasks per subject also drive the per-task trajectory plots.

MEG with dedicated cardiac and ocular reference channels (no EEG), so this dataset shows the standard MEG path: MAG + GRAD calculation, Head-motion metric enabled via cHPI, and ECG / EOG correlations computed directly from the reference channels rather than reconstructed from magnetometers.

EEG · Neuroscan 10/20

HAD-MEEG action recognition (EEG)

2 subjects · 1 session each · 1 task (action) · 8 runs per subject · ~5 min per run · 1.4 GB total.

BIDS-organised slice of the public OpenNeuro ds007353 ("HAD-MEEG") from Beijing Normal University. Recorded on a Neuroscan cap with the extended 10/20 scheme: 62 EEG + 2 dedicated EOG channels at 1 kHz sampling, 50 Hz line frequency. No ECG channel. Files are in EEGLAB .set format. Participants watched short video clips and classified each as "sports" or not using the left / right hand. The 8 runs per subject give enough event-rich material to exercise the Stimulus and EOG views.

EEG with dedicated ocular reference channels (no ECG, no MEG), so this dataset shows the EEG path: auto-detected 10/20 montage, average reference, the EEG-specific 20–100 Hz muscle band, Head-motion metric skipped (cHPI is MEG-only), EOG correlation computed directly from the two EOG channels, and the ECG metric skipped (no reference channel available).

Bring your own dataset Any BIDS-organised MEG or EEG dataset works. If you would rather start from one of the original OpenNeuro releases the two samples above were sliced from, DataLad will fetch a single subject without pulling the whole archive:
# MEG (Logical reasoning study, openneuro.ds003483)
datalad install https://github.com/OpenNeuroDatasets/ds003483.git
cd ds003483 && datalad get sub-009/

# EEG (HAD-MEEG, openneuro.ds007353)
datalad install https://github.com/OpenNeuroDatasets/ds007353.git
cd ds007353 && datalad get sub-01/

GUI walkthrough

Launch MEEGqc by double-clicking the desktop shortcut the installer created, or by running meegqc in an activated environment. The main window has two top tabs (QA/QC calculation and QA/QC plotting), plus collapsible Inputs, Output folder, and Log sections, and a Settings... button on each dataset row.

MEEGqc main window
The full MEEGqc main window: top tabs select QA/QC calculation or plotting; Inputs, Output folder, and Log are collapsible. The whole layout swaps dark / light with the header theme toggle.
  1. Add one or more BIDS datasets in the Inputs section. You can optionally detach the panel into its own window for multi-dataset runs, then click + Add dataset to browse to the BIDS root. Reorder and remove entries, and toggle Use per-dataset configuration as needed.
    Inputs section detached into its own window
    Step 1a. The empty Inputs panel, detached into its own window. Useful when you plan to queue several datasets.
    Browsing to a BIDS root
    Step 1b. Click Browse and pick the BIDS root of the dataset you want to QA.
    Inputs section with one dataset added
    Step 1c. The dataset is now queued in the Inputs panel; repeat to add more.
  2. Two separate things called "settings". Don't conflate them:
    • GUI Settings: the app's own preferences (theme, parallel-worker count limit, system info readout). Affects the GUI shell only, not the analysis.
      MEEGqc GUI Settings dialog
      GUI Settings: theme, available CPUs, total RAM. Nothing here changes a metric.
    • Analysis settings (the settings.ini editor): what actually drives the pipeline: enabled metrics, channel types, thresholds, GQI parameters, etc. Click Global settings... for a single settings.ini shared across all datasets, or Settings... on a dataset row for a per-dataset override. The dialog is a typed editor over the same settings.ini the CLI consumes (section reference at settings.ini reference below).
      Walking through the settings.ini editor: navigation, typing thresholds, applying overrides.
  3. Pick an analysis profile (optional). The Mode control switches between legacy / new / reuse / latest. For sensitivity sweeps, choose new and give the profile an explicit ID.
  4. Set parallelism with n_jobs in the QA/QC calculation tab. Each parallel job handles one subject.
  5. Run Calculation to compute QA metrics, or click Run ALL (calc + plotting) to compute and generate every report in one shot. The Log panel streams progress.
    QA/QC calculation tab
    The calculation tab: pick the channel types, tweak n_jobs, run.
  6. Switch to the QA/QC plotting tab to render reports independently. Tick the scopes you want (QA Subject, QA Group, QA Multi-dataset, QC Group, QC Multi-dataset) and click Run Plotting.
    QA/QC plotting tab
    The plotting tab selects which report scopes to render. Re-rendering does not re-run the calculation.
  7. Recompute GQI independently with Run GQI in the calculation tab. Each click writes a new attempt file with the exact thresholds used.
  8. Point at an output folder (the Output folder panel). By default MEEGqc writes derivatives under <dataset>/derivatives/Meg_QC/; the Output folder override redirects them to a custom root.
    Empty output folder panel
    Default: derivatives land inside each dataset.
    Output folder panel with custom root
    Override: redirect every dataset's derivatives to a shared root.

CLI walkthrough

For scripted runs and batch processing. The CLI exposes four entry points; the GUI calls into the same dispatchers under the hood.

Step 0. Export an editable settings.ini
mkdir -p ./config
get-meegqc-config --target_directory ./config --filename settings.ini
Step 1. Calculation (compute the QA metrics)
run-meegqc \
  --inputdata /path/to/bids_dataset \
  --config ./config/settings.ini \
  --n_jobs 4
Step 2. Plotting (render the reports)
# Subject + dataset-level QA from one dataset
run-meegqc-plotting \
  --inputdata /path/to/bids_dataset \
  --qa-subject --qa-group

# Cross-dataset comparison; --njobs (no underscore) for plotting
run-meegqc-plotting \
  --inputdata /path/ds1 /path/ds2 \
  --qa-multisample --qc-multisample --njobs 4
Step 3. (Optional) GQI recomputation
globalqualityindex \
  --inputdata /path/to/bids_dataset \
  --analysis_mode reuse \
  --analysis_id qa_pass_01

# Then re-render the QC Group report against the new attempt
run-meegqc-plotting \
  --inputdata /path/to/bids_dataset \
  --qc-group --attempt 2
One-shot: compute + plot in one command
run-meegqc \
  --inputdata /path/ds1 /path/ds2 \
  --config ./config/settings.ini \
  --run-all --all

Multi-dataset with per-dataset overrides

run-meegqc \
  --inputdata /path/ds1 /path/ds2 \
  --subs_per_dataset \
    "/path/ds1::001,002,003" \
    "/path/ds2::all" \
  --config_per_dataset \
    "/path/ds1::./config/ds1.ini" \
    "/path/ds2::./config/ds2.ini" \
  --n_jobs 4

CLI reference

Every flag, grouped by command. Use --help on any command for the runtime version.

run-meegqc (calculation)

FlagTypeDescription
--inputdatapath(s)One or more BIDS dataset roots.
--configpathsettings.ini file shared across all datasets.
--config_per_datasetlistPer-dataset config overrides as "<path>::<config>" pairs.
--subslistSubject IDs to process (default: all).
--subs_per_datasetlistPer-dataset subject lists as "<path>::<ids>" pairs.
--n_jobsintParallel subject workers.
--derivatives_outputpathWrite derivatives to a custom root instead of <dataset>/derivatives/Meg_QC/.
--analysis_modeenumlegacy | new | reuse | latest.
--analysis_idstrProfile identifier. Required with reuse; recommended with new.
--existing_config_policyenumprovided | latest_saved | fail when a settings file already exists in the profile.
--processed_subjects_policyenumskip | rerun | fail for subjects already processed.
--run-allflagAfter calculation, automatically run plotting.
--all / --qa-all / --qc-allflagWith --run-all, choose which plotting scopes to render.
--qa-subject / --qa-group / --qa-multisampleflagSelective QA scopes (with --run-all).
--qc-group / --qc-multisampleflagSelective QC scopes (with --run-all).

run-meegqc-plotting (reports)

FlagTypeDescription
--inputdatapath(s)One or more BIDS dataset roots.
--qa-subjectflagRender subject-level QA reports.
--qa-groupflagRender dataset-level QA report.
--qa-multisampleflagRender multi-dataset-level QA report (≥ 2 datasets).
--qc-groupflagRender dataset-level QC report.
--qc-multisampleflagRender multi-dataset-level QC report (≥ 2 datasets).
--qa-all / --qc-all / --allflagConvenience presets.
--attemptintQC Group / QC Multi-dataset: GQI attempt to render. Defaults to the latest.
--input_tsvpathQC Group: explicit GQI TSV path.
--analysis_mode / --analysis_idProfile selection (same semantics as run-meegqc).
--njobsintParallel subject workers (note: no underscore on the plotting command).

globalqualityindex (GQI recomputation)

FlagTypeDescription
--inputdatapath(s)One or more BIDS dataset roots.
--analysis_mode / --analysis_idProfile selection.

get-meegqc-config (export settings.ini)

FlagTypeDescription
--target_directorypathWhere to write the file.
--filenamestrOutput filename (default settings.ini).

Python API

The dispatchers in meg_qc.test are the same backend the GUI and CLI call. Import them directly to wire MEEGqc into a notebook, a Snakemake workflow, or any larger Python pipeline.

Setup: export an editable config (once)
mkdir -p ./config
get-meegqc-config --target_directory ./config --filename settings.ini
Resolve the internal config path
from pathlib import Path
import meg_qc

pkg_root     = Path(meg_qc.__file__).resolve().parent
internal_cfg = str(pkg_root / "settings" / "settings_internal.ini")
Calculation
from meg_qc.test import (
    run_calculation_dispatch,
    run_plotting_dispatch,
    run_gqi_dispatch,
    run_all_dispatch,
)

run_calculation_dispatch(
    dataset_paths=["/path/ds1", "/path/ds2"],
    config_file_path="./config/settings.ini",
    internal_config_file_path=internal_cfg,
    sub_list="all",
    n_jobs=4,
    analysis_mode="new",
    analysis_id="qa_pass_01",
    existing_config_policy="provided",
    processed_subjects_policy="skip",
)
Plotting
run_plotting_dispatch(
    dataset_paths=["/path/ds1", "/path/ds2"],
    qa_subject=True,
    qa_group=True,
    qa_multisample=True,
    qc_group=True,
    qc_multisample=True,
    analysis_mode="reuse",
    analysis_id="qa_pass_01",
    njobs=4,
)
GQI recomputation
run_gqi_dispatch(
    dataset_paths=["/path/ds1", "/path/ds2"],
    default_config_file_path="./config/settings.ini",
    analysis_mode="reuse",
    analysis_id="qa_pass_01",
)
Run ALL orchestration
run_all_dispatch(
    dataset_paths=["/path/ds1", "/path/ds2"],
    config_file_path="./config/settings.ini",
    internal_config_file_path=internal_cfg,
    sub_list="all",
    calc_n_jobs=4,
    plot_njobs=4,
    analysis_mode="new",
    analysis_id="qa_pass_02",
    qa_subject=True,
    qa_group=True,
    qa_multisample=True,
    qc_group=True,
    qc_multisample=True,
)
Notes
  • analysis_mode='reuse' requires analysis_id.
  • Multi-dataset modes (qa_multisample, qc_multisample) need at least two datasets.
  • The dispatchers print to standard stdout / stderr, so you can capture output with contextlib.redirect_stdout in a notebook.

settings.ini reference

Every behaviour knob in MEEGqc is controlled through settings.ini. Export the defaults with get-meegqc-config, edit the copy, and pass it via --config or load it in the GUI.

[GENERAL]

VariableDefaultTypeDescription
ch_typesmag, grad, eegstring listChannel types to process. mag, grad for MEG, eeg for EEG, all three for simultaneous.
STDTrueboolEnable the Standard Deviation metric.
PSDTrueboolEnable Power Spectral Density.
PTP_manualTrueboolEnable manual Peak-to-Peak.
ECGTrueboolEnable ECG correlation.
EOGTrueboolEnable EOG correlation.
HeadFalseboolEnable head-motion metric. Requires cHPI; MEG only.
MuscleTrueboolEnable the muscle metric.
data_crop_tmin0floatStart crop time (s).
data_crop_tmaxblankfloat / blankEnd crop time. Blank uses the full recording.

[Filtering]

VariableDefaultTypeDescription
apply_filteringTrueboolEnable the filtering stage.
downsample_to_hz1000float / int / FalseTarget sampling rate. Must be ≥ 5x h_freq. Set False to skip.
l_freq0floatHigh-pass edge (Hz).
h_freq140floatLow-pass edge (Hz).
methodiirstringFilter method.

[Epoching]

VariableDefaultTypeDescription
event_dur0.002floatMinimum trigger pulse duration (only used when no BIDS _events.tsv is found).
epoch_tmin-0.2floatEpoch start relative to event (s).
epoch_tmax1floatEpoch end relative to event (s).
stim_channelblankstringExplicit stim channel; blank for auto detection.
preferred_stim_channelssee configstring listCombined trigger channels (STI101 / STI 014 / UPPT00x / STATUS).
noisy_stim_channelsSTI301, STI 301string listStim channels excluded from auto detection.
event_repeatedmergestringDuplicate-event handling: error / drop / merge.
use_fixed_length_epochsTrueboolFallback to fixed-length epochs when no events are available.
fixed_epoch_duration2.0floatFixed-length epoch size (s).
fixed_epoch_overlap0.0floatOverlap between consecutive fixed epochs (s).

[STD]

VariableDefaultTypeDescription
std_lvl1intStd-from-mean cutoff.
allow_percent_noisy_flat_epochs70intMax % of epochs a channel can be noisy / flat before flagging.
noisy_channel_multiplier1.2floatHigher = fewer noisy flags.
flat_multiplier0.5floatFlat-channel multiplier.

[PSD]

VariableDefaultTypeDescription
freq_min0.5floatLower edge (Hz).
freq_max140floatUpper edge (Hz).
psd_step_size1floatFrequency resolution (Hz).

[PTP_manual]

VariableDefaultTypeDescription
numba_versionTrueboolUse the Numba-accelerated path.
max_pair_dist_sec20floatMaximum pair distance (s).
ptp_thresh_lvl10intHigher = more peaks detected.
allow_percent_noisy_flat_epochs70intSame semantics as in [STD].
std_lvl1intStd-from-mean cutoff.
noisy_channel_multiplier1.2float
flat_multiplier0.5float

[ECG]

VariableDefaultTypeDescription
drop_bad_chTrueboolDrop a bad ECG channel and reconstruct from magnetometers.
n_breaks_bursts_allowed_per_10min3intAllowed breaks per 10 minutes.
allowed_range_of_peaks_stds0.14floatPeak-height variability tolerance.
height_multiplier0.6floatHigher = fewer peaks.
norm_lvl1intThreshold scaling factor.
gaussian_sigma4intGaussian smoothing kernel sigma.
thresh_lvl_peakfinder5int
fixed_channel_namesblankstring listExplicit ECG channel names.

[EOG]

VariableDefaultTypeDescription
n_breaks_bursts_allowed_per_10min3int
allowed_range_of_peaks_stds0.15float
norm_lvl1int
gaussian_sigma6intLarger than ECG (EOG is noisier).
thresh_lvl_peakfinder3int
fixed_channel_namesblankstring listExplicit EOG channel names.

[Head_movement]

Reserved section. The block exists in the default settings.ini but has no keys; head motion is toggled by the top-level Head flag in [GENERAL].

[Muscle]

VariableDefaultTypeDescription
muscle_freqs110, 140int pairMEG muscle band (Hz).
muscle_freqs_eeg20, 100int pairEEG muscle band (Hz).
threshold_muscle5intZ-score threshold.
min_length_good0.2floatMin "good" gap between events (s).
min_distance_between_different_muscle_events1floatMin separation between distinct events (s).

[EEG]

VariableDefaultTypeDescription
reference_methodaveragestringaverage, REST, or none.
montageautostringauto tries 10-20 / 10-10 / 10-05 with reference-suffix stripping. Or pass a builtin name (standard_1020, biosemi64, etc.).

[GlobalQualityIndex]

The GQI math is documented on the metrics page.

VariableDefaultTypeDescription
compute_gqiTrueboolEnable GQI computation.
include_ecg_eogTrueboolInclude the correlation term.
bad_ch_start0int% bad channels with no penalty.
bad_ch_end100int% bad channels yielding max penalty.
bad_ch_weight35intChannel variability weight.
correlation_start0int% correlated channels with no penalty.
correlation_end100int% correlated channels yielding max penalty.
correlation_weight30intECG / EOG correlation weight.
muscle_start0floatMuscle ratio with no penalty.
muscle_end0.0001floatMuscle ratio yielding max penalty.
muscle_weight15intMuscle weight.
psd_noise_start0int% PSD noise with no penalty.
psd_noise_end100int% PSD noise yielding max penalty.
psd_noise_weight20intPSD weight.

Next: the reports reference or the metrics + GQI page.