
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/visualizations/test.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_visualizations_test.py>`
        to download the full example code. or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_visualizations_test.py:


=======================================
Simple tree visualization with metadata
=======================================

A simple tree visualization with cocoatree.

.. GENERATED FROM PYTHON SOURCE LINES 9-64

.. code-block:: Python


    import pandas as pd
    from cocoatree.io import load_MSA, load_tree_ete3
    from cocoatree.visualization import update_tree_ete3_and_return_style

    # Import necessary packages
    from ete3 import ProfileFace, TreeStyle, NodeStyle, TextFace, \
        add_face_to_node, SeqMotifFace, RectFace


    annot_file = 'data/random_seq_tree_annotations.csv'
    df_annot = pd.read_csv(annot_file)

    tree_file = 'data/random_seq_tree_kpicsg_ete3.treefile'
    tree_ete3 = load_tree_ete3(tree_file)

    sector_file = 'data/SCA_sector_1_core_tagged_seq.fasta'
    data = load_MSA(sector_file, 'fasta')

    sector_id = data["sequence_ids"]
    sector_seq = data["alignment"]


    tree_style = TreeStyle() 
    tree_style.scale = 200
    tree_style.layout_fn = [] 
    tree_style.show_leaf_name = False

    linewidth = 3
    tree_style.branch_vertical_margin = 10 # 10 pixels between adjacent branches

    # Add bootstrap support NodeStyle 
    boot_style = NodeStyle() 
    boot_style["fgcolor"] = "darkred"
    boot_style["size"] = 10

    boot_style["vt_line_width"] = linewidth
    boot_style["hz_line_width"] = linewidth

    support = 95

    empty_style = NodeStyle() 
    empty_style["size"] = 0 
    empty_style["hz_line_width"] = linewidth
    empty_style["vt_line_width"] = linewidth

    for node in tree_ete3.traverse(): 
        if node.support >= support: 
            node.set_style(boot_style) 
        else: 
            node.set_style(empty_style)



    tree_ete3.render("simple_tree.png", tree_style=tree_style)


.. _sphx_glr_download_auto_examples_visualizations_test.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/tree-timc/cocoatree/gh-pages?urlpath=lab/tree/notebooks/auto_examples/visualizations/test.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: test.ipynb <test.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: test.py <test.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: test.zip <test.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
