import toytree
import toyplot
import numpy as np

"""
Explanation: Tip labels
Tip labels are composed simply of text plotted at the tips of the tree, or aligned at the furthest tip of the tree, and can be highly modified as with any text element. Common examples are presented below.
End of explanation
"""


## A tree with edge lengths
newick = "((apple:2,orange:4):2,(((tomato:2,eggplant:1):2,pepper:3):1,tomatillo:2):1);"
tre = toytree.tree(newick)

## show tip labels
tre.draw();

## hide tip labels
tre.draw(tip_labels=False);

"""
Explanation: Hide/Show tip labels
The argument tip_labels can be entered as True, False, or as a list of names, with the default being True in which case the tip labels are shown and are taken from the tree object (parsed from the newick string).
End of explanation
"""


## enter a new list of names
tipnames = ["a", "b", "c", "d", "e", "f"]
tre.draw(tip_labels=tipnames);

## get list of existing names and modify it
modnames = ["tip - " + i for i in tre.get_tip_labels()]
tre.draw(tip_labels=modnames);

## you can use HTML tags to further style the text
modnames = ["<b>{}</b>".format(i) if 'tom' in i else i for i in tre.get_tip_labels()]
tre.draw(tip_labels=modnames);

"""
Explanation: Modify tip labels
You can enter a list to tip_labels if which case the list of names will replace the labels at the tips of the tree. The list must be the same length as the number of tips. You can use the function .get_tip_labels() to return a list of names that are currently on the tree. Names are ordered from top to bottom in position on a right-facing tree. The .get_tip_labels() argument is useful for returning a list of names that you can modify and then enter back into tip_labels like in the example below.
End of explanation
"""


## set a single tip labels color
tre.draw(tip_labels_colors="darkcyan");

## use a list of colors to assign different values to tips
colorlist = ["darkcyan" if "tom" in t else "darkorange" for t in tre.get_tip_labels()]
tre.draw(tip_labels_colors=colorlist);

"""
Explanation: Color tip labels
You can color all tip labels to be the same color or you can enter a different color for each tip label by entering a list of colors. Colors can be entered as HTML names, as HEX strings, or as rgba codes. See the excellent Toyplot color guide for more color options.
End of explanation
"""


## default tree
tre.draw();

## with edge lengths
tre.draw(use_edge_lengths=False);

## with edge lengths and aligned tips
tre.draw(tip_labels_align=True);

"""
Explanation: Aligning tip labels
By default Toytree plots trees without edge length information so that the tips are aligned. If you add the argument use_edge_lengths=True then tips of the tree will no longer necessarily be aligned and thus tip labels may not be aligned. To use edge lengths but still enforce aligning of the tip labels you can add the additional argument tip_labels_align=True, which will add dashed lines complete the edge lengths.
End of explanation
"""


## style the edges and alignment-edges
tre.draw(
    use_edge_lengths=True, 
    tip_labels_align=True, 
    edge_style={"stroke": "darkcyan"}, 
    edge_align_style={"stroke": "darkorange"},
    );

"""
Explanation: Styling edges on aligned tip trees
You can of course modify the styling of the dashed edge lengths (such as making them not dashed or changing their color) by using the edge_align_style dictionary.
End of explanation
"""


