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

"""
Explanation: DPT for hematopoiesis in mouse (Moignard et al., 2015)
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).
End of explanation
"""


adata = sc.datasets.moignard15()

"""
Explanation: 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.

Filter out a few genes.
Choose a 'root cell'.                                                                                                                                                           
Define groupnames by inspecting cellnames.
End of explanation
"""


sc.pp.neighbors(adata, n_neighbors=5, method='gauss', knn=False)

"""
Explanation: Compute the neighborhood relations of single cells.
End of explanation
"""


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)

"""
Explanation: Compute branchings and diffusion pseudotime using DPT.
End of explanation
"""


adata.rename_categories('dpt_groups', ['undecided/endothelial', 'erythrocytes', 'trunk', 'endothelial'])

sc.pl.diffmap(adata, color='dpt_groups')

"""
Explanation: Let us annotate the cell groups as follows.
End of explanation
"""


adata.write(results_file)

"""
Explanation: Save the results.
End of explanation
"""


# adata.obs.to_csv('./write/annotation.csv')

# To write the full object to csvs
# adata.write_csvs('./write/moignard15.csv')

"""
Explanation: Or as csv.
End of explanation
"""


