xnatcli bidsmap¶
Generates a participant/session mapping TSV for a BIDS dataset — the output of xnatcli mriconvert (with any physio already placed by xnatcli physioconvert) — at INPUT_DIR/PROJECT/. The map is later filled in by hand to relate XNAT IDs and real dates to anonymized BIDS IDs and session codenames. When -o OUTPUT_DIR is provided, it additionally applies all filled-in renames by copying the BIDS dataset to a new directory tree.
This is the "map" half of the xnatcli workflow: mriconvert/physioconvert first convert raw source data to BIDS, preserving the source data untouched; bidsmap then maps that raw/unmapped BIDS data to a separate, renamed BIDS output, so the intermediary unmapped BIDS data is preserved too. bidsmap operates on .nii.gz main files with .json/.bval/.bvec sidecars, reading its rename column and QC-exclusion columns (recommend_for_use, complete, usable, qc_rating) from mriconvert_qc.tsv (one row per .nii.gz file, so rename unambiguously targets one file). A physio _physio.tsv.gz/.json pair co-located under the same sub-*/ses-*/<datatype>/ directory rides along the copy for free (participant/session label substitution only — physioconvert already writes it under its final name, so no separate rename step is needed for it).
mriconvert_qc.tsv is named distinctly from BIDS's canonical scans.tsv (see xnatcli mriconvert); bidsmap -o promotes it to the canonical scans.tsv/scans.json in the mapped output.
Map TSV generation (always runs)¶
- Validates that
--inputexists and that the BIDS datasetINPUT_DIR/PROJECT/exists. - Scans
INPUT_DIR/PROJECT/forsub-*directories and, within each,ses-*subdirectories. - Writes
INPUT_DIR/PROJECT-<PROJECT>_bidsmap.tsvwith the columnsparticipant_id,participant_rename,session_id,session_rename. One row is emitted per(participant, session)pair, with the two*_renamecolumns left blank for later editing. Rows are sorted alphanumerically byparticipant_idthensession_id.- If the dataset has no sessions (no participant has any
ses-*subdirectory), only theparticipant_idandparticipant_renamecolumns are written, one row per participant. - If the dataset uses sessions but a particular participant has no
ses-*subdirectory, that participant is skipped with a warning.
- If the dataset has no sessions (no participant has any
- If
PROJECT-<PROJECT>_bidsmap.tsvalready exists, a fresh blank map is generated and compared to it (withpandas): any(participant_id, session_id)pairs not already present are appended, and all existing rows — including any*_renamevalues already filled in — are preserved. The merged table is re-sorted and rewritten.
Copy-with-rename (-o OUTPUT_DIR)¶
When -o is provided, after updating the map TSV the command reads back the renames and writes a fully renamed copy of the BIDS dataset to OUTPUT_DIR/PROJECT/:
PROJECT-<PROJECT>_bidsmap.tsv—participant_renameandsession_renamecolumns renamesub-*andses-*directory names and the matching labels embedded in all filenames. Blank values mean "keep the original label."mriconvert_qc.tsv— itsrenamecolumn supplies a correctedbids_name(the part aftersub-X[_ses-Y]_) for the file(s) that row describes. Sidecar files (.json,.bval,.bvec) sharing the same stem are renamed to match. Blank values mean "keep the original bids_name."
The copy also:
- QC filtering: Rows whose
recommend_for_use,complete, orusableis exactly"FALSE", or whoseqc_ratingis exactly"FAIL"or"UNCERTAIN", have their file(s) excluded from the copy (along with sidecars) and their row omitted from the output manifest. Values in any of these columns that are non-empty but do not match a valid Level frommriconvert_qc.json(e.g."false"instead of"FALSE") generate an additional warning, since they are silently ignored by the filter. - Updates
participants.tsvin the output with the renamed participant IDs, and writesscans.tsv(filename,bids_name,participant_id,session_idcolumns, among others) to reflect all renames, omits rows for QC-excluded files, and drops the columnsrenameandphysio(both have already been applied by the timebidsmap -oruns —renametobids_name,physiobyxnatcli physioconvert, which must run beforebidsmap -o). All other reviewer columns are preserved.mriconvert_qc.tsv/mriconvert_qc.jsonandphysioconvert_qc.tsv/.jsonthemselves are not copied —mriconvert_qc.tsv/.jsonare promoted toscans.tsv/.jsoninstead, andphysioconvert_qc.tsv/.jsonstay raw-tree-only bookkeeping with no promoted counterpart. - Skips
tmp_dcm2bidsandlogscratch directories. - Incremental by default: if
OUTPUT_DIR/PROJECT/already exists, files undersub-*/whose destination path already exists are treated as already mapped and left untouched — only files not yet present at the destination are copied. Root-level manifests (scans.tsv,participants.tsv,dataset_description.json, ...) are always re-copied/re-written and re-patched, since they reflect the fully merged source state. This letsbidsmap -obe re-run safely as new data lands inINPUT_DIR/PROJECT/(e.g. from furthermriconvert/physioconvertruns). - Warns loudly when new files are being mapped into a
sub-*/[ses-*/]directory that already existed at the destination before this run, since that session was already mapped and is only gaining files. - Warns loudly for any two source files that would map to the same destination path (neither is copied); all warnings are re-displayed together at the end.
For example, if the BIDS dataset lives at /data/bids/MYPROJ/, then:
xnatcli bidsmap -i /data/bids -p MYPROJwrites/data/bids/PROJECT-MYPROJ_bidsmap.tsv.- After filling in the rename columns,
xnatcli bidsmap -i /data/bids -p MYPROJ -o /data/renamedcopies the dataset to/data/renamed/MYPROJ/with all renames applied.
| Argument | Description |
|---|---|
-i, --input |
Required. Root directory holding the BIDS dataset at INPUT_DIR/PROJECT/. The map TSV is written here as PROJECT-<PROJECT>_bidsmap.tsv. |
-p, --project |
Required. Project directory name under INPUT_DIR identifying the BIDS dataset to scan. |
-o, --output |
Optional. When provided, copy the BIDS dataset to OUTPUT_DIR/PROJECT/ with all renames from the map TSV and mriconvert_qc.tsv's own rename column applied. If OUTPUT_DIR/PROJECT/ already exists, only files not already mapped there are copied (see above). |