A small Bash wrapper for converting source imaging data to NIfTI with dcm2niix.
Source data
↓
Input validation
↓
Subject/session assignment
↓
dcm2niix conversion
↓
Organized output
↓
Downstream QC or BIDS preparation
Additional workflow documentation is available in docs/workflow.md.
NIfTI_conversion_wrapper/
├── bin/
│ └── nifti-convert
├── scripts/
│ ├── helpers.sh
│ ├── validate_input.sh
│ └── convert_subject.sh
├── config/
│ └── example.env
├── docs/
│ └── workflow.md
├── .gitignore
├── LICENSE
└── README.md
- Bash 4+
dcm2niix- Standard Unix utilities
realpathor Python 3
Confirm that dcm2niix is available:
dcm2niix -hgit clone <repository-url> NIfTI_conversion_wrapper
cd NIfTI_conversion_wrapper
chmod +x bin/nifti-convert scripts/*.shOptional local configuration:
cp config/example.env config/local.envconfig/local.env is excluded from Git and should be used for machine-specific paths and settings.
./bin/nifti-convert \
--input /path/to/source/sub-001 \
--output /path/to/converted \
--subject sub-001With a session:
./bin/nifti-convert \
--input /path/to/source/sub-001/session1 \
--output /path/to/converted \
--subject sub-001 \
--session ses-01Example output:
/path/to/converted/
└── sub-001/
└── ses-01/
└── <converted files>
Inspect the conversion command without launching the converter:
./bin/nifti-convert \
--input /path/to/source/sub-001 \
--output /path/to/converted \
--subject sub-001 \
--dry-runThe wrapper:
- validates source directories and subject/session identifiers;
- refuses to write into an existing target unless
--forceis supplied; - quotes filesystem paths;
- excludes local configuration from Git;
- returns non-zero exit codes on failure;
- supports a no-write dry-run mode.
Review all paths and proposed outputs before processing research data.
Default settings are documented in config/example.env:
CONVERTER_BIN=dcm2niix
DICOM_FILENAME_PATTERN=%p_%s
DICOM_GZIP=y
DICOM_OVERWRITE=nDo not commit config/local.env, source imaging data, converted outputs, logs, credentials or machine-specific paths.
./bin/nifti-convert --helpMIT.