SPATNIC: Spatial Pathology-based Typist for Normal / Cancer
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spatnic-0.1.1.tar.gz.
File metadata
- Download URL: spatnic-0.1.1.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4048da138d57bf6c82bb9970aa6b761f7454209e8ca9f2102442c33486abb386
|
|
| MD5 |
5cf0a6531c0ee480756208fb70cf0c85
|
|
| BLAKE2b-256 |
a85a79396275b91cdb147a2ab467c606215d9b5cc12929019a70f80c26ce1908
|
File details
Details for the file spatnic-0.1.1-py3-none-any.whl.
File metadata
- Download URL: spatnic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5b6ef1122362f462ded5ffd4849013fb0f7f03274d854ae89609b973fbf7840
|
|
| MD5 |
2b45d2f7a598f881fc6ca9933f6acc51
|
|
| BLAKE2b-256 |
3f9ee7432563710aa3616453b84d4d6d6c3ff59a5bd6a157747de76967a953a2
|