NewickReader
in package
implements
NewickReaderInterface
A small recursive-descent parser over the Newick grammar (J. Felsenstein's specification) : tree := subtree ";" subtree := ("(" subtree ("," subtree)* ")")? label? (":" number)? Blanks, tabs and newlines may appear anywhere but inside an unquoted label or a branch length, and so may comments in square brackets, NHX annotations ("[&&NHX:S=human]") included : both are skipped. A quoted label ('Homo sapiens (human)') may hold any character, a single quote being written twice. An unquoted label runs until the next structural character, blank or comment.
Underscores are kept as they are : the specification reads them as blanks, but Biopython and ape do not, and identifiers such as "seq_1" must still match the sequences they name. Class NewickReader
Tags
Table of Contents
Interfaces
- NewickReaderInterface
- Interface NewickReaderInterface - parses a Newick string into a PhylogeneticNode tree. Only one tree per call is supported ; a file holding several trees, one per line, is read by calling read() once per line.
Constants
- STRUCTURAL_CHARACTERS : mixed = "(),:;["
Methods
- read() : PhylogeneticNode
- parseBranchLength() : float|null
- parseLabel() : string|null
- Reads a node's label : quoted, with '' standing for a single quote, or unquoted. A node with no label has none (null) ; an empty quoted label ('') is an empty name, which toNewick() writes for a node named "".
- parseSubtree() : PhylogeneticNode
- parseToken() : string
- Reads characters up to the next structural character, blank or comment ; used for an unquoted name and for a branch length.
- skipBlanksAndComments() : void
- Steps over blanks, tabs, newlines and [comments].
Constants
STRUCTURAL_CHARACTERS
private
mixed
STRUCTURAL_CHARACTERS
= "(),:;["
Methods
read()
public
read(string $sNewick) : PhylogeneticNode
Parameters
- $sNewick : string
Tags
Return values
PhylogeneticNodeparseBranchLength()
private
parseBranchLength(string $sBody, int &$iPosition) : float|null
Parameters
- $sBody : string
- $iPosition : int
Return values
float|null —Null when no ":" is present at the current position
parseLabel()
Reads a node's label : quoted, with '' standing for a single quote, or unquoted. A node with no label has none (null) ; an empty quoted label ('') is an empty name, which toNewick() writes for a node named "".
private
parseLabel(string $sBody, int &$iPosition) : string|null
Parameters
- $sBody : string
- $iPosition : int
Tags
Return values
string|nullparseSubtree()
private
parseSubtree(string $sBody, int &$iPosition) : PhylogeneticNode
Parameters
- $sBody : string
- $iPosition : int
-
Advanced past whatever was consumed
Return values
PhylogeneticNodeparseToken()
Reads characters up to the next structural character, blank or comment ; used for an unquoted name and for a branch length.
private
parseToken(string $sBody, int &$iPosition) : string
Parameters
- $sBody : string
- $iPosition : int
Return values
stringskipBlanksAndComments()
Steps over blanks, tabs, newlines and [comments].
private
skipBlanksAndComments(string $sBody, int &$iPosition) : void
Parameters
- $sBody : string
- $iPosition : int