Skip to content

Commit b5bec73

Browse files
authored
Merge pull request #1 from yibeichan/main
ANTs BIDS App Implementation
2 parents 5da9aab + 545cd87 commit b5bec73

22 files changed

+3620
-1
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.9", "3.10", "3.11", "3.12"]
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -e .
26+
pip install pytest pytest-cov
27+
- name: Run tests
28+
run: |
29+
pytest --cov=src tests/

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ __pycache__/
33
*.py[cod]
44
*$py.class
55

6+
data/
67
# C extensions
78
*.so
89

@@ -31,6 +32,7 @@ MANIFEST
3132
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3233
*.manifest
3334
*.spec
35+
AGENTS.md
3436

3537
# Installer logs
3638
pip-log.txt
@@ -172,3 +174,13 @@ cython_debug/
172174

173175
# PyPI configuration file
174176
.pypirc
177+
178+
# Claude Code guidance file
179+
CLAUDE.md
180+
181+
# Container images
182+
*.sif
183+
*.simg
184+
185+
# Internal documentation and team files
186+
internal/

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "src/ants_seg_to_nidm"]
2+
path = src/ants_seg_to_nidm
3+
url = https://github.com/yibeichan/ants_seg_to_nidm.git
4+
branch = feature/link-ants-acquisition

Dockerfile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
FROM ubuntu:22.04
2+
3+
# Set non-interactive frontend for apt-get
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
# Install system dependencies
7+
RUN apt-get update && \
8+
apt-get install -y --no-install-recommends \
9+
python3 \
10+
python3-pip \
11+
python3-dev \
12+
wget \
13+
curl \
14+
unzip \
15+
git \
16+
gcc \
17+
g++ \
18+
cmake \
19+
build-essential \
20+
libgomp1 \
21+
ca-certificates && \
22+
apt-get clean && \
23+
rm -rf /var/lib/apt/lists/*
24+
25+
# Install Python packages
26+
RUN pip3 install --no-cache-dir \
27+
numpy \
28+
nibabel \
29+
pandas \
30+
pybids \
31+
nipype \
32+
antspyx
33+
34+
# Create directory for templates with proper permissions
35+
RUN mkdir -p /opt/data && chmod 755 /opt/data
36+
37+
# Download OASIS templates and atlases
38+
WORKDIR /opt/data
39+
40+
# Download OASIS-30 Atropos template
41+
RUN wget -q https://files.osf.io/v1/resources/ej52r/providers/osfstorage/5e8251d20f59a8001ae648c3/?zip= \
42+
-O OASIS-30_Atropos_template.zip && \
43+
unzip -q OASIS-30_Atropos_template.zip && \
44+
rm OASIS-30_Atropos_template.zip && \
45+
chmod -R 755 /opt/data/OASIS-30_Atropos_template
46+
47+
# Download OASIS-TRT-20 atlases for joint label fusion
48+
RUN wget -q https://files.osf.io/v1/resources/ej52r/providers/osfstorage/5e825d0f2301130197e6a15e/?zip= \
49+
-O OASIS-TRT-20.zip && \
50+
unzip -q OASIS-TRT-20.zip && \
51+
rm OASIS-TRT-20.zip && \
52+
chmod -R 755 /opt/data/OASIS-TRT-20_*
53+
54+
# Create app directory with proper permissions
55+
RUN mkdir -p /app && chmod 755 /app
56+
WORKDIR /app
57+
58+
# Copy application code
59+
COPY setup.py /app/
60+
COPY src/ /app/src/
61+
COPY README.md /app/
62+
63+
# Install the application and NIDM conversion toolkit
64+
RUN pip3 install -e . && \
65+
pip3 install -e src/ants_seg_to_nidm && \
66+
pip3 install -r src/ants_seg_to_nidm/requirements.txt && \
67+
chmod -R 755 /app
68+
69+
# Set environment variables
70+
ENV ANTSPATH=/usr/local/bin
71+
ENV PATH=/usr/local/bin:$PATH
72+
ENV ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1
73+
74+
# Create work directory for temporary files with world-writable permissions
75+
RUN mkdir -p /work && chmod 777 /work
76+
ENV TMPDIR=/work
77+
ENV TEMP=/work
78+
ENV TMP=/work
79+
80+
# Create entrypoint script with proper permissions
81+
RUN echo '#!/bin/bash\nexec ants-bidsapp "$@"' > /entrypoint.sh && \
82+
chmod 755 /entrypoint.sh
83+
84+
# Ensure all installed binaries are executable
85+
RUN chmod -R 755 /usr/local/bin || true
86+
87+
# Set a non-root user (but allow running as any UID/GID)
88+
# This helps with permission issues in HPC environments
89+
RUN echo "ALL ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
90+
chmod 666 /etc/passwd /etc/group || true
91+
92+
ENTRYPOINT ["/entrypoint.sh"]

README.md

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,138 @@
1-
# ants_bidsapp
1+
# ANTs BIDS App
2+
3+
A BIDS App for ANTs-based brain segmentation with NIDM outputs.
4+
5+
## Overview
6+
7+
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.
8+
9+
## Features
10+
11+
- BIDS-compliant input/output
12+
- ANTs-based brain segmentation
13+
- N4 bias field correction
14+
- Brain extraction
15+
- Tissue segmentation
16+
- NIDM-compatible outputs
17+
- Docker and Singularity support
18+
19+
## Installation
20+
21+
### Container Images
22+
23+
Pre-built images will be available once the app is published to Docker Hub. For now, please build from source (see below).
24+
25+
### From Source
26+
27+
```bash
28+
git clone https://github.com/ReproNim/ants-bidsapp.git
29+
cd ants-bidsapp
30+
pip install -e .
31+
```
32+
33+
### Building Containers from Source
34+
35+
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.
36+
37+
#### Building with Docker (on systems with Docker installed)
38+
39+
```bash
40+
# Using the setup.py helper script
41+
python setup.py docker
42+
43+
# Or directly with Docker
44+
docker build -t ants-bidsapp:latest .
45+
46+
# Save for transfer to HPC (if needed)
47+
docker save ants-bidsapp:latest -o ants-bidsapp.tar
48+
```
49+
50+
#### Building with Singularity/Apptainer (for HPC environments)
51+
52+
```bash
53+
# Direct build from Singularity definition file
54+
# The --fakeroot flag is required on HPC systems without root access
55+
apptainer build --fakeroot ants-bidsapp.sif Singularity
56+
57+
# Or using the setup.py helper
58+
python setup.py singularity
59+
```
60+
61+
#### Converting Docker to Singularity
62+
63+
If you have a Docker image (either built locally or from a tar file):
64+
65+
```bash
66+
# From a saved Docker tar file
67+
singularity build ants-bidsapp.sif docker-archive://ants-bidsapp.tar
68+
69+
# From local Docker daemon (requires Docker)
70+
singularity build ants-bidsapp.sif docker-daemon://ants-bidsapp:latest
71+
```
72+
73+
## Usage
74+
75+
### Basic Usage
76+
77+
```bash
78+
ants-bidsapp bids_dir output_dir participant --participant-label 01
79+
```
80+
81+
### Advanced Options
82+
83+
```bash
84+
ants-bidsapp bids_dir output_dir participant \
85+
--participant-label 01 \
86+
--session-label pre \
87+
--modality T1w \
88+
--prob-threshold 0.5 \
89+
--num-threads 4 \
90+
--verbose
91+
```
92+
93+
### Command-line Arguments
94+
95+
- `bids_dir`: Path to the BIDS dataset
96+
- `output_dir`: Path where outputs will be stored
97+
- `analysis_level`: Level of the analysis (participant)
98+
- `--participant-label`: Label(s) of the participant(s) to analyze
99+
- `--session-label`: Label(s) of the session(s) to analyze
100+
- `--modality`: Imaging modality to process (default: T1w)
101+
- `--prob-threshold`: Probability threshold for binary mask creation (default: 0.5)
102+
- `--priors`: Paths to prior probability maps for segmentation
103+
- `--skip-nidm`: Skip NIDM conversion step
104+
- `--num-threads`: Number of threads to use for processing (default: 1)
105+
- `--verbose`: Print detailed logs
106+
107+
## Outputs
108+
109+
The app generates the following outputs:
110+
111+
- Segmentation results in BIDS-compatible format
112+
- Probability maps for each tissue class
113+
- Binary masks for each tissue class
114+
- NIDM-compatible outputs for reproducibility
115+
116+
## NIDM Outputs
117+
118+
The app generates NIDM-compatible outputs that can be used with NIDM tools for visualization and sharing of results. The NIDM outputs include:
119+
120+
- Segmentation statistics
121+
- Brain volumes
122+
- Tissue volumes
123+
124+
## Contributing
125+
126+
Contributions are welcome! Please feel free to submit a Pull Request.
127+
128+
## License
129+
130+
This project is licensed under the MIT License - see the LICENSE file for details.
131+
132+
## Citation
133+
134+
If you use this BIDS App in your research, please cite:
135+
136+
```
137+
ANTs BIDS App. ReproNim. https://github.com/ReproNim/ants-bidsapp
138+
```

0 commit comments

Comments
 (0)