Metadata-Version: 2.4
Name: histox
Version: 0.3.0
Summary: Deep learning tools for digital histology
Home-page: https://github.com/leicaohmu/histox
Author: Lei Cao
Author-email: caolei@hrbmu.edu.cn
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: THIRD_PARTY_NOTICES.md
License-File: licenses/MIT-HistoBistro.txt
License-File: licenses/MIT-StainTools.txt
License-File: licenses/MIT-Transformer-Explainability.txt
Requires-Dist: gast>=0.3.3
Requires-Dist: scipy
Requires-Dist: scikit-learn
Requires-Dist: matplotlib>=3.2
Requires-Dist: imageio
Requires-Dist: opencv-python-headless
Requires-Dist: shapely
Requires-Dist: umap-learn
Requires-Dist: seaborn<0.14
Requires-Dist: pandas
Requires-Dist: pyvips
Requires-Dist: fpdf2
Requires-Dist: scikit-image
Requires-Dist: tqdm
Requires-Dist: click
Requires-Dist: protobuf<3.21
Requires-Dist: tensorboard
Requires-Dist: crc32c
Requires-Dist: numpy
Requires-Dist: tabulate
Requires-Dist: rasterio
Requires-Dist: rich
Requires-Dist: pillow>=6.0.0
Requires-Dist: saliency
Requires-Dist: requests
Requires-Dist: parameterized
Requires-Dist: zarr<3,>=2.16
Requires-Dist: gdown
Requires-Dist: triangle
Requires-Dist: pyarrow
Provides-Extra: torch
Requires-Dist: torch; extra == "torch"
Requires-Dist: torchvision; extra == "torch"
Requires-Dist: pretrainedmodels; extra == "torch"
Requires-Dist: six; extra == "torch"
Requires-Dist: cellpose<2.2; extra == "torch"
Requires-Dist: fastai; extra == "torch"
Requires-Dist: pytorch-lightning; extra == "torch"
Requires-Dist: timm; extra == "torch"
Requires-Dist: segmentation-models-pytorch; extra == "torch"
Provides-Extra: hpo
Requires-Dist: smac==1.4.0; extra == "hpo"
Requires-Dist: ConfigSpace; extra == "hpo"
Provides-Extra: studio
Requires-Dist: imgui>=2.0.0; extra == "studio"
Requires-Dist: pyopengl; extra == "studio"
Requires-Dist: glfw; extra == "studio"
Requires-Dist: pyperclip; extra == "studio"
Provides-Extra: huggingface
Requires-Dist: transformers<5,>=4.32; extra == "huggingface"
Requires-Dist: safetensors>=0.4; extra == "huggingface"
Provides-Extra: tf
Requires-Dist: tensorflow<2.16,>=2.12; extra == "tf"
Requires-Dist: tensorflow_probability<0.24,>=0.20; extra == "tf"
Requires-Dist: tensorflow_datasets<4.10,>=4.9; extra == "tf"
Provides-Extra: cucim
Requires-Dist: cucim; extra == "cucim"
Provides-Extra: cucim-cuda12
Requires-Dist: cucim; extra == "cucim-cuda12"
Requires-Dist: cupy-cuda12x; extra == "cucim-cuda12"
Provides-Extra: cucim-cuda11
Requires-Dist: cucim; extra == "cucim-cuda11"
Requires-Dist: cupy-cuda11x; extra == "cucim-cuda11"
Provides-Extra: dicom
Requires-Dist: wsidicom<0.37,>=0.36.1; extra == "dicom"
Provides-Extra: noncommercial
Requires-Dist: slideflow-noncommercial; extra == "noncommercial"
Provides-Extra: gpl
Requires-Dist: slideflow-gpl; extra == "gpl"
Provides-Extra: all
Requires-Dist: slideflow-noncommercial; extra == "all"
Requires-Dist: slideflow-gpl; extra == "all"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# HistoX

[![Package checks](https://github.com/leicaohmu/histox/actions/workflows/python-app.yml/badge.svg)](https://github.com/leicaohmu/histox/actions/workflows/python-app.yml)
[![PyPI](https://img.shields.io/pypi/v/histox)](https://pypi.org/project/histox/)
![Python](https://img.shields.io/badge/Python-%3E%3D3.7-blue)
[![License](https://img.shields.io/badge/License-Apache--2.0-green)](LICENSE)

HistoX is an open-source Python library for computational pathology. It is a
modified fork of [Slideflow](https://github.com/slideflow/slideflow) and is
being developed into a PyTorch-first toolkit for whole-slide image (WSI)
processing, model training, evaluation, and multimodal pathology research.

> [!IMPORTANT]
> HistoX is under active development. Version `0.2.x` retains substantial
> upstream-compatible behavior, while its maintained imports, entry points,
> examples, and documentation use the `histox` namespace. Treat the current
> public API as pre-stable and pin the package version in reproducible projects.

## What works today

The current package provides a working baseline for:

- project and cohort configuration;
- WSI reading, tissue quality control, and tile extraction;
- stain normalization;
- PyTorch and legacy TensorFlow model backends;
- supervised training and multiple-instance learning workflows;
- feature extraction, heatmaps, mosaics, and the HistoX Studio viewer.

PyTorch is selected automatically when it is installed and is the target for
new model and task development. TensorFlow remains available for compatibility
with inherited workflows, but new HistoX capabilities will be designed for
PyTorch first. See [ROADMAP.md](ROADMAP.md) for the planned interfaces and
milestones.

## Requirements

- Package metadata currently declares Python `>=3.7`.
- Distribution builds are currently checked in CI with Python 3.9.
- WSI reading requires a working libvips installation, unless a compatible
  cuCIM backend is used.
- Training requires at least one deep-learning backend.

The Python-version declaration is not yet a full compatibility guarantee.
Python 3.9 is the current development and CI baseline.

## Installation

Install the published package with the PyTorch extras:

```bash
python -m pip install "histox[torch]"
```

To install the current GitHub version without keeping a source checkout:

```bash
python -m pip install "histox[torch] @ git+https://github.com/leicaohmu/histox.git@master"
```

Editable installation is intended for contributors. Use a checkout directory
whose name is distinct from the import package:

```bash
git clone https://github.com/leicaohmu/histox.git histox-src
cd histox-src
python -m pip install -e ".[torch]"
```

Using `histox-src` avoids an outer directory named `histox` shadowing the
installed package when Python is started from the checkout's parent directory.

Optional installation groups are retained for existing workflows:

| Command | Purpose |
| --- | --- |
| `python -m pip install histox` | Base dependency set; install a backend separately |
| `python -m pip install "histox[torch]"` | PyTorch backend and related tools |
| `python -m pip install "histox[tf]"` | Legacy TensorFlow compatibility |
| `python -m pip install "histox[torch,cucim]"` | PyTorch plus cuCIM; manage CuPy separately |
| `python -m pip install "histox[torch,cucim-cuda12]"` | PyTorch, cuCIM, and CUDA 12 CuPy |
| `python -m pip install "histox[torch,cucim-cuda11]"` | PyTorch, cuCIM, and CUDA 11 CuPy |

Do not install multiple `cupy-*` variants in the same environment. Match the
CuPy package to the CUDA runtime reported by `nvidia-smi`.

### Verify the installation

```python
import histox as hx

print("HistoX:", hx.__version__)
print("package location:", hx.__file__)
print("model backend:", hx.backend())
print("slide backend:", hx.slide_backend())
```

The package location must point to a real ``histox/__init__.py`` file. With
PyTorch installed, `hx.backend()` should report `torch` unless `HX_BACKEND`
explicitly selects another supported backend.

## Minimal project workflow

HistoX uses an annotation table to connect patient labels to slide names. A
minimal table looks like this:

```csv
patient,slide,label
P001,S001,tumor
P002,S002,normal
```

Create a project and configure a PyTorch model:

```python
from pathlib import Path

import histox as hx

workspace = Path("/path/to/workspace")

project = hx.create_project(
    root=str(workspace / "project"),
    name="my-cohort",
    annotations=str(workspace / "annotations.csv"),
    slides=str(workspace / "slides"),
    tfrecords=str(workspace / "tfrecords"),
)

params = hx.ModelParams(
    tile_px=256,
    tile_um="20x",
    model="resnet50",
    epochs=1,
)
```

Once the slide files named by the annotation table are available, extraction
and training use the following public methods:

```python
project.extract_tiles(
    tile_px=256,
    tile_um="20x",
    qc="otsu",
    normalizer="macenko",
)

results = project.train("label", params=params)
```

Tile extraction and training are intentionally separate from project creation:
they require real WSI files, sufficient local storage, and an environment
configured for the selected slide and model backends.

## Data and storage policy

HistoX does not intend to bundle public WSI datasets in the Python wheel, keep
them in the Git repository, or operate the laboratory server as a public data
mirror. Dataset providers remain the source of record.

The `histox.data` interface provides small, versioned registry records,
read-only download plans, and verified direct downloads for open HTTP(S)
assets. Those records describe:

- the authoritative provider and dataset identifier;
- access and license requirements;
- file manifests and provider checksums when available;
- supported labels, cohorts, and HistoX adapters;
- the local cache layout and provenance metadata.

```python
import histox as hx

record = hx.data.get_dataset("histox-metadata-fixture")
plan = hx.data.plan_download(record, path="/shared/pathology-data")
print(plan.destination)
```

A4b1 ships one metadata-only fixture so registry lookup and cache planning can
be tested without bundling pathology data. A4b2 adds explicit direct downloads,
HTTP Range resumption, atomic file publication, checksum enforcement, and a
machine-readable local provenance record. Authentication and provider-specific
clients remain subsequent A4b work.

Downloads will go directly from the provider to storage controlled by the
user. The cache resolution order is:

1. `HISTOX_CACHE_DIR`, when set;
2. `$XDG_CACHE_HOME/histox`, when `XDG_CACHE_HOME` is set;
3. `~/.cache/histox` otherwise.

Controlled-access datasets will continue to require the user's own provider
account, approvals, and credentials. The registry and planning contract do not
bypass provider access controls.

## Core modules

| Module | Current responsibility |
| --- | --- |
| `histox.project` | Project configuration and end-to-end workflow orchestration |
| `histox.data` | Dataset registry, cache resolution, and download planning |
| `histox.dataset` | Cohort filtering, slide/tile records, and dataset operations |
| `histox.slide` | WSI reading, QC, ROI handling, and tile extraction |
| `histox.norm` | Stain-normalization algorithms |
| `histox.model` | Backend selection, model configuration, training, and features |
| `histox.mil` | Multiple-instance learning workflows |
| `histox.heatmap` | Spatial model visualization |
| `histox.studio` | Interactive desktop viewer |

## Documentation and support

- [Documentation](https://histox.readthedocs.io/)
- [Roadmap](ROADMAP.md)
- [GitHub issues](https://github.com/leicaohmu/histox/issues)
- [PyPI package](https://pypi.org/project/histox/)

The hosted documentation is generated from `docs/source`. For installation
and current project direction, this README and [ROADMAP.md](ROADMAP.md) remain
the source of truth.

## Contributing

Small, reviewable pull requests are preferred. Before opening a pull request:

1. explain the user-facing behavior being changed;
2. add or update the smallest relevant test or check;
3. run the package checks used by GitHub Actions;
4. keep new APIs PyTorch-first unless compatibility work is explicitly scoped.

## License and provenance

HistoX is a modified fork of
[Slideflow](https://github.com/slideflow/slideflow). The top-level
[`LICENSE`](LICENSE) records the repository's Apache-2.0 license declaration.
Some bundled source files and optional integrations remain under their original
licenses.

See [`PROVENANCE.md`](PROVENANCE.md) for repository lineage and
[`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) for component-level notices
and unresolved review items. Model weights, datasets, and optional extensions
are not automatically covered by the repository license; consult each
artifact's terms before use or redistribution.

Do not publish a new release until the unresolved license-review items in
`THIRD_PARTY_NOTICES.md` are closed.

## Acknowledgments

- [Slideflow](https://github.com/slideflow/slideflow), the upstream project
  from which HistoX is derived.
- [The Cancer Genome Atlas](https://portal.gdc.cancer.gov/) and other data
  providers that make computational pathology research possible.
- The PyTorch, TensorFlow, libvips, and cuCIM communities.

Contact: [caolei@hrbmu.edu.cn](mailto:caolei@hrbmu.edu.cn)
