def plot_backbone_clades(tree, plot_hull=False, _i=0): c_noclade = grey(0.6) if tree.is_leaf(): plt.scatter(*tree.location, c='k') return clade, rest = tree.children # print(clade.tree_size(), rest.tree_size()) if clade.n_leafs() > 5: plot_tree(clade, color=COLORS[_i]) # , alpha=0.2) plt.scatter(*clade.get_leaf_locations().T, color=COLORS[_i], s=4.) if plot_hull: plot_tree_hull(clade, COLORS[_i]) _i += 1 else: plot_tree(clade, color=c_noclade) plt.scatter(*clade.get_leaf_locations().T, color=c_noclade, s=4.) plot_edge(tree, rest, lw=None, no_arrow=True, zorder=9) if rest.n_leafs() > 20: plot_backbone_clades(rest, plot_hull=plot_hull, _i=_i) else: # plot_tree(rest, color=c_noclade) # plt.scatter(*rest.get_leaf_locations().T, color=c_noclade, s=4.) plot_tree(rest, color=COLORS[_i]) plt.scatter(*rest.get_leaf_locations().T, color=COLORS[_i], s=4.)
def plot_subtree_hulls(tree: Tree): for i in range(4): c = COLORS[i] plot_tree_hull(tree, c=c) plot_root(tree.location, color=c, edgecolor=grey(1.)) tree = tree.big_child() tree = tree.big_child() tree = tree.big_child()
def color_backbone_clades(tree, _i=0): c_noclade = grey(0.65) if tree.is_leaf(): tree.color = COLORS[_i] return clade, rest = tree.children if clade.n_leafs() > 5: color_tree(clade, COLORS[_i]) _i += 1 else: color_tree(clade, c_noclade) if rest.n_leafs() > 30: color_backbone_clades(rest, _i=_i) else: # color_tree(rest, c_noclade) color_tree(rest, COLORS[_i]) rest.color = grey(0.0)
def plot_backbone_splits(tree, plot_edges=True, lw=1., n_clades=10, bb_side=1, plot_hull=True): # SUBGROUP_COLOR_IDXS = [0, 1, 1, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11] # SUBGROUP_COLORS = [COLORS[i] for i in SUBGROUP_COLOR_IDXS] SUBGROUP_COLORS = COLORS p = tree for i in range(n_clades): if p.is_leaf(): break c_backbone, c_subgroup = next_split(p) while c_subgroup.tree_size() < 10: print('Subgroup Size:', c_subgroup.tree_size(), '--> skipped') if plot_edges: plot_tree(c_subgroup, color=grey(0.5), lw=lw) plot_edge(p, c_backbone, no_arrow=True, lw=2*lw, color='k', zorder=3) p = c_backbone if p.is_leaf(): break c_backbone, c_subgroup = next_split(p) print('Subgroup Size:', c_subgroup.tree_size()) if plot_edges: plot_tree(c_subgroup, color=SUBGROUP_COLORS[i], lw=lw) plot_edge(p, c_backbone, no_arrow=True, lw=2*lw, color='k', zorder=3) if plot_hull: plot_tree_hull(c_subgroup, c=SUBGROUP_COLORS[i]) p = c_backbone # # if mode == 'geo': if plot_edges: plot_tree(p, color=SUBGROUP_COLORS[n_clades], lw=lw) if plot_hull: plot_tree_hull(p, c=SUBGROUP_COLORS[n_clades])
x = np.dot(node.location, DRIFT_DIRECTION) return x, t if __name__ == '__main__': import matplotlib.pyplot as plt import geopandas as gpd from src.beast_interface import run_beast, run_treeannotator, load_tree_from_nexus, \ read_nexus_name_mapping, load_trees from src.plotting import plot_hpd, plot_tree, plot_posterior_scatter from src.util import grey from src.colors import PINK, TURQUOISE world = gpd.read_file('data/naturalearth_50m_wgs84.geojson') ax = world.plot(color=grey(.95), edgecolor=grey(0.7), lw=.4, ) CHAIN_LENGTH = 500000 BURNIN = 10000 HPD = 90 MODEL = 'rrw' USE_OUTGROUP = False ADAPT_TREE = False ADAPT_HEIGHT = False FIX_ROOT = False # SUFFIX = '_missingClades' WORKING_DIR = 'data/bantu_{model}_outgroup_{og}_adapttree_{at}_' + \ 'adaptheight_{ah}_hpd_{hpd}{fixroot}{suffix}/'
# -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function, \ unicode_literals import matplotlib.pyplot as plt from webcolors import hex_to_rgb, rgb_to_hex import numpy as np from src.util import grey # COLORS PINK = (0.95, 0.15, 0.8) TURQUOISE = (0, 0.8, 0.9) COLOR_ROOT_EST = (0.75, 0.2, 0.0) COLOR_ROOT_TRUE = (0., 0.5, 0.6) COLOR_PATH = grey(0.5) COLOR_SCATTER = 'orange' class Cycler(object): def __init__(self, data): self.data = data def __getitem__(self, i): n = len(self.data) return self.data[i % n] _COLORS = [ '#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf', '#ffe999', '#802a66', '#058090'