Package newick

import ""

Overview ▾

Package newick provides facilities for reading and writing trees in the Newick format. The format used is roughly equivalent to the conventions established here: Although, comments and quoted labels are not (yet) implemented.

An informal description of the Newick format can be found here:

Currently, this package only includes a reader, but a writer will be added as needed.

type Reader

type Reader struct {
    // contains filtered or unexported fields

Reader corresponds to the state necessary to read trees from Newick formatted input.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a reader ready for reading trees from `r`.

func (*Reader) ReadAll

func (lx *Reader) ReadAll() ([]*Tree, error)

ReadAll returns all of the Newick trees in the source input. The first error that occurs is returned with no trees. The error is never `io.EOF`.

func (*Reader) ReadTree

func (lx *Reader) ReadTree() (*Tree, error)

ReadTree reads a single tree from the source input. If the end of the input is reached, then a nil `Tree` is returned with `io.EOF` as the error.

type Tree

type Tree struct {
    // All children of this node, which may be empty.
    Children []Tree

    // The label of this node. If it's empty, then this node does
    // not have a name.
    Label string

    // The branch length of this node corresponding to the distance between
    // it and its parent node. If it's `nil`, then no distance exists.
    Length *float64

Tree corresponds to any value representable in a Newick format. Each tree value corresponds to a single node.

func (*Tree) String

func (tree *Tree) String() string

String recursively converts a tree to a string, with whitespace indenting to indicate depth.