.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/visualization/plot_dendrogram.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_visualization_plot_dendrogram.py: Visualizing a tree in dendrogram format --------------------------------------- This example shows how to visualize an inferred tree. .. GENERATED FROM PYTHON SOURCE LINES 7-12 .. code-block:: Python import scphylo as scp # sphinx_gallery_thumbnail_path = "_static/thumbnails/dendrogram.png" .. GENERATED FROM PYTHON SOURCE LINES 13-14 First, we load a readcount single-cell genotype data and filter it. .. GENERATED FROM PYTHON SOURCE LINES 14-24 .. code-block:: Python 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() .. rst-class:: sphx-glr-script-out .. code-block:: none /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 .. GENERATED FROM PYTHON SOURCE LINES 25-26 Then we infer the tree using scistree algorithm. .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python df_out = scp.tl.scistree(df_in, alpha=0.001, beta=0.2) .. rst-class:: sphx-glr-script-out .. code-block:: none 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 .. GENERATED FROM PYTHON SOURCE LINES 29-30 Next we convert the inferred genotype matrix to a tree object. .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: Python tree = scp.ul.to_tree(df_out) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Finally we can draw the tree in `dendrogram` format. .. GENERATED FROM PYTHON SOURCE LINES 34-51 .. code-block:: Python # 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 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.313 seconds) **Estimated memory usage:** 10 MB .. _sphx_glr_download_auto_examples_visualization_plot_dendrogram.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_dendrogram.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_dendrogram.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_