pylogeny.tree module

Container definition for (phylogenetic) bifurcating or multifurcating trees defined using Newick strings, collections of them, and for splits of these trees.

class pylogeny.tree.bipartition(topol, bra=None)[source]

Bases: object

A tree bipartition. Requires a tree topology. Using the term borrowed from nomenclature of a bipartite graph, a bipartition for a phylogenetic tree coincides with the definition of two disjoint sets U and V . A branch in a phylogenetic tree defines a single bipartition that divides the tree into two disjoint sets U and V . The set U comprises all of the children leaf of the subtree associated with that branch. The set V contains the rest of the leaves or taxa in the tree.

__init__(topol, bra=None)[source]

Construct a bipartition from a branch in a topology.

Parameters:
fromStringRepresentation(st)[source]

Acquire all component elements from a string representation of a bipartition.

Parameters:st – A string representation from a tree.bipartition object.
getBestSPRScore(ls, node=None)[source]

Given a landscape, return the best SPR score.

getBranch()[source]

Get branch corresponding to this bipartition.

Returns:newick.branch
getBranchIndex()[source]

Return an index of the branch with respect to a post order traversal of the topology.

Returns:an integer
getBranchListRepresentation()[source]

Get the tuple of lists of branches that represent this bipartition.

getMedianSPRScore(ls, node=None)[source]

Given a landscape, return the median SPR score.

getSPRRearrangements()[source]

Return the set of all scores related to this bipartition.

getSPRScores(ls, node=None)[source]

Given a landscape, return all possible scores, not actively performing scoring if not done.

getShortStringMappings()[source]

Get the mapping of symbols from taxa names for the shorter string representation.

getShortStringRepresentation()[source]

Get the shorter string representation corresponding to this bipartition.

Returns:a string
getStringRepresentation()[source]

Get the string representation corresponding to this bipartition.

Returns:a string
pylogeny.tree.median(lst)[source]
pylogeny.tree.numberRootedTrees(t)
pylogeny.tree.numberUnrootedTrees(t)
class pylogeny.tree.tree(newi='', check=False, structure=None)[source]

Bases: object

Represents a single (phylogenetic) tree by Newick string; can possess other metadata. For manipulation of tree structure, such as rerooting and unrooting, convert this object to a topology.

__init__(newi='', check=False, structure=None)[source]

If enabled, “check” will force the structure to reroot the given Newick string tree to a lowest-order leaf in order to ensure a consistent Newick string among any duplicate topologies. If a structure is provided and check is disabled, all parsing routines are bypassed and the Newick and Structure fields of this tree are overriden by the appropriate arguments.

Parameters:
  • newi (a string) – a Newick or New Hampshire string for a tree
  • check (a boolean) – perform parsing checks on the string input
getName()[source]

Gets the name of this tree if it has been defined.

Returns:a string
getNewick()[source]

Gets the Newick (New Hampshire) string for this tree.

Returns:a string
getOrigin()[source]

Gets the “origin” of this tree, or where this tree was acquired or constructed from. Usually set by other code or an interface.

Returns:string or None
getRerootedNoBranchLengthNewick()[source]

Returns the tree’s “structure”, a Newick string without any branch lengths.

Returns:a string
getScore()[source]

Gets the score(s) (objective function) for this tree if it/they has/have been defined.

Returns:a tuple of floats or integers
getSimpleNewick()[source]

Return a Newick string with all taxa name replaced with successive integers.

Returns:a string
getStructure()[source]

Returns the tree’s “structure”, a Newick string without any branch lengths.

Returns:a string
setName(n)[source]

Sets the name of this tree (object).

Parameters:n (a string) – a string indicating this tree’s name
setOrigin(o)[source]

Set the “origin” or specification of where this tree was acquired or constructed from.

Parameters:o (string or None) – a string indicating where the tree came from
setScore(s)[source]

Sets the score(s) for this tree. Should be performed by a scorer (see scoring functions in the appropriate module).

Parameters:s (a tuple of floats or integers) – a set of objective function scores.
toDendroPy()[source]

Convert the tree object to a DendroPy tree object. Requires DendroPy to be installed on the system.

Returns:a DendroPy Tree object or None if DendroPy not on system
toNewick()[source]

Gets the Newick (New Hampshire) string for this tree.

Returns:a string
toTopology()[source]

Return a topology object instance for this tree to allow for rearrangement of the actual structure of the tree.

Returns:a rearrangement.topology object
updateNewick(n, reroot=False)[source]

Update the contained Newick string only as long as the structure obtained (after rerooting, which is an optional parameter) is identical to the contained structure.

Parameters:
  • n (a string) – A Newick or New Hampshire formatted string.
  • reroot (a boolean) – reroot to lexicographically lowest-order leaf.
class pylogeny.tree.treeSet[source]

Bases: _abcoll.Sized, _abcoll.Iterable

Represents an ordered, disorganized collection of trees that do not necessarily comprise a combinatorial space.

__init__()[source]
addTree(tr)[source]

Add a tree object to the collection.

Parameters:tr (tree.tree) – A tree object.
addTreeByNewick(newick)[source]

Add a tree to the structure by Newick string.

Parameters:newick (a string) – A New Hampshire or Newick string.
static fromTreeFile(fin)[source]

Acquire a file where newlines separate Newick strings, and create an instance of treeSet from those trees.

indexOf(tr)[source]

Acquire the index in this collection of a tree object. Returns -1 if not found.

Parameters:tr (tree.tree) – A tree object.
Returns:an integer [-1,length of collection)
iterTrees()[source]

Iterate over all trees found in this set.

removeTree(tr)[source]

Remove a tree object from the collection if present.

Parameters:tr (tree.tree) – A tree object (present in the collection).
toTreeFile(fout)[source]

Output this landscape as a series of trees, separated by newlines, as a text file saved at the given path.

Parameters:fout (a string) – A string indicating a file system path to a file.

Previous topic

pylogeny.scoring module

This Page