Set up¶
- Tool: Scanpy
- Github: None
- Paper: https://www.sc-best-practices.org/trajectories/pseudotemporal.html
In [ ]:
import scanpy as sc
import matplotlib.pyplot as plt
In [ ]:
src_dir = '../../data/preprocessed_data/'
Load data¶
In [ ]:
adata = sc.read_h5ad(f'{src_dir}/harmony_cellmarkers.h5ad')
adata
/Users/Shared/anaconda3/envs/IDIMENSIONS/lib/python3.9/site-packages/anndata/_core/anndata.py:1818: UserWarning: Observation names are not unique. To make them unique, call `.obs_names_make_unique`. utils.warn_names_duplicates("obs")
Out[Â ]:
AnnData object with n_obs × n_vars = 7391 × 33694 obs: 'batch', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'leiden', 'cell_type' var: 'mean', 'std', 'highly_variable', 'means', 'dispersions', 'dispersions_norm' uns: 'batch_colors', 'cell_type_colors', 'dendrogram_cell_type', 'hvg', 'leiden', 'leiden_colors', 'log1p', 'neighbors', 'pca', 'umap' obsm: 'X_pca', 'X_pca_harmony', 'X_umap', 'ora_estimate', 'ora_pvals' varm: 'PCs' layers: 'log_norm', 'norm', 'raw', 'scale_data' obsp: 'connectivities', 'distances'
In [ ]:
sc.tl.tsne(adata)
sc.pl.tsne(adata, color=["batch", "cell_type"])
Pseudotime construction¶
In [ ]:
sc.tl.diffmap(adata)
sc.tl.dpt(adata)
In [ ]:
# Setting root cell as described above
root_ixs = adata.obsm["X_diffmap"][:, 3].argmin()
sc.pl.diffmap(
adata,
color=["cell_type"],
components=['2, 3'],
)
adata.uns["iroot"] = root_ixs
In [ ]:
sc.pl.tsne(
adata,
color=["dpt_pseudotime"],
)
In [ ]:
sc.pl.violin(
adata,
keys=["dpt_pseudotime"],
groupby="cell_type",
rotation=45,
)