Coverage for lingpy/basic/tree.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Basic module for the handling of language trees. """
""" Initialize a star tree for the random tree function. """
""" Create a random tree from a list of taxa.
Parameters ----------
taxa : list The list containing the names of the taxa from which the tree will be created. branch_lengths : bool (default=False) When set to *True*, a random tree with random branch lengths will be created with the branch lengths being in order of the maximum number of the total number of internal branches.
Returns ------- tree_string : str A string representation of the random tree in Newick format.
""" # clone the list in order to avoid that lists used outside the function # suffer from modifications
else: random.uniform(1, nbr))) 0, "(" + penulti_elem + "," + ulti_elem + ")" + ":" + '{0:.2f}'.format( random.uniform(0, nbr))) else:
""" Basic class for the handling of phylogenetic trees.
Parameters ---------- tree : {str file list} A string or a file containing trees in Newick format. As an alternative, you can also simply pass a list containing taxon names. In that case, a random tree will be created from the list of taxa.
branch_lengths : bool (default=False) When set to *True*, and a list of taxa is passed instead of a Newick string or a file containing a Newick string, a random tree with random branch lengths will be created with the branch lengths being in order of the maximum number of the total number of internal branches.
"""
# this is an absolutely nasty hack, but it helps us to maintain # lingpy-specific aspects of cogent's trees and allows us to include # them in our documentation else: else: else: # pragma: no cover # last ditch attempt to try load tmp = LoadTree(tree)
""" Function returns the Robinson-Foulds distance between the two trees.
Parameters ---------- other : lingpy.basic.tree.Tree A tree object. It should have the same number of taxa as the intitial tree. distance : { "grf", "rf", "branch", "symmetric"} (default="grf") The distance which shall be calculated. Select between:
* "grf": the generalized Robinson-Foulds Distance * "rf": the Robinson-Foulds Distance * "symmetric": the symmetric difference between all partitions of the trees """ else:
""" Return the distance from the given node to the root.
Parameters ---------- node : str The name of a given node in the tree.
Returns ------- distance : int The distance of the given node to the root of the tree. """
#def getTransitionMatrix(self): # """ # Return a matrix with two columns for each node in the tree.
# """ # matrix = [] # for name, node in self.getNodesDict().items(): # if node.Parent: # matrix += [[name, node.Parent.Name]]
# return matrix
#def createTransitionMatrix(self, states, tmat): # max_state = max(states)
# matrix = [] # counter = 0 # for i in range(self._edge_len): # if tmat[i][0] in self.taxa: # matrix += [states[counter]] # counter += 1 # else: # matrix += [[random.randint(0, max_state), random.randint(0, max_state)]] # return matrix |