tree

package
v0.0.0-...-eeaf01f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2021 License: GPL-2.0 Imports: 8 Imported by: 3

Documentation

Overview

Package tree implements tree structure and newick parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSpecial

func IsSpecial(c rune) bool

IsSpecial returns true if character is a special character (i.e. not identifier).

func NewickSplit

func NewickSplit(data []byte, atEOF bool) (advance int, token []byte, err error)

NewickSplit is a function parsing a newick-formatted data.

Types

type Mode

type Mode int

Mode is a newick parsing mode variable.

const (
	// Default parsing mode.
	NORMAL Mode = iota
	// Parsing branch length.
	LENGTH
	// Parsing node class.
	CLASS
)

Newick parsing modes.

type Node

type Node struct {
	// Name is the node label.
	Name string
	// BranchLength is the length of the  branch going to the node.
	BranchLength float64
	// Parent is the parent node (nil for the root).
	Parent *Node

	// Id is the node ID.
	ID int
	// LeafId is the leaf id.
	LeafID int
	// Class is a node class (specified by # symbol in newick).
	Class int
	// contains filtered or unexported fields
}

Node is a node of a tree.

func NewNode

func NewNode(parent *Node, nodeID int) (node *Node)

NewNode creates a new Node.

func (*Node) AddChild

func (node *Node) AddChild(subNode *Node)

AddChild adds a child node.

func (*Node) BrString

func (node *Node) BrString() (s string)

BrString returns a newick string with branch labels for a node and its' subnodes.

func (*Node) ChildNodes

func (node *Node) ChildNodes() []*Node

ChildNodes returns a children nodes slice.

func (*Node) ClassString

func (node *Node) ClassString() (s string)

ClassString returns a newick string with class labels for a node and its' subnodes.

func (*Node) Copy

func (node *Node) Copy() *Node

Copy creates copy of node with empty parent and children.

func (*Node) FullString

func (node *Node) FullString() string

FullString returns extended string for the whole tree.

func (*Node) IsRoot

func (node *Node) IsRoot() bool

IsRoot returns true if current node is a root.

func (*Node) IsTerminal

func (node *Node) IsTerminal() bool

IsTerminal returns true if node is a leaf.

func (*Node) LongString

func (node *Node) LongString() (s string)

LongString returns an extended string with all the ids, classes, etc for one node.

func (*Node) NSubNodes

func (node *Node) NSubNodes() (size int)

NSubNodes returns a total number of subnodes for a current node.

func (*Node) ShortClassString

func (node *Node) ShortClassString() (s string)

ShortClassString returns a newick string with class labels for a node and its' subnodes without branch lengths.

func (*Node) String

func (node *Node) String() (s string)

String returns a newick string for a node and its' subnodes.

func (*Node) Walk

func (node *Node) Walk(ch chan *Node, filter func(*Node) bool)

Walk traverses the tree nodes and sends them into a channel. An optional filtering function may be provided.

type Tree

type Tree struct {
	// Node is the root node.
	*Node
	// contains filtered or unexported fields
}

Tree is a tree structure.

func ParseNewick

func ParseNewick(rd io.Reader) (tree *Tree, err error)

ParseNewick parses a newick formatted reader into the Tree type.

func (*Tree) ClassNodes

func (tree *Tree) ClassNodes(class int) <-chan *Node

ClassNodes returns a channel with all the nodes of a given class.

func (*Tree) ClearCache

func (tree *Tree) ClearCache()

ClearCache clears all precomputed parameters.

func (*Tree) Copy

func (tree *Tree) Copy() (newTree *Tree)

Copy creates independent copy of the tree.

func (*Tree) IsRooted

func (tree *Tree) IsRooted() bool

IsRooted returns true if the tree is rooted (i.e. bifurcation at the root).

func (*Tree) MaxNodeID

func (tree *Tree) MaxNodeID() (maxID int)

MaxNodeID returns maximum id of a node.

func (*Tree) NLeaves

func (tree *Tree) NLeaves() (i int)

NLeaves returns number of leaves.

func (*Tree) NNodes

func (tree *Tree) NNodes() int

NNodes returns number of nodes.

func (*Tree) NodeIDArray

func (tree *Tree) NodeIDArray() []*Node

NodeIDArray returns an array (slice). This array allows addressing nodes by their ids.

func (*Tree) NodeOrder

func (tree *Tree) NodeOrder() []*Node

NodeOrder returns an array (slice) with non-terminal nodes in post-order.

func (*Tree) NonTerminals

func (tree *Tree) NonTerminals() <-chan *Node

NonTerminals returns a channel with all the non-terminal nodes of a tree.

func (*Tree) Root

func (tree *Tree) Root(branchID int) error

Root roots the tree by replacing trifurcation at the root by a bifurcation.

func (*Tree) Terminals

func (tree *Tree) Terminals() <-chan *Node

Terminals returns a channel with all the terminal nodes of a tree.

func (*Tree) Unroot

func (tree *Tree) Unroot() (int, error)

Unroot unroots the tree (i.e. replaces bifurcation at the root with a trifurcation).

func (*Tree) Walker

func (tree *Tree) Walker(filter func(*Node) bool) <-chan *Node

Walker returns a channel iterating over nodes. An optional function is provided to filter nodes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL