Getting Start
Examples of PhyloVelo and steps are provided in Jupyter Notebook under notebooks folder. For start, please refer to records analyzing simulation, C.elegans and KPTracer datasets.
PhyloVelo on New Dataset
PhyloVelo provides an integrated function for phylogenetic velocity analysis by default whilst specific configurations might need to be adjusted accordingly.
1. import pacakge
import phylovelo as pv
2. import data, filter, normalize and dimensionality reduction
sd = pv.scData(count=xx, phylo_tree=xx)
sd.drop_duplicate_genes()
sd.normalize_filter(min_count=20)
sd.dimensionality_reduction(target='x_normed', method='umap')
3. Run model
depths = [tree.get_depth(sd.phylo_tree.find_any(name=i)) for i in sd.x_normed.index]
pv.velocity_inference(sd, depths, cutoff=0.95, target='x_normed')
4. Porject velocity into embedding and visualization
pv.velocity_embedding(sd, target='x_normed')
fig, ax = plt.subplots()
ax.scatter(sd.Xdr.iloc[:,0], sd.Xdr.iloc[:,1], c=depths, s=100, alpha=0.3)
ax = pv.velocity_plot(sd.Xdr.to_numpy(), sd.velocity_embeded, ax, 'stream', radius=0.8, lw_coef=100, arrowsize=2)
5. PhyloVelo pseudotime analysis
PhyloVelo supports two pseudotime estimators. The default graph-based method uses the projected velocity field in the embedding, while the MEG expression method directly scores cells from robustly oriented MEG expression. Both methods store a [0, 1] normalized result in sd.phylo_pseudotime.
# Graph-based pseudotime from the projected velocity field.
pv.calc_phylo_pseudotime(sd, n_neighbors=100, r_sample=0.8, random_state=0)
# Alternatively, estimate pseudotime directly from MEG expression.
# pv.calc_meg_pseudotime(sd, target='x_normed')
# pv.calc_phylo_pseudotime(sd, method='meg', target='x_normed')
fig, ax = plt.subplots(figsize=(8,8))
scatter = ax.scatter(sd.Xdr.iloc[:,0],sd.Xdr.iloc[:,1], c=sd.phylo_pseudotime,cmap='plasma', s=60)
cbaxes = inset_axes(ax, width="3%", height="30%", loc='lower left')
plt.colorbar(scatter, cax=cbaxes, orientation='vertical')
[ ]: