Note
Go to the end to download the full example code
Visualizing a tree in dendrogram format#
This example shows how to visualize an inferred tree.
import scphylo as scp
# sphinx_gallery_thumbnail_path = "_static/thumbnails/dendrogram.png"
First, we load a readcount single-cell genotype data and filter it.
adata = scp.datasets.example()
adata = adata[adata.obs.group.isin(["C16", "C11", "C22"]), :].copy()
scp.pp.filter_mut_vaf_greater_than_coverage_mutant_greater_than(
adata, min_vaf=0.4, min_coverage_mutant=20, min_cells=2
)
scp.pp.filter_mut_reference_must_present_in_at_least(adata, min_cells=1)
scp.pp.filter_mut_mutant_must_present_in_at_least(adata, min_cells=2)
scp.pp.build_scmatrix(adata)
df_in = adata.to_df()
/home/docs/checkouts/readthedocs.org/user_builds/scphylo-tools/envs/latest/lib/python3.9/site-packages/anndata/__init__.py:51: FutureWarning: `anndata.read` is deprecated, use `anndata.read_h5ad` instead. `ad.read` will be removed in mid 2024.
warnings.warn(
Matrix with n_obs × n_vars = 21 × 123
Matrix with n_obs × n_vars = 21 × 112
Matrix with n_obs × n_vars = 21 × 112
Then we infer the tree using scistree algorithm.
df_out = scp.tl.scistree(df_in, alpha=0.001, beta=0.2)
running ScisTree with alpha=0.001, beta=0.2, n_threads=1
input -- size: 21x112
input -- 0: 817#, 34.7%
input -- 1: 790#, 33.6%
input -- NA: 745#, 31.7%
input -- CF: False
output -- size: 21x112
output -- 0: 721#, 30.7%
output -- 1: 1631#, 69.3%
output -- NA: 0#, 0.0%
output -- CF: True
output -- time: 0.7s (0:00:00.711603)
flips -- #0->1: 282
flips -- #1->0: 1
flips -- #NA->0: 185
flips -- #NA->1: 560
rates -- FN: 0.263
rates -- FP: 0.00186567
rates -- NA: 0.317
score -- NLL: 637.364776250779
Next we convert the inferred genotype matrix to a tree object.
tree = scp.ul.to_tree(df_out)
Finally we can draw the tree in dendrogram format.
# scp.pl.dendro_tree(
# tree,
# cell_info=adata.obs,
# label_color="subclone_color",
# width=1200,
# height=600,
# dpi=200,
# distance_labels_to_bottom=3,
# inner_node_type="both",
# inner_node_size=2,
# annotation=[
# ("bar", "Axl", "Erbb3", 0.2),
# ("bar", "Mitf", "Mitf", 0.2),
# ],
# )
# TODO: fix
Total running time of the script: (0 minutes 1.313 seconds)
Estimated memory usage: 10 MB