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.
Installation
pip install git+https://github.com/shusakai/spatnic.git
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
spatnic-0.1.0.tar.gz
(15.8 kB
view details)
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
spatnic-0.1.0-py3-none-any.whl
(14.1 kB
view details)
File details
Details for the file spatnic-0.1.0.tar.gz.
File metadata
- Download URL: spatnic-0.1.0.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
961ac4d00753c3a8b4a806d9c071cfb48ba61530da134459d3c7e81722ebad51
|
|
| MD5 |
7269d3a2ad1ea89f60493e62bca1aa62
|
|
| BLAKE2b-256 |
b6a8228217b758e877466a6ce48b5b88ef4c6feb59d881ffd529f8df55c84571
|
File details
Details for the file spatnic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spatnic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.1 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 |
bd96e88516f7eeb4c265e1b95ed33103d55ac4e41da30891222a4b9940678ab5
|
|
| MD5 |
5aa8f2638251e1249b596457f5985b19
|
|
| BLAKE2b-256 |
3dec5d0a7e14fb956dd2f2fd8768370f2d381feb06152b4efe60e94ad6e133ec
|