A local RNA velocity model for cell differentiation inference based on Julia programming language. This project is currently WIP and highly inspired by cellDancer.
-
Julia >= 1.10
-
Python >= 3.7
-
scvelo
- cellDancer == 1.1.7
Preprocessing
import scvelo as scv
import scanpy as sc
import numpy as np
# Load anndata from scvelo
adata = scv.datasets.gastrulation_erythroid()
# Preprocessing
scv.pp.filter_and_normalize(adata, min_shared_counts = 20, n_top_genes = 2000)
sc.pp.pca(adata)
sc.pp.neighbors(adata, n_pcs = 50, n_neighbors = 50)
scv.pp.moments(adata, n_pcs = None, n_neighbors = None)
# Clustering
sc.tl.leiden(adata)
sc.pl.umap(adata, color = "leiden")
# Calculate diffusion pseudotime
adata.uns["iroot"] = np.flatnonzero(adata.obs["leiden"] == '6')[0]
adata.uns["root"] = 6 #Base on root leiden cluster
sc.tl.dpt(adata)
# Avoid PooledArray bug in Julia
adata.var["highly_variable_genes"] = ["true" if item == "True" else "false" for item in adata.var["highly_variable_genes"]]
# Write anndata for JuloVelo
adata.write_h5ad("JuloVelo_pre.h5ad")
Training model
using JuloVelo
using Plots
# Load anndata and change iroot to root cluster
adata = read_adata("JuloVelo_pre.h5ad")
# Normalize read count
normalize(adata)
# Filter genes and pre-determine gene kinetics
filter_and_gene_kinetics_predetermination(adata)
# Reshape data for model compatible
reshape_data(adata)
# Reduce sample size
density_sampling(adata)
# Training
Kinetics = train(adata)
# Calculate velocity
velocity_estimation(adata, Kinetics)
# Compute cell velocity on embedding space
compute_cell_velocity(adata)
# Restore pseudotime
estimate_pseudotime(adata)
# Write anndata
write_adata(adata)