Metadata-Version: 2.4
Name: ndpi2bids
Version: 0.1.2
Summary: Convert Hamamatsu NDPI whole-slide images to BIDS-compliant microscopy datasets
Author-email: "Raul R. Cruces" <raul.rodriguezcruces@mcgill.ca>
License: MIT License
        
        Copyright (c) March 2026 Raúl R.Cruces
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/rcruces/BIDS_ndpi
Project-URL: Repository, https://github.com/rcruces/BIDS_ndpi
Project-URL: Issues, https://github.com/rcruces/BIDS_ndpi/issues
Project-URL: Changelog, https://github.com/rcruces/BIDS_ndpi/blob/main/CHANGELOG.md
Keywords: BIDS,NDPI,whole-slide imaging,microscopy,neuroimaging,histology
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tifffile>=2023.7.10
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Dynamic: license-file

# BIDS microscopy: ndpi

---

[![Version](https://img.shields.io/github/v/tag/rcruces/BIDS_ndpi)](https://github.com/rcruces/BIDS_ndpi)
[![PyPI version](https://img.shields.io/pypi/v/ndpi2bids.svg)](https://pypi.org/project/ndpi2bids/)
[![Docker Image Version](https://img.shields.io/docker/v/micalab/ndpi2bids?color=blue&label=docker%20version)](https://hub.docker.com/r/micalab/BIDS_ndpi)
[![Docker Pulls](https://img.shields.io/docker/pulls/micalab/ndpi2bids)](https://hub.docker.com/r/micalab/BIDS_ndpi)
[![GitHub issues](https://img.shields.io/github/issues/rcruces/BIDS_ndpi?color=brightgreen)](https://github.com/rcruces/BIDS_ndpi/issues)
[![GitHub stars](https://img.shields.io/github/stars/rcruces/BIDS_ndpi.svg?style=flat&label=%E2%AD%90%EF%B8%8F%20stars&color=brightgreen)](https://github.com/rcruces/BIDS_ndpi/stargazers)

Convert whole-slide images in `.ndpi` format to [Brain Imaging Data Structure (BIDS) microscopy](https://bids-specification.readthedocs.io/en/stable/modality-specific-files/microscopy.html) compliant datasets.
https://hub.docker.com/r/micalab/ndpi2bids



## Overview

`BIDS_ndpi` automates the conversion of Hamamatsu `.ndpi` whole-slide microscopy images into a BIDS-compliant directory structure, generating the required JSON sidecars, `participants.tsv`, and metadata files along the way.

---

## Repository structure

```
BIDS_ndpi/
├── CHANGELOG.md
├── Dockerfile
├── LICENSE
├── README.md
├── boutiques
│   └── ndpi2bids.json                  # Boutique descriptor 
├── environment.yml
├── .gitignore
├── ndpi2bids
│   ├── __init__.py
│   ├── ndpi2bids.py                    # Main conversion script
│   └── templates
│       ├── dataset_description.json
│       ├── participants.json
│       ├── stain-AT8_BF.json           # Stain-specific JSON sidecar template
│       └── CITATION.cff
└── pyproject.toml
```

---

## Requirements

- Docker (recommended), **or**
- conda with the provided `environment.yml`
- pip

---

## Quick start

### With Docker

```bash
# Build the image
docker build -t bids_ndpi .

# Run conversion
docker run --rm \
  -v /path/to/ndpi/files:/input \
  -v /path/to/output:/output \
  bids_ndpi \
  python ndpi2bids/ndpi2bids.py --input /input --output /output
```

### With conda

```bash
# Create environment
conda env create -f environment.yml
conda activate bids_ndpi

# Run conversion
python ndpi2bids/ndpi2bids.py --input /path/to/ndpi --output /path/to/bids
```

---

## Usage

```bash
python ndpi2bids/ndpi2bids.py [OPTIONS]

Mandatory arguments:
  --ndpi_path  PATH   Path to raw Hamamatsu .ndpi file             [required]
  --bids       PATH   Path to the root of the BIDS dataset         [required]
  --sub        LABEL  Subject ID (e.g., PX067)                     [required]
  --stain      LABEL  Stain entity (e.g., AT8)                     [required]
  --suffix     LABEL  BIDS suffix (e.g., BF)                       [required]

Optional BIDS entities:
  --ses        LABEL  Session ID
  --sample     LABEL  Sample ID (e.g., NP24709)
  --acq        LABEL  Acquisition label
  --run        INDEX  Run index
  --chunk      LABEL  Chunk label (e.g., A3)
  --template   PATH   JSON template for metadata (overrides defaults)

Operational flags:
  --convert           Convert NDPI to OME-TIFF via bfconvert
  --force             Overwrite existing BIDS files and sidecars
  --dry_run           Print the intendet output.
```

## Example
```bash
python ndpi2bids/ndpi2bids.py \
  --ndpi_path /data/raw/PX067_AT8.ndpi \
  --bids      /data/bids \
  --sub       S001 \
  --stain     AT8 \
  --suffix    BF \
  --ses       01 \
  --sample    NP24709A1 \
  --convert
```

---

## Templates

JSON templates in `./templates/` define stain-specific metadata injected into BIDS sidecars.

| File | Purpose |
|------|---------|
| `stain-AT8_BF.json` | Sidecar template for AT8 brightfield staining |
| `participants.json` | Column definitions for `participants.tsv` |
| `participants_description.json` | Dataset-level participant metadata |
| `CITATION.cff` | Citation metadata for the dataset (authors, title, version, DOI) |

To add a new stain, copy an existing template and update the fields, then pass it via `--template`.

---

## BIDS output structure

```
output/
├── CITATION.cff
├── dataset_description.json
├── participants.tsv
├── participants.json
├── README
└── sub-<label>/
    └── ses-<label>/
        └── micr/
            ├── sub-<label>_ses-<label>_stain-AT8_BF.ome.tif
            └── sub-<label>_ses-<label>_stain-AT8_BF.json
```

---

## License

MIT License — see `LICENSE` for details.
