CmhaDSO scVelo

使用例

インストール
$ conda install -c bioconda scvelo
$ conda install -c conda-forge python-igraph # If you use PAGA GRAPH
$ conda install -c conda-forge jupyterlab
IMPORT etc
import scvelo as scv
scv.logging.print_version()
scv.settings.verbosity = 3
scv.settings.presenter_view = True # set max width size
scv.set_figure_params('scvelo') # for beautiful visualization
%matplotlib inline
I/O
adata = scv.datasets.pancreas()
  # in-built data for tutolial

  # Input data for scVelo are two count matrices of pre-mature (unspliced) and mature (spliced) abundances
  # READ FILE (loom, h5ad, xlsx, csv, tab, txt ...) to an AnnData
  # adata = scv.read(filepath, cache=True)

adata
  # adata.X 
  # adata.obs 
  # adata.var 
  # adata.uns 
INTRON PROPORTION
scv.utils.show_proportions(adata)
# typically between 10%-25% of unspliced molecules containing intronic sequences
PREPROCESSING
# GENE SELECTION BY DETECTION (with a minimum number of counts)
# HIGH VARIABILITY
# NORMALIZING EVERY CELL BY ITS TOTAL SIZE
# LOGARITHMIZING

scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000)
scv.pp.moments(adata, n_pcs=30, n_neighbors=30)
COMPUTE VELOCITY AND VELOCITY GRAPH
  # A: STOCHASTICALLY (DEFAULT)
  # B: DETERMINISTICALLY
  # C: DYNAMICAL >>> LATENT TIME, DRIVER GENES

#@ A:
scv.tl.velocity(adata)
scv.tl.velocity_graph(adata)

#@ C:
scv.tl.recover_dynamics(adata, n_jobs=24) # TIME CONSUMING PROCESS
scv.tl.velocity(adata, mode='dynamical')
scv.tl.velocity_graph(adata, n_jobs=24)
# adata.write('adata.h5ad')
# adata = scv.read('adata.h5ad')
scv.tl.latent_time(adata) # NEED MANY MEMORIES

#@ VISUALIZATION_1 (A, B, C)
scv.pl.velocity_embedding_stream(adata, basis='umap')

#@ VISUALIZATION_2 (A, B, C)
scv.pl.velocity(adata, var_names=['Ins1', 'Pdx1'])

#@ VISUALIZATION_3 (C)
scv.pl.scatter(adata, color='latent_time', color_map='gnuplot', size=80, colorbar=True)

#@ VISUALIZATION_4 (C)
scv.pl.scatter(adata, x='latent_time', y=['Ins1', 'Pdx1'], frameon=False)

#@ VISUALIZATION_5 (A, B, C) 
scv.tl.velocity_confidence(adata)
keys='velocity_length', 'velocity_confidence'
scv.pl.scatter(adata, c=keys, cmap='coolwarm', perc=[5, 95])

#@ VISUALIZATION_6 (A, B, C) 

# This is needed due to a current bug
adata.uns['neighbors']['distances'] = adata.obsp['distances']
adata.uns['neighbors']['connectivities'] = adata.obsp['connectivities']

scv.tl.paga(adata, groups='clusters')
df = scv.get_df(adata, 'paga/transitions_confidence', precision=2).T
df.style.background_gradient(cmap='Blues').format('{:.2g}')
scv.pl.paga(adata, basis='umap', size=50, alpha=.1,
min_edge_width=2, node_size_scale=1.5)