Simple tree visualization with metadataΒΆ

A simple tree visualization with cocoatree.

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)

Gallery generated by Sphinx-Gallery