Description
When working with files that have square brackets [] in their names, dcm2bids appears to incorrectly handle these files. While dcm2niix successfully converts DICOM files with [], dcm2bids fails to mv .nii.gz with [] to the final BIDS directory structure.
Annoyingly, files with [] are detected by dcm2bids and appear in the log as being paired, but they are not correctly moved to the final BIDS directory. Even worse, it won't create the sub- directory if all filenames have [].
$ tree tmp_dcm2bids/sub-brackets
tmp_dcm2bids/sub-brackets
├── 007_07-anat_T1w_anat_T1w_20210731093046.json
├── 007_07-anat_T1w_anat_T1w_20210731093046.nii.gz
├── 007_07-anat_T1w_anat_T1w_[2021_2-110-XD]0731093046.json
└── 007_07-anat_T1w_anat_T1w_[2021_2-110-XD]0731093046.nii.gz
0 directories, 4 files
vs
$ dcm2bids -c dcm2bids-v3_config.json -p brackets -d X/07-anat_T1w/
INFO | --- dcm2bids start ---
INFO | Running the following command: $HOME/.conda/envs/dcm2bids3/bin/dcm2bids -c dcm2bids-v3_config.json -p brackets -d X/07-anat_T1w/
INFO | OS version: Linux-5.15.0-136-generic-x86_64-with-glibc2.35
INFO | Python version: 3.12.8 | packaged by Anaconda, Inc. | (main, Dec 11 2024, 16:31:09) [GCC 11.2.0]
INFO | dcm2bids version: 3.2.0
INFO | dcm2niix version: v1.0.20240202
INFO | Checking for software update
INFO | Currently using the latest version of dcm2bids.
WARNING | A newer version exists for dcm2niix: v1.0.20241211
WARNING | You should update it -> https://github.com/rordenlab/dcm2niix.
INFO | participant: sub-brackets
INFO | config: dcm2bids-v3_config.json
INFO | BIDS directory: $HOME
INFO | Auto extract entities: False
INFO | Reorder entities: True
INFO | Validate BIDS: False
INFO | SIDECAR PAIRING
INFO | sub-brackets_T1w <- 007_07-anat_T1w_anat_T1w_20210731093046
INFO | sub-brackets_T1w <- 007_07-anat_T1w_anat_T1w_[2021_2-110-XD]0731093046
INFO | sub-brackets/anat/sub-brackets_T1w has 2 runs
INFO | Adding run information to the acquisition
INFO | Moving acquisitions into BIDS folder "$HOME/sub-brackets".
INFO | Logs saved in $HOME/tmp_dcm2bids/log/sub-brackets_20250424-090736.log
INFO | --- dcm2bids end ---
$ tree sub-brackets
sub-brackets
└── anat
├── sub-brackets_run-01_T1w.json
└── sub-brackets_run-01_T1w.nii.gz
Note that only one run appears in the final output, despite two runs being detected during processing. I copied/pasted the same scan, only difference is the filename with [].
Possible Cause
Probably related to how dcm2bids handles special characters in filenames when moving files from the tmp dir to the final BIDS dir. [] and potentially others (I havent tested other chars) have special meaning in many shell/regex commands and may not be properly escaped during file operations.
Workaround
If you encounter this issue, add and modify the dcm2niixOptions in your config to rename the files without special characters. You'll likely want to modify the -f option which is for filename.
Tagging @ericearl as he discovered it!
Description
When working with files that have square brackets
[]in their names, dcm2bids appears to incorrectly handle these files. While dcm2niix successfully converts DICOM files with [], dcm2bids fails to mv .nii.gz with[]to the final BIDS directory structure.Annoyingly, files with [] are detected by dcm2bids and appear in the log as being paired, but they are not correctly moved to the final BIDS directory. Even worse, it won't create the
sub-directory if all filenames have[].vs
Note that only one run appears in the final output, despite two runs being detected during processing. I copied/pasted the same scan, only difference is the filename with [].
Possible Cause
Probably related to how dcm2bids handles special characters in filenames when moving files from the tmp dir to the final BIDS dir. [] and potentially others (I havent tested other chars) have special meaning in many shell/regex commands and may not be properly escaped during file operations.
Workaround
If you encounter this issue, add and modify the dcm2niixOptions in your config to rename the files without special characters. You'll likely want to modify the
-foption which is for filename.Tagging @ericearl as he discovered it!