Documentation

NewickReader 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
author

Amélie DUVERNET aka Amelaye amelieonline@gmail.com

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

parseBranchLength()

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
throws
InvalidNewickException

When a quoted label is never closed

Return values
string|null

parseToken()

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
string

skipBlanksAndComments()

Steps over blanks, tabs, newlines and [comments].

private skipBlanksAndComments(string $sBody, int &$iPosition) : void
Parameters
$sBody : string
$iPosition : int
Tags
throws
InvalidNewickException

When a comment is never closed

On this page

Search results