pylogeny.newick module
Newick string parsing and object interaction. A Newick string can represent
a phylogenetic tree.
-
exception pylogeny.newick.ParsingError(val)[source]
Bases: exceptions.Exception
-
__init__(val)[source]
-
pylogeny.newick.assignParents(top)[source]
Should be a one-time use function. Goes through
and assigns parents to the parsed newick tree structure
nodes and branches to allow for up-traversal.
| Parameters: | top (a node object) – a top-level node for a tree (root node) |
-
class pylogeny.newick.branch(chi, l, parent=None, s=None)[source]
Bases: pylogeny.base.treeBranch
Branch for a tree parsed from a Newick string.
-
__init__(chi, l, parent=None, s=None)[source]
Initialize a branch in a tree parsed from a Newick string.
| Parameters: |
- chi (a node object) – a child node
- l (a floating point value) – a branch length
- parent (a node object) – an optional parent node; default none
|
-
pylogeny.newick.getAllBranches(br)[source]
Given a branch, traverse subtree and return
comprising branches as a list.
| Parameters: | br (a branch object) – a branch from a tree |
-
pylogeny.newick.getBalancingBracket(newick, i)[source]
Given a position of an opening bracket in a
newick string, i, output the closing bracket’s
position that corresponds to this opening bracket.
| Parameters: |
- newick (a string) – a Newick string
- i (an integer < length of the string) – a position in the string (index)
|
| Returns: | an integer
|
-
pylogeny.newick.getBranchLength(newick, i)[source]
Given a position of a colon symbol (indicating a
branch length), return the branch length.
| Parameters: |
- newick (a string) – a Newick string
- i (an integer < length of the string) – a position in the string (index)
|
| Returns: | an integer
|
-
pylogeny.newick.getLeafName(newick, i)[source]
Given the position of a leaf, find its complete name.
| Parameters: |
- newick (a string) – a Newick string
- i (an integer < length of the string) – a position in the string (index)
|
| Returns: | an integer
|
-
pylogeny.newick.invertAlongPathToNode(target, top)[source]
DANGEROUS: Reverses all directionality to a given
node from a top-level node. Intended as a low-level
function for rerooting a tree.
| Parameters: |
- target (a node object) – a target node
- top (a node object) – a top-level node for a tree (root node)
|
-
pylogeny.newick.isSibling(br, other)[source]
Given a branch, determine if that branch is
adjacent to another branch.
| Parameters: |
- br (a branch object) – a branch from a tree
- other (a branch object) – another branch from a tree
|
-
class pylogeny.newick.newickParser(newick)[source]
Parsing object for Newick strings.
-
__init__(newick)[source]
Initialize this parser (with a Newick string).
| Parameters: | newick (a string) – a Newick string |
-
parse()[source]
Parse the stored newick string into a topological structure.
| Returns: | the top-level root node object |
-
class pylogeny.newick.node(lbl='', children=None, parent=None)[source]
Bases: pylogeny.base.treeNode
Node for a tree parsed from a Newick string.
-
__init__(lbl='', children=None, parent=None)[source]
Initialize a node in a tree parsed from a Newick string.
| Parameters: |
- lbl (a string) – a label for this node
- children (a list of branch objects) – an optional set of children (branches); default none
- parent (a branch object) – an optional parent branch for this node; default none
|
-
pylogeny.newick.parseNewick(newick, i, j, top)[source]
Parse a newick string into a topological newick
structure given a top-level node.
| Parameters: |
- newick (a string) – a Newick string
- i (an integer) – a starting position to start parsing
- j (an integer) – an end position to stop parsing
- top (a node object) – a top-level node; start parsing with None
|
-
pylogeny.newick.removeBranchLengths(top)[source]
Goes through and removes any stored branch lengths.
| Parameters: | top (a node object) – a top-level node for a tree (root node) |
-
pylogeny.newick.removeUnaryInternalNodes(top)[source]
Goes through and ensures any degree-2 internal
nodes are smoothed into a single degree-3 internal
node.
| Parameters: | top (a node object) – a top-level node for a tree (root node) |
-
pylogeny.newick.shuffleLeaves(top)[source]
DANGEROUS: Given a top-level node, shuffle all
leaves in this tree.
| Parameters: | top (a node object) – a top-level node for a tree (root node) |