Skip to main content

SPATNIC

Spatial Pathology-based Typist for Normal / Cancer

A pip-installable tool for annotating tumor cells in single-cell and spatial transcriptomics data using a Student-t VAE classifier. Pre-trained models are specialized for colorectal cancer (CRC) tissue.

Installation

pip install spatnic

Quick Start

import scanpy as sc
import spatnic

# Load and preprocess your data
adata = sc.read_h5ad("your_data.h5ad")
sc.pp.normalize_total(adata)
sc.pp.log1p(adata)

# Predict (default: Tumor vs Normal)
spatnic.predict(adata)

# Results are added to adata.obs
print(adata.obs["spatnic_pred"].value_counts())
print(adata.obs["spatnic_score"].describe())

Models

Model Description Classes
tumor_normal (default) Tumor vs normal epithelial cells Normal, Tumor
tumor_other Tumor vs all other cell types Other, Tumor
# Select a model
spatnic.predict(adata, model="tumor_normal")
spatnic.predict(adata, model="tumor_other")

# Use a custom (fine-tuned) model
spatnic.predict(adata, model="path/to/finetuned.pt")

Fine-tuning

spatnic.finetune(
    adata,
    label_key="cell_type",
    label_map={"Epithelial": 0, "Malignant": 1},
    save_path="my_finetuned.pt",
)

# Predict with the fine-tuned model
spatnic.predict(adata_new, model="my_finetuned.pt")

Options

spatnic.predict(
    adata,
    model="tumor_normal",      # model name or path
    threshold=0.5,              # classification threshold
    batch_size=2048,            # batch size for inference
    key_added="spatnic_pred",   # obs key for predicted labels
    score_key_added="spatnic_score",
    layer_key=None,             # AnnData layer to use (None = .X)
    return_latent=False,        # if True, also returns latent representation
    device=None,                # "cuda" or "cpu" (auto-detected)
)

Checkpoint Export (for developers)

After training in a notebook, export a checkpoint:

from spatnic import export_checkpoint

export_checkpoint(
    state_dict_path="student_t_vae_cls_weights.pth",
    gene_names=list(adata_hvg.var_names),  # 3000 genes
    mu_g=mu_g,  # per-gene mean from training set
    std_g=std_g,  # per-gene std from training set
    model_name="tumor_normal",
    label_map={0: "Normal", 1: "Tumor"},
)

Requirements

  • Python >= 3.9
  • PyTorch >= 2.0
  • scanpy >= 1.9
  • anndata >= 0.8

Performance (default model: tumor_normal)

              precision    recall  f1-score   support
      Normal       0.96      0.96      0.96     48902
       Tumor       0.96      0.96      0.96     48902
    accuracy                           0.96     97804
ROC-AUC: 0.9909

License

MIT

Metadata

Release files for spatnic 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spatnic 0.1.1
File Size Uploaded Provenance Actions
spatnic-0.1.1.tar.gz 16.2 kB Without provenance Details for spatnic-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spatnic 0.1.1
File Interpreter ABI Platform Actions
spatnic-0.1.1-py3-none-any.whl Python 3 none any Details for spatnic-0.1.1-py3-none-any.whl

Total release size: 30.5 kB

Release files / spatnic-0.1.1.tar.gz

Download URL spatnic-0.1.1.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4048da138d57bf6c82bb9970aa6b761f7454209e8ca9f2102442c33486abb386
BLAKE2b-256 checksum
How to use checksums
a85a79396275b91cdb147a2ab467c606215d9b5cc12929019a70f80c26ce1908
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / spatnic-0.1.1-py3-none-any.whl

Download URL spatnic-0.1.1-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5b6ef1122362f462ded5ffd4849013fb0f7f03274d854ae89609b973fbf7840
BLAKE2b-256 checksum
How to use checksums
3f9ee7432563710aa3616453b84d4d6d6c3ff59a5bd6a157747de76967a953a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Security for spatnic 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page