Encapsulate a phylogenetic tree space. A phylogenetic landscape or tree space refers to the entire combinatorial space comprising all possible phylogenetic tree topologies for a set of n taxa. The landscape of n taxa can be defined as consisting of a finite set T of tree topologies. Tree topologies can be associated with a fitness function f(t_i) describing their fit. This forms a discrete solution search space and finite graph (T, E) = G. E(G) refers to the neighborhood relation on T(G). Edges in this graph are bidirectional and represent transformation from one tree topology to another by a tree rearrangement operator. An edge between t_i and t_j would be notated as e_{ij} in E(G).
Bases: object
Define an empty graph object.
Instantiate a graph. Default edge weights are 0.
| Parameters: |
|
|---|
Return in- and out-degree for node named i.
| Parameters: | i (a string) – a node name |
|---|---|
| Returns: | an integer |
Get the data associated with an edge (including weight).
| Parameters: |
|
|---|---|
| Returns: | an edge (and associated data) |
Get all edges (as defined for NetworkX graphs). Recommended to use an iterator for large graphs.
| Returns: | a list of edges (and associated data) |
|---|
Get all edges associated with a certain node.
| Parameters: | i (a string) – a node name |
|---|---|
| Returns: | a list of edges (and associated data) for all neighbors |
Get a list of all node names neighbor to a node.
| Parameters: | i (a string) – a node name |
|---|---|
| Returns: | a list of strings (node names) |
Get a single node by name.
| Parameters: | i (a string) – a node name: |
|---|---|
| Returns: | a dictionary (with node information) |
Get all node values. Recommended to use an iterator for large graphs (iterNodes()).
| Returns: | a list of node values (whatever is associated with nodes) |
|---|
Bases: pylogeny.landscape.graph, pylogeny.tree.treeSet
Defines an entire phylogenetic tree space.
Initialize the landscape.
| Parameters: |
|
|---|
Add a tree to the landscape. Will return its index.
| Parameters: |
|
|---|---|
| Returns: | the index of the tree |
Add tree to the landscape by Newick string. Will return index.
| Parameters: |
|
|---|---|
| Returns: | the index of the tree |
Acquire a single neighbor to a tree in the landscape by performing a random rearrangement of type SPR (by default), NNI, or TBR – this is done by performing a rearrangement on a random branch in the topology. Rearrangement type is provided as a rearrangement module type definition of form, for example, TYPE_SPR, TYPE_NNI, etc.
| Parameters: |
|
|---|---|
| Returns: | the new tree index or None in case of failure |
Get all neighbors to a tree named i in the landscape using a respective rearrangement operator as defined in the rearrangement module. Rearrangement type is provided as a rearrangement module type definition of form, for example, TYPE_SPR, TYPE_NNI, etc. By default, this is TYPE_SPR.
| Parameters: |
|
|---|---|
| Returns: | a list of neighbors as tree names (usually integers) |
Find a tree by Newick string, taking into account branch lengths. Returns the index of this tree in the landscape. Warning: naively performs a sequential search.
| Parameters: | newick (a string) – a Newick string |
|---|---|
| Returns: | a tree name (usually an integer index) or None if not found |
Find a tree by topology, not taking into account branch lengths.
| Parameters: | newick (a string) – a Newick string |
|---|---|
| Returns: | a tree name (usually an integer index) or None if not found |
Find a tree by topology, not taking into account branch lengths, given the topology.
| Parameters: | struct (a string) – a Newick string without branch lengths (a “structure”) |
|---|---|
| Returns: | a tree name (usually an integer index) or None if not found |
Acquire the alignment object associated with this space.
| Returns: | an alignment.alignment object |
|---|
Return all paths of best improvement as a dictionary.
| Returns: | a dictionary of tree name to paths (lists of tree names) |
|---|
For a tree in the landscape, investigate neighbors to find a tree that leads to the best improvement of fitness function score on the basis of likelihood.
| Parameters: | i – a tree name (usually an integer) |
|---|---|
| Returns: | a tree name (usually an integer) or None if no better tree |
Given a tree node and a branch index, return the associated bipartition.
| Parameters: |
|
|---|---|
| Returns: | a tree.bipartition object |
Get the global optimum of the current space.
| Returns: | a tree name (usually an integer) |
|---|
Get all trees in the landscape that can be labelled as a local optimum.
| Returns: | a list of tree names (usually integers) |
|---|
Get all restrictions (locks which cannot be violated on splits).
| Returns: | a list of tree.bipartition objects |
|---|
Return the number of different taxa present in any respective tree in the landscape.
| Returns: | an integer |
|---|
For a tree in the landscape, investigate neighbors iteratively until a best path of score improvement is found on basis of likelihood.
| Parameters: | i – a tree name (usually an integer) |
|---|---|
| Returns: | a list of tree names (usually integers) |
Assuming all of the trees in the space are rooted, return the maximum possible number of unrooted trees that can possibly be generated for the number of taxa of trees in the landscape.
| Returns: | an integer |
|---|
Assuming all of the trees in the space are unrooted, return the maximum possible number of unrooted trees that can possibly be generated for the number of taxa of trees in the landscape.
| Returns: | an integer |
|---|
Returns the root (starting) tree of the space in its node form.
| Returns: | a dictionary (with node information) |
|---|
Acquire the first tree that was placed in this space.
| Returns: | a tree.tree object |
|---|
Get the object for a tree by its name.
| Parameters: | i – a tree name (usually an integer) |
|---|---|
| Returns: | a tree.tree object |
Acquire a vertex object from the landscape; this is a high-level representation of a tree in the landscape with additional functionality. Object created upon invocation of this function.
| Parameters: | i – a tree name (usually an integer) |
|---|---|
| Returns: | a vertex object |
Acquire the index/name in this landscape of a tree object. Returns -1 if not found. Warning: naively performs a sequential search.
| Parameters: | tr (a tree.tree object) – a tree |
|---|---|
| Returns: | a tree name (usually an integer index) or -1 if not found |
Determine if a tree is a local optimum. This means it has the following properties:
- Possesses a likelihood score.
- Local neighborhood completely enumerated (and scored).
- None of its neighbors is a better improvement.
| Returns: | a boolean |
|---|
Determine if a tree is violating any locks intrinsic to the landscape. Will also return False if the tree (name) is not present in the landscape.
| Parameters: | i – a tree name (usually an integer) |
|---|
Return an iterator for all paths of best improvement.
| Returns: | a generator of paths (lists of tree names) |
|---|
Given a tree node and a branch object, add a given bipartition to the bipartition lock list. Returns bipartition if locked.
| Parameters: |
|
|---|---|
| Returns: | a tree.bipartition object that has been locked or None |
Given a tree node and a branch index, add an associated bipartition to the bipartition lock list. Returns the bipartition if locked.
| Parameters: |
|
|---|---|
| Returns: | a tree.bipartition object if it has been locked |
Remove a tree from the landscape by object.
| Parameters: | tree (a tree.tree object) – a tree that exists in the landscape |
|---|---|
| Returns: | a boolean (success or failure) |
Remove a tree from the landscape by index.
| Parameters: | i – a tree name (usually an integer) |
|---|---|
| Returns: | a boolean (success or failure) |
Set the alignment present in this landscape. WARNING; will not modify existing scores.
| Parameters: | ali (an alignment.alignment object) – an alignment |
|---|
Set the operator assigned to this landscape.
| Parameters: | op (a string) – an operator (string description) |
|---|
Convert this landscape into an unorganized set of trees where taxa names are transformed to their original form (i.e. not transformed to a state friendly for the Phylip format).
| Returns: | a tree.treeSet object |
|---|
Convert this landscape into an unorganized set of trees.
| Returns: | a tree.treeSet object |
|---|
Add a biparition to the list of locked bipartitions if not present; otherwise, remove it. Return status of lock.
| Parameters: | lock (a tree.bipartition object) – a bipartition that cannot be violated |
|---|---|
| Returns: | a boolean (on or off) |
Bases: object
Encapsulate a single vertex in the landscape and add convenient functionality to alias parent landscape functions.
Approximate the possible number of neighbors to this vertex by considering the type of tree rearrangement operator. Returns LS_NOT_DEFINED if the operator is not known yet.
| Returns: | an integer |
|---|
Get all bipartitions for this vertex.
| Returns: | a list of tree.bipartition objects |
|---|
Get the dictionary object (key-value pairs) associated with this tree as it is in the NetworkX graph.
| Returns: | a dictionary |
|---|
Get the index of this tree in the space.
| Returns: | a tree name (usually an integer) |
|---|
Get any neighbors to this tree in the landscape.
| Returns: | a list of tree names (usually integers) |
|---|
Get corresponding neighbors of a bipartition in this vertex’s tree.
Get the dictionary object (key-value pairs) associated with this tree as it is in the NetworkX graph.
| Returns: | a dictionary |
|---|
Get (any) score(s) associated with this tree.
| Returns: | a tuple of floating point values (scores) |
|---|
Check to see if this vertex is a best move for another node.
| Returns: | a boolean |
|---|
See if this tree has had all possible rearrangements performed.
| Returns: | a boolean |
|---|