Leveraging information in spatial transcriptomics to predict super-resolution gene expression from histology images in tumors
HisToGene is a deep learning method that predicts super-resolution gene expression from histology images in tumors. Trained in a spatial transcriptomics dataset, HisToGene models the spatial dependency in gene expression and histological features among spots through a modified Vision Transformer model. [bioRxiv]
import torch
from vis_model import HisToGene
model = HisToGene(
n_genes=1000,
patch_size=112,
n_layers=4,
dim=1024,
learning_rate=1e-5,
dropout=0.1,
n_pos=64
)
# flatten_patches: [N, 3*W*H]
# coordinates: [N, 2]
pred_expression = model(flatten_patches, coordinates) # [N, n_genes]
Required package:
- PyTorch >= 1.8
- pytorch-lightning >= 1.4
- scanpy >= 1.8
n_genes
: int.
Amount of genes.patch_size
: int.
Width/diameter of the spots.n_layers
: int, default4
.
Number of Transformer blocks.dim
: int.
Dimension of the embeddings.learning_rate
: float between[0, 1]
, default1e-5
.
Learning rate.dropout
: float between[0, 1]
, default0.1
.
Dropout rate in the Transformer.n_pos
: int, default64
.
Maximum number of the coordinates.
See tutorial.ipynb