Week of 2026-04-20

BIDS, preprocessing & BME-X

Published

April 20, 2026

Goals for the week

  • get BME-X working on a syn7T test subject

syn7T

Aim: get the BME-X pipeline operational on the Linux HPC.

The raw data was organized with acquisition labels (acq-3T, acq-7T) rather than the session folders BME-X requires. Wrote code/restructure_bids.sh to rename all files and create proper ses-3T/ and ses-7T/ folders for all 52 subjects, plus per-subject scans.tsv files with an age_years column (BME-X needs it for age-dependent model selection).

raw_nifti/sub-002/
├── ses-3T/
│   ├── anat/
│   │   ├── sub-002_ses-3T_T1w.nii.gz
│   │   └── sub-002_ses-3T_T2w.nii.gz
│   └── sub-002_ses-3T_scans.tsv
└── ses-7T/
    ├── anat/
    │   ├── sub-002_ses-7T_T1w.nii.gz
    │   └── sub-002_ses-7T_T2w.nii.gz
    └── sub-002_ses-7T_scans.tsv

Three BME-X issues came up and got resolved:

  1. layout.get(subject="sub-002") returned 0 files — pybids expects the subject ID without the sub- prefix. Fixed by passing --subject_id 002.
  2. Age lookup was failing silently. The file actually imported at runtime (/utils/bids.py, via from utils.bids import *) had a buggy regex ^anat* instead of anat/.* for matching filenames in scans.tsv. Fixed by mounting a corrected version: -v /data/syn7T/code/bids_fixed.py:/utils/bids.py.
  3. The pipeline ran on CPU despite an available GPU. Fixed by adding --gpus all to the docker run.

Working docker command:

docker run --rm --gpus all \
  -v /data/syn7T/data/raw_nifti:/data \
  -v /data/syn7T/data/derivatives/bmex:/results \
  -v /data/syn7T/code/bids_fixed.py:/utils/bids.py \
  yuesun814/bme-x:v1.0.5 \
  --bids_root /data \
  --subject_id 002 \
  --session_id 3T \
  --output_dir /results

Output verified visually for sub-002 ses-3T T1w (QI = 0.847).

For a valid quantitative comparison (SSIM, VIF) between BME-X-enhanced 3T and actual 7T, the images need to be in the same space with matched brain extraction. Pipeline order decided:

  1. SynthStrip brain extraction on all 7T T1w → derivatives/synthstrip/
  2. ANTs SyN coregistration: 3T T1w → brain-extracted 7T T1w → derivatives/coreg/
  3. Apply transforms to 3T T2w/FLAIR
  4. BME-X on coregistered 3T images → derivatives/bmex/
  5. SSIM/VIF comparison

Scripts, all in code/:

  • restructure_bids.sh — BIDS session restructuring (per-subject)
  • batch_synthstrip_7T.sh — SynthStrip brain extraction on all 7T T1w
  • batch_coreg_3T_to_7T.sh — ANTs SyN coregistration 3T → 7T
  • batch_apply_coreg.sh — apply transforms to T2w/FLAIR
  • bids_fixed.py — patched /utils/bids.py with the corrected regex

SynthStrip finished on all 52 subjects’ 7T T1w (~10 min total), outputs in derivatives/synthstrip/. ANTs coregistration kicked off overnight (PID 3854907), monitored via:

tail -f /data/syn7T/code/logs/coreg.log

One open question on input resolution. 3T T1w voxel sizes vary a lot (0.41-1.33mm, median ~0.86mm isotropic) while 7T T1w is consistent at ~0.85mm isotropic. BME-X outputs at input resolution, so SSIM/VIF comparisons across subjects will be confounded by resolution differences. Options: (a) resample all 3T inputs to 0.85mm isotropic before the pipeline — standardizes the comparison space but upsamples some scans; or (b) accept subject-level variability and account for it analytically. Awaiting input from Irene and Mary before the full batch BME-X run.