pylogeny.rearrangement module

Phylogenetic tree structure encapsulation; allow rearrangement of said structure. Tree rearrangements inducing other topologies include Nearest Neighbor Interchange (NNI), Subtree Pruning and Regrafting (SPR), and Tree Bisection and Reconstruction (TBR). Each of these describe a transfer of one node in phylogenetic trees from one parent of a tree to a new parent. Respectively, these operators describe transformations that are subsets of those possible by the successive operator. For example, an NNI operator can perform transformations that are a subset of the transformations possible by the SPR operator.

exception pylogeny.rearrangement.RearrangementError(val)[source]

Bases: exceptions.Exception

__init__(val)[source]
pylogeny.rearrangement.dup(topo, where=None)[source]
class pylogeny.rearrangement.rearrangement(struct, type, targ, dest)[source]

Encapsulates a single rearrangement move of type SPR, NNI, ...

__init__(struct, type, targ, dest)[source]

Initialize by providing a pointer to a base topology, a target branch to be moved, and its destination.

Parameters:
  • struct (a topology object) – a topology object
  • type – the type of movement to perform
  • targ – a target branch
  • dest – a destination branch
doMove()[source]

Commit the move and return the topology.

Returns:a topology object
getType()[source]

Get the type of movement.

Returns:a string
isNNI()[source]
isSPR()[source]
isTBR()[source]
toNewick()[source]

Commit the move but do not create a new structure. Only retrieve resultant Newick string; will be more efficient.

Returns:a Newick string
toTopology()[source]

Commit the actual move and return the topology.

Returns:a new topology object
toTree()[source]

Commit the move and transform to tree object.

Returns:a tree.tree object
class pylogeny.rearrangement.topology(t=None, rerootToLeaf=True, toLeaf=None)[source]

Bases: pylogeny.base.treeStructure

Encapsulate a tree topology, wrapping the newick tree structure as a richer, rooted tree data structure object. Is immutable.

NNI(branch, destination)[source]

Perform an NNI move of a branch to a destination, only if that destination branch is a parent’s parent or a parent’s sibling. Returns a rearrangement structure (not the actual new structure) that can then be polled for the actual move; this is in order to save memory.

Returns:a rearrangement object
SPR(branch, destination)[source]

Perform an SPR move of a branch to a destination branch, creating a new node there. Returns a rearrangement structure (not the actual new structure) that can then be polled for the actual move; this is in order to save memory.

Returns:a rearrangement object
__init__(t=None, rerootToLeaf=True, toLeaf=None)[source]

Initialize structure with a top-level internal node OR nothing.

Parameters:
  • t – a top-level internal node
  • rerootToLeaf – whether to not reroot the structure to a lowest-lexicographic order taxon name
  • toLeaf – reroot to a specifically provided leaf
allNNI()[source]

Consider all valid NNI moves for a given topology and return all possible rearrangements.

Returns:a list of rearrangement objects
allNNIForBranch(br, flip=True)[source]

Consider all valid NNI moves for a given branch in the topology and return all possible rearrangements.

Returns:a list of rearrangement objects
allSPR()[source]

Consider all valid SPR moves for a given topology and return all possible rearrangements.

Returns:a list of rearrangement objects
allSPRForBranch(br, flip=True)[source]

Consider all valid SPR moves for a given branch in the topology and return all possible rearrangements.

Returns:a list of rearrangement objects
allType(type=1)[source]

Consider all valid moves of a given rearrangement operator for a given topology. Uses a given rearrangement operator type defined in this module. For example, calling this function by providing TYPE_NNI as the type will iterate over all NNI operations. By default, the type is TYPE_SPR.

Returns:a list of rearrangement objects
fromNewick(newickstr)[source]

Alias for parse().

getBipartitions()[source]

Get all bipartitions.

Returns:a list of tree.bipartition objects
getBranchFromBipartition(bip)[source]

Given a bipartition object, return a branch that creates that partition of taxa.

Parameters:bip (a tree.bipartition object) – a bipartition
Returns:a newick.branch object
getBranchFromStrBipartition(bip)[source]

Given a bipartition of taxa, return a branch that creates that partition of tree taxa.

Parameters:bip – a tuple of taxa names
Returns:a newick.branch object
getBranches()[source]

Return all branches from this topology.

Returns:a list of newick.branch objects
getLeaves()[source]

Return all leaves from this topology.

Returns:a list of newick.node objects
getStrBipartitionFromBranch(br)[source]

Given a branch, return corresponding bipartition.

Parameters:br (a newick.branch object) – a branch
Returns:a tree.bipartition object
iterNNIForBranch(br, flip=True)[source]

Consider all valid NNI moves for a given branch in the topology and and yield all possible rearrangements as a generator.

Returns:a generator of rearrangement objects
iterSPRForBranch(br, flip=True)[source]

Consider all valid SPR moves for a given branch in the topology and yield all possible rearrangements as a generator.

Returns:a generator of rearrangement objects
iterTypeForBranch(br, type=1, flip=True)[source]

Iterate over all possible rearrangements for a branch using a given rearrangement operator type defined in this module. For example, calling this function by providing TYPE_NNI as the type will iterate over all NNI operations. By default, the type is TYPE_SPR.

lockBranch(branch)[source]

Given a branch, lock it such that no transitions can ever occur across it.

Parameters:branch (a newick.branch object) – a branch
Returns:a boolean (True if success)
move(branch, destination, returnStruct=True)[source]

Move a branch and attach to a destination branch. Return new structure, or return merely the resultant Newick string.

Returns:a topology object or a Newick string
parse(newickstr)[source]

Parse a newick string and assign the tree to this object. Cannot already be initialized with a tree.

Returns:None
rerootToLeaf(toleaf=None)[source]

Reroots the given tree structure such that it is rooted nearest the lowest-order leaf or a provided leaf.

Parameters:toleaf (a newick.node object) – a leaf node from this topology
toNewick()[source]

Return the newick string of the tree.

Returns:a Newick string (rooted)
toTree()[source]

Return the tree object for this topology.

Returns:a new tree.tree object
toUnrootedNewick()[source]

Return the newick string of the tree as an unrooted topology with a multifurcating top-level node.

Returns:a Newick string (unrooted)
toUnrootedTree()[source]

Return the tree object of the unrooted version of this topology.

Previous topic

pylogeny.pll module

Next topic

pylogeny.scoring module

This Page