Nodes and branches¶
This will describe node and branchbased methods.
Node methods¶

phylotree.
get_nodes
()¶ Get an array of all nodes.
Returns: Array – Nodes in the current phylotree
.

phylotree.
descendants
(n)¶ Get all descendants of a given node.
Arguments:  node (Node) – A node in the current phylotree.
Returns: Array – An array of descendant nodes.

phylotree.
collapse_node
(n)¶ Collapses a given node.
Arguments:  node (Node) – A node to be collapsed.

phylotree.
style_nodes
([attr])¶ Get or set node styler. If setting, pass a function of two arguments,
element
anddata
.data
exposes the underlying node so that its attributes can be referenced. These can be used to apply styles toelement
, which will be a D3 selection corresponding to the SVG element that makes up the current node.Arguments:  attr (function) – Optional; if setting, the node styler function to be set.
Returns: The
node_styler
function if getting, or the currentphylotree
if setting.

phylotree.
node_span
([attr])¶ Get or set the current node span. If setting, the argument should be a function of a node which returns a number, so that node spans can be determined dynamically. Alternatively, the argument can be the string
"equal"
, to give all nodes an equal span.Arguments:  attr (function) – Optional; if setting, the node_span function.
Returns: The
node_span
if getting, or the currentphylotree
if setting.

phylotree.
delete_a_node
(index)¶ Delete a given node.
Arguments:  The (Node) – node to be deleted, or the index of such a node.
Returns: The current
phylotree
.

phylotree.
traverse_and_compute
(callback, traversal_type)¶ Traverse the tree in a prescribed order, and compute a value at each node.
Arguments:  callback (function) – A function to be called on each node.
 traversal_type (String) – Either
"preorder"
or"postorder"
.

phylotree.
reroot
(node)¶ Reroot the tree on the given node.
Arguments:  node (Node) – Node to reroot on.
Returns: Phylotree – The current
phylotree
.

phylotree.
toggle_collapse
(node)¶ Toggle collapsed view of a given node. Either collapses a clade into a smaller blob for viewing large trees, or expands a node that was previously collapsed.
Arguments:  node (Node) – The node to toggle.
Returns: Phylotree – The current
phylotree
.
Branch methods¶

phylotree.
style_edges
([attr])¶ Get or set edge styler. If setting, pass a function of two arguments,
element
anddata
.data
exposes the underlying edge so that its attributes can be referenced. These can be used to apply styles toelement
, which will be a D3 selection corresponding to the SVG element that makes up the current edge.Note that, in accordance with the D3 hierarchy layout, edges will have a
source
andtarget
field, corresponding to the nodes that make up up the associated branch.Arguments:  attr (function) – Optional; if setting, the node styler function to be set.
Returns: The
edge_styler
function if getting, or the currentphylotree
if setting.

phylotree.
branch_length
([attr])¶ Get or set branch length accessor.
Arguments:  attr (function) – Empty if getting, or new branch length accessor if setting.
Returns: Object – The branch length accessor if getting, or the current phylotree if setting.