Spaces:
Sleeping
Sleeping
#!/usr/bin/env python | |
# coding: utf-8 | |
# # Trajectory Inference with VIA and scVelo | |
# | |
# When scRNA-velocity is available, it can be used to guide the trajectory inference and automate initial state prediction. However, because RNA velocitycan be misguided by(Bergen 2021) boosts in expression, variable transcription rates and data capture scope limited to steady-state populations only, users might find it useful to adjust the level of influence the RNA-velocity data should exercise on the inferred TI. | |
# | |
# Paper: [Generalized and scalable trajectory inference in single-cell omics data with VIA](https://www.nature.com/articles/s41467-021-25773-3) | |
# | |
# Code: https://github.com/ShobiStassen/VIA | |
# | |
# Colab_Reproducibility:https://colab.research.google.com/drive/1MtGr3e9uUb_BWOzKlcbOTiCYsZpljEyF?usp=sharing | |
# In[7]: | |
import omicverse as ov | |
import scanpy as sc | |
import scvelo as scv | |
import cellrank as cr | |
ov.utils.ov_plot_set() | |
# ## Data loading and preprocessing | |
# | |
# We use a familiar endocrine-genesis dataset (Bastidas-Ponce et al. (2019).) to demonstrate initial state prediction at the EP Ngn3 low cells and automatic captures of the 4 differentiated islets (alpha, beta, delta and epsilon). As mentioned, it us useful to control the level of influence of RNA-velocity relative to gene-gene distance and this is done using the velo_weight parameter. | |
# In[2]: | |
adata = cr.datasets.pancreas() | |
adata | |
# In[3]: | |
n_pcs = 30 | |
scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=5000) | |
sc.tl.pca(adata, n_comps = n_pcs) | |
scv.pp.moments(adata, n_pcs=None, n_neighbors=None) | |
scv.tl.velocity(adata, mode='stochastic') # good results acheived with mode = 'stochastic' too | |
# ## Initialize and run VIA | |
# | |
# | |
# In[4]: | |
v0 = ov.single.pyVIA(adata=adata,adata_key='X_pca',adata_ncomps=n_pcs, basis='X_umap', | |
clusters='clusters',knn=20, root_user=None, | |
dataset='', random_seed=42,is_coarse=True, preserve_disconnected=True, pseudotime_threshold_TS=50, | |
piegraph_arrow_head_width=0.15,piegraph_edgeweight_scalingfactor=2.5, | |
velocity_matrix=adata.layers['velocity'],gene_matrix=adata.X.todense(),velo_weight=0.5, | |
edgebundle_pruning_twice=False, edgebundle_pruning=0.15, pca_loadings = adata.varm['PCs'] | |
) | |
v0.run() | |
# In[ ]: | |
# In[5]: | |
fig, ax, ax1 = v0.plot_piechart_graph(clusters='clusters',cmap='Reds',dpi=80, | |
show_legend=False,ax_text=False,fontsize=4) | |
fig.set_size_inches(8,4) | |
# ## Visualize trajectory and cell progression | |
# | |
# Fine grained vector fields | |
# In[8]: | |
v0.plot_trajectory_gams(basis='X_umap',clusters='clusters',draw_all_curves=False) | |
# In[9]: | |
v0.plot_stream(basis='X_umap',clusters='clusters', | |
density_grid=0.8, scatter_size=30, scatter_alpha=0.3, linewidth=0.5) | |
# ## Draw lineage likelihoods | |
# | |
# These indicate potential pathways corresponding to the 4 islets (two types of Beta islets Lineage 5 and 12) | |
# In[10]: | |
v0.plot_lineage_probability() | |