eaton-lab / toytree

A minimalist tree plotting library using toyplot graphs
http://eaton-lab.org/toytree
BSD 3-Clause "New" or "Revised" License
165 stars 28 forks source link

fixed_order should be a draw setting, not tree setting. #36

Closed eaton-lab closed 4 years ago

eaton-lab commented 4 years ago

The current setting is superfluous, and was designed only to allow modifying tipnames on multitree objects more easily. Instead, order/position should be implemented only in .draw().

# what happens under the hood when you draw normally
tre = toytree.rtree.rtree(5)
tre.draw(fixed_order=None, fixed_position=None)
tre.draw(fixed_order=['r0', 'r1', 'r2', 'r3', 'r4'], , fixed_position=[0, 1, 2, 3, 4])

# draw tree with different tip order but same normal spacing between tips
tre = toytree.rtree.rtree(5)
tre.draw(fixed_order=['r1', 'r2', 'r0', 'r3', 'r4'], fixed_position=[0, 1, 2, 3, 4])

# draw tree with different tip order And different spacing between tips
tre = toytree.rtree.rtree(5)
tre.draw(fixed_order=['r1', 'r2', 'r0', 'r3', 'r4'], fixed_position=[0.5, 1, 2.5, 3, 5])

Multitree objects can take fixed order as a list, like above, or as the argument True, in which case it will infer a consensus tree and use the consensus tip order. Modifying the order and spacing on multiple trees is hard to do with a similarly concise syntax. Below is how i will probably implement it...

# draw multitree with tips in consensus order
mtre = toytree.mtree([toytree.rtree.rtree(5) for i in range(10)])
mtre.draw_tree_grid(fixed_order=True)

# draw multitree with tips in specific order
mtre = toytree.mtree([toytree.rtree.rtree(5) for i in range(10)])
mtre.draw_tree_grid(fixed_order=['r1', 'r2', 'r0', 'r3', 'r4'])

# draw multitree with tips in specific order AND spacing modified
mtre = toytree.mtree([toytree.rtree.rtree(5) for i in range(10)])
mtre.draw_tree_grid(fixed_order=['r1', 'r2', 'r0', 'r3', 'r4'], fixed_position=[0.5, 1, 2.5, 3, 5])

# draw multitree with tips in specific order AND spacing **randomly jittered by x amount.**
mtre = toytree.mtree([toytree.rtree.rtree(5) for i in range(10)])
mtre.draw_tree_grid(fixed_order=['r1', 'r2', 'r0', 'r3', 'r4'], fixed_position=0.5)
eaton-lab commented 4 years ago

Now implemented in v.2.0, now up on conda-forge!