A BIDS App for ANTs-based brain segmentation with NIDM outputs.
This BIDS App provides a standardized way to run ANTs-based brain segmentation on BIDS-formatted datasets. It includes preprocessing steps, segmentation, and generates NIDM-compatible outputs for better reproducibility and sharing of results.
- BIDS-compliant input/output
- ANTs-based brain segmentation
- N4 bias field correction
- Brain extraction
- Tissue segmentation
- NIDM-compatible outputs
- Docker and Singularity support
Pre-built images will be available once the app is published to Docker Hub. For now, please build from source (see below).
git clone https://github.com/ReproNim/ants-nidm_bidsapp.git
cd ants-nidm_bidsapp
pip install -e .This BIDS App follows standard BIDS Apps practices with a Dockerfile as the primary container definition. For HPC environments without Docker, we also provide a native Singularity definition file.
# Using the setup.py helper script
python setup.py docker
# Or directly with Docker
docker build -t ants-nidm_bidsapp:latest .
# Save for transfer to HPC (if needed)
docker save ants-nidm_bidsapp:latest -o ants-nidm_bidsapp.tar# Direct build from Singularity definition file
# The --fakeroot flag is required on HPC systems without root access
apptainer build --fakeroot ants-nidm_bidsapp.sif Singularity
# Or using the setup.py helper
python setup.py singularityIf you have a Docker image (either built locally or from a tar file):
# From a saved Docker tar file
singularity build ants-nidm_bidsapp.sif docker-archive://ants-nidm_bidsapp.tar
# From local Docker daemon (requires Docker)
singularity build ants-nidm_bidsapp.sif docker-daemon://ants-nidm_bidsapp:latestants-nidm bids_dir output_dir participant --participant-label 01# Full pipeline with all options
ants-nidm bids_dir output_dir participant \
--participant-label 01 \
--session-label pre \
--modality T1w \
--prob-threshold 0.5 \
--nidm-input-dir /path/to/nidm/inputs \
--num-threads 4 \
--verboseIf you have already run ANTs segmentation and only want to generate NIDM outputs:
# Run only NIDM conversion using existing ANTs results
ants-nidm bids_dir output_dir participant \
--participant-label 01 \
--skip-ants \
--ants-input /path/to/existing/ants-seg \
--nidm-input-dir /path/to/nidm/inputsRequired:
bids_dir: Path to the BIDS datasetoutput_dir: Path where outputs will be storedanalysis_level: Level of the analysis (participantorsession)
Participant/Session Selection:
--participant-label,--participant_label: Label of the participant to analyze (with or without "sub-" prefix)--session-label,--session_label: Label of the session to analyze (with or without "ses-" prefix)
Processing Options:
--modality: Imaging modality to process (default: T1w)--method: Segmentation method -quickorfusion(default: fusion)--prob-threshold: Probability threshold for binary mask creation (default: 0.5)--num-threads: Number of threads to use for processing (default: 1)
Skip Options:
--skip-nidm: Skip NIDM conversion step (run ANTs only)--skip-ants: Skip ANTs segmentation step (run NIDM only, requires--ants-input)--skip-bids-validation: Skip BIDS validation step
Input Options (for NIDM-only mode):
--ants-input: Path to existing ANTs segmentation derivatives (required if--skip-ants)--nidm-input-dir: Directory containing existing NIDM files (optional). The app will search for files matchingsub-{id}/[ses-{session}/]sub-{id}[_ses-{session}].ttlor fallback tonidm.ttl
Other:
-v,--verbose: Print detailed logs--version: Print version and exit
The app generates the following output structure:
output_dir/
├── ants-nidm_bidsapp/ # Main BIDS App output directory
│ ├── ants-seg/ # ANTs segmentation derivatives
│ │ ├── dataset_description.json
│ │ └── sub-XX/
│ │ ├── ses-YY/ # For multi-session datasets
│ │ │ ├── anat/
│ │ │ │ ├── sub-XX_ses-YY_T1w_space-orig_dseg.nii.gz
│ │ │ │ ├── sub-XX_ses-YY_T1w_BrainSegmentation.nii.gz
│ │ │ │ └── sub-XX_ses-YY_T1w_BrainSegmentationPosteriors*.nii.gz
│ │ │ └── stats/
│ │ │ ├── sub-XX_ses-YY_antslabelstats.csv
│ │ │ └── sub-XX_ses-YY_antsbrainvols.csv
│ │ └── anat/, stats/ # For single-session datasets (no ses-)
│ └── nidm/ # NIDM outputs (flat structure)
│ ├── dataset_description.json
│ ├── sub-01_ses-baseline.ttl # NIDM files (Turtle format)
│ └── sub-02_ses-baseline.ttl
└── logs/ # Processing logs
Note: NIDM outputs use a flat file structure (all TTL files in one directory) rather than hierarchical subdirectories. This design choice simplifies file management and discovery. See CLAUDE.md for detailed rationale.
Output files include:
- Segmentation results in BIDS-derivatives format
- Probability maps for each tissue class
- Statistics files (CSV) for downstream analysis
- NIDM-compatible outputs (Turtle RDF format) for reproducibility and data sharing
The app generates NIDM-compatible outputs that can be used with NIDM tools for visualization and sharing of results. The NIDM outputs include:
- Segmentation statistics
- Brain volumes
- Tissue volumes
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this BIDS App in your research, please cite:
ANTs NIDM BIDS App. ReproNim. https://github.com/ReproNim/ants-nidm_bidsapp