cogent3.core.tree.PhyloNode#
- class PhyloNode(*args, **kwargs)#
- Attributes:
- length
parent
Accessor for parent.
Methods
ancestors
()Returns all ancestors back to the root.
append
(i)Appends i to self.children, in-place, cleaning up refs.
ascii_art
([show_internal, compact])Returns a string containing an ascii drawing of the tree.
balanced
()Tree 'rooted' here with no neighbour having > 50% of the edges.
bifurcating
([eps, constructor, name_unnamed])Wrap multifurcating with a num of 2
child_groups
()Returns list containing lists of children sharing a state.
child_parent_map
()return dict of {<child name>: <parent name>, ...}
compare_by_names
(other)Equality test for trees by name
compare_by_subsets
(other[, exclude_absent_taxa])Returns fraction of overlapping subsets where self and other differ.
compare_by_tip_distances
(other[, sample, ...])Compares self to other using tip-to-tip distance matrices.
compare_name
(other)Compares TreeNode by name
copy
([memo, _nil, constructor])Returns a copy of self using an iterative approach
copy_topology
([constructor])Copies only the topology and labels of a tree, not any extra data.
deepcopy
([memo, _nil, constructor])Returns a copy of self using an iterative approach
descendant_array
([tip_list])Returns numpy array with nodes in rows and descendants in columns.
distance
(other)Returns branch length between self and other.
extend
(items)Extends self.children by items, in-place, cleaning up refs.
get_connecting_edges
(name1, name2)returns a list of edges connecting two nodes.
get_connecting_node
(name1, name2)Finds the last common ancestor of the two named edges.
get_distances
([endpoints])The distance matrix as a dictionary.
get_edge_names
(tip1name, tip2name[, clade, ...])Return the list of stem and/or sub tree (clade) edge name(s).
get_edge_vector
([include_root])Collect the list of edges in postfix order
get_figure
([style])gets Dendrogram for plotting the phylogeny
get_max_tip_tip_distance
()Returns the max tip-to-tip distance between any pair of tips
get_newick
([with_distances, semicolon, ...])Return the newick string of node and its descendents
get_node_names
([includeself, tipsonly])Return a list of edges from this edge - may or may not include self.
get_nodes_dict
()Returns a dict keyed by node name, value is node
get_param_value
(param, edge)returns the parameter value for named edge
get_sub_tree
(name_list[, ignore_missing, ...])A new instance of a sub tree that contains all the otus that are listed in name_list.
get_tip_names
([includeself])return the list of the names of all tips contained by this edge
get_xml
()Return XML formatted tree string.
index_in_parent
()Returns index of self in parent.
insert
(index, i)Inserts an item at specified position in self.children.
is_root
()Returns True if the current is a root, i.e. has no parent.
is_tip
()Returns True if the current node is a tip, i.e. has no children.
isroot
()Returns True if root of a tree, i.e. no parent.
istip
()Returns True if is tip, i.e. no children.
iter_nontips
([include_self])Iterates over nontips descended from self, [] if none.
iter_tips
([include_self])Iterates over tips descended from self, [] if self is a tip.
last_common_ancestor
(other)Finds last common ancestor of self and other, or None.
lca
(other)Finds last common ancestor of self and other, or None.
levelorder
([include_self])Performs levelorder iteration over tree
lin_rajan_moret
(tree2)return the lin-rajan-moret distance between trees
lowest_common_ancestor
(tipnames)Lowest common ancestor for a list of tipnames
make_tree_array
([dec_list])Makes an array with nodes in rows and descendants in columns.
max_tip_tip_distance
()returns the max distance between any pair of tips
multifurcating
(num[, eps, constructor, ...])return a new tree with every node having num or few children
name_unnamed_nodes
()sets the Data property of unnamed nodes to an arbitrary value
non_tip_children
()Returns direct children in self that have descendants.
nontips
([include_self])Returns nontips descended from self.
pop
([index])Returns and deletes child of self at index (default: -1)
postorder
([include_self])performs postorder iteration over tree.
pre_and_postorder
([include_self])Performs iteration over tree, visiting node before and after.
preorder
([include_self])Performs preorder iteration over tree.
prune
()Reconstructs correct tree after nodes have been removed.
reassign_names
(mapping[, nodes])Reassigns node names based on a mapping dict
remove
(target)Removes node by name instead of identity.
remove_deleted
(is_deleted)Removes all nodes where is_deleted tests true.
remove_node
(target)Removes node by identity instead of value.
root
()Returns root of the tree self is in.
root_at_midpoint
()return a new tree rooted at midpoint of the two tips farthest apart
rooted_at
(edge_name)Return a new tree rooted at the provided node.
rooted_with_tip
(outgroup_name)A new tree with the named tip as one of the root's children
same_shape
(other)Ignores lengths and order, so trees should be sorted first
same_topology
(other)Tests whether two trees have the same topology.
scale_branch_lengths
([max_length, ultrametric])Scales BranchLengths in place to integers for ascii output.
separation
(other)Returns number of edges separating self and other.
set_max_tip_tip_distance
()Propagate tip distance information up the tree
set_param_value
(param, edge, value)set's the value for param at named edge
set_tip_distances
()Sets distance from each node to the most distant tip.
siblings
()Returns all nodes that are children of the same parent as self.
sorted
([sort_order])An equivalent tree sorted into a standard order.
subset
()Returns set of names that descend from specified node
subsets
()Returns all sets of names that come from specified node and its kids
tip_children
()Returns direct children of self that are tips.
tip_to_tip_distances
([endpoints, default_length])Returns distance matrix between all pairs of tips, and a tip order.
tips
([include_self])Returns tips descended from self, [] if self is a tip.
tips_within_distance
(distance)Returns tips within specified distance from self
to_json
()returns json formatted string {'newick': with edges and distances, 'edge_attributes': }
to_rich_dict
()returns {'newick': with node names, 'edge_attributes': {'tip1': {'length': ...}, ...}}
total_descending_branch_length
()Returns total descending branch length from self
total_length
()returns the sum of all branch lengths in tree
traverse
([self_before, self_after, include_self])Returns iterator over descendants.
tree_distance
(other[, method])Return the specified tree distance between this and another tree.
unrooted
()A tree with at least 3 children at the root.
write
(filename[, with_distances, format])Save the tree to filename
get_node_matching_name
unrooted_deepcopy