Graph contrastive learning for spatial transcriptomics
Project description
CellNiche
Overview
CellNiche is a graph‐contrastive learning framework for spatial transcriptomics data. It constructs a cell‐cell graph from spatial coordinates or a provided adjacency, learns low-dimensional embeddings via a contrastive graph neural network (GNN), and can optionally reconstruct gene expression profiles. Use CellNiche to discover spatial domains and relationships between cells in high-resolution tissue maps.
Installation
From PyPI
pip install cellniche
From Source
git clone https://github.com/Super-LzzZ/CellNiche.git
cd CellNiche/release
pip install .
Requirements
- Python ≥ 3.7
- PyTorch ≥ 1.12
- PyTorch Geometric (torch-geometric, torch-scatter, torch-sparse, torch-cluster, torch-spline-conv)
- Scanpy ≥ 1.9
- Anndata ≥ 0.9
- scikit-learn ≥ 1.3
- numpy ≥ 1.22
- scipy ≥ 1.10
- pandas ≥ 2.0
- networkx ≥ 3.1
- tqdm ≥ 4.67.1
You can install most dependencies with:
pip install torch torchvision torchaudio
pip install torch-geometric torch-scatter torch-sparse torch-cluster torch-spline-conv
pip install scanpy anndata scikit-learn numpy scipy pandas networkx tqdm
Getting Started
import cellniche
# Parse arguments from a YAML config
opts = cellniche.parse_args([
"--config", "configs/cortex.yaml"
])
# Run training/inference
cellniche.main(opts)
Example YAML snippet (configs/example.yaml):
# Data & preprocessing
data_path: "path/data/cortex/"
dataset: "osmFISH_SScortex"
phenoLabels: "ClusterName"
nicheLabels: "Region" # None
embedding_type: "pheno_expr"
hvg: False
# Graph construction
k_neighborhood: null
radius: 1000.0
# Sampling & training
batch_size: 2048
epochs: null
max_steps: 20
lr: 0.001
weight_decay: 0.0
dropout: 0.0
# Model architecture
hidden_channels: [512, 256]
size: [10, 10]
projection: "" # [128, 64]
decoder: "" # [64]
# Contrastive strategy
tau: 0.9
negative_slope: 0.5
strategy: "freq"
use_weight: False
pos_weight_strategy: "inverse_sim"
neg_weight_strategy: "inverse_sim"
# Random‐walk
wt: 30
wl: 5
p: 0.25
q: 4.0
# Misc
seed: 3207
save: False
metrics: true
refine: False
save_path: "path/results/cortex"
verbose: true
Project details
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 cellniche-0.1.0.tar.gz.
File metadata
- Download URL: cellniche-0.1.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e92fa3f216c4b60f5433b14b357aa54634583f11e270271d8cdfc68bf33d0e9f
|
|
| MD5 |
54e363221feba368cb8a25a1d02df3da
|
|
| BLAKE2b-256 |
2ea747ade064672fbe90ff49a2f7fa2efd956ffebd5ab9d18d71ce6f41895ad5
|
File details
Details for the file cellniche-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cellniche-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b424b547f6bd9b40d77544f0705919952dd70aa151af02838188af5dd19efb68
|
|
| MD5 |
5749c0a9e8bee9c10c579f4d0efda85d
|
|
| BLAKE2b-256 |
886bc5145fa4ce705b83059fd6973961d1191b34bbc8e6deb07fe5a40e7fe15f
|