The following analysis has been published by Haghverdi et al., Nat. Meth. (2016) together with a Matlab implementation of Diffusion Pseudotime. The data is from Moignard et al., Nat. Biotechn. (2015).
import numpy as np
import pandas as pd
import scanpy.api as sc
sc.settings.verbosity = 3 # verbosity: errors (0), warnings (1), info (2), hints (3)
sc.logging.print_versions()
results_file = './write/moignard15.h5ad'
sc.settings.set_figure_params(dpi=80) # low dpi (dots per inch) yields small inline figures
This is single-cell qPCR data. It's already on a logrithmic scale and pretty low-dimensional. We do not have to perform extensive preprocessing.
adata = sc.datasets.moignard15()
Compute the neighborhood relations of single cells.
sc.pp.neighbors(adata, n_neighbors=5, method='gauss', knn=False)
Compute branchings and diffusion pseudotime using DPT.
sc.tl.diffmap(adata)
sc.tl.dpt(adata, n_branchings=1, n_dcs=10)
sc.pl.diffmap(adata, color=['dpt_pseudotime', 'dpt_groups', 'exp_groups'])
sc.pl.dpt_groups_pseudotime(adata)
sc.pl.dpt_timeseries(adata)
Let us annotate the cell groups as follows.
adata.rename_categories('dpt_groups', ['undecided/endothelial', 'erythrocytes', 'trunk', 'endothelial'])
sc.pl.diffmap(adata, color='dpt_groups')
Save the results.
adata.write(results_file)
Or as csv.
# adata.obs.to_csv('./write/annotation.csv')
# To write the full object to csvs
# adata.write_csvs('./write/moignard15.csv')