Documentation ¶
Overview ¶
Package gotree implements a simple library for handling phylogenetic trees in go
Index ¶
- Constants
- func CommonEdges(edges1 []*Edge, edges2 []*Edge, tipEdges bool) (tree1 int, common int, err error)
- func Compare(refTree *Tree, compTrees <-chan Trees, tips, comparetreeidentical bool, ...) (<-chan BipartitionStats, error)
- func NewAllNodeIndex(t *Tree) *nodeIndex
- func NewNodeIndex(t *Tree) (*nodeIndex, error)
- type BipartitionStats
- type Edge
- func (e *Edge) AddComment(comment string)
- func (e *Edge) Bitset() *bitset.BitSet
- func (e *Edge) ClearComments()
- func (e *Edge) Comments() []string
- func (e *Edge) CommentsString() string
- func (e *Edge) DumpBitSet() string
- func (e *Edge) FindEdge(edges []*Edge) (*Edge, error)
- func (e *Edge) HashCode() uint64
- func (e *Edge) HashEquals(h hashmap.Hasher) bool
- func (e *Edge) Id() int
- func (e *Edge) IncrementSupport(support float64)
- func (e *Edge) Inverse()
- func (e *Edge) Left() *Node
- func (e *Edge) Length() float64
- func (e *Edge) LengthString() string
- func (e *Edge) Locality(maxdist int, cutoff float64) (float64, float64, float64, bool, bool)
- func (e *Edge) Name(rooted bool) (nodename string)
- func (e *Edge) NeigborEdges(maxdist int) []*Edge
- func (e *Edge) NumTipsLeft() int
- func (e *Edge) NumTipsRight() int
- func (e *Edge) PValue() float64
- func (e *Edge) Right() *Node
- func (e *Edge) SameBipartition(e2 *Edge) bool
- func (e *Edge) SetId(id int)
- func (e *Edge) SetLength(length float64)
- func (e *Edge) SetPValue(pval float64)
- func (e *Edge) SetSupport(support float64)
- func (e *Edge) Support() float64
- func (e *Edge) SupportString() string
- func (e *Edge) TipPresent(id uint) bool
- func (e *Edge) ToStatsString(withedgecomments bool) string
- func (e *Edge) TopoDepth() (int, error)
- type EdgeIndex
- type EdgeIndexInfo
- type KeyValue
- type NNIRearranger
- type Node
- func (n *Node) AddComment(comment string)
- func (n *Node) ClearComments()
- func (n *Node) Comments() []string
- func (n *Node) CommentsString() string
- func (n *Node) Depth() (int, error)
- func (n *Node) EdgeIndex(e *Edge) (int, error)
- func (n *Node) Edges() []*Edge
- func (n *Node) Id() int
- func (n *Node) IsConnected(next *Node) bool
- func (n *Node) Name() string
- func (n *Node) Neigh() []*Node
- func (n *Node) Newick(parent *Node, newick *bytes.Buffer)
- func (n *Node) Nneigh() int
- func (n *Node) NodeIndex(next *Node) (int, error)
- func (n *Node) Parent() (*Node, error)
- func (n *Node) ParentEdge() (*Edge, error)
- func (n *Node) RotateNeighbors()
- func (n *Node) SetDepth(depth int)
- func (n *Node) SetId(id int)
- func (n *Node) SetName(name string)
- func (n *Node) Tip() bool
- func (n *Node) TipIndex() int
- type NodeIndex
- type Quartet
- type QuartetSet
- type Rearrangement
- type Rearranger
- type TipBag
- type Tree
- func AllTopologies(nbTips int, rooted bool, tipNames ...string) (trees []*Tree, err error)
- func BipartitionTree(leftTips []string, rightTips []string) (*Tree, error)
- func Consensus(trees <-chan Trees, cutoff float64) (*Tree, error)
- func EdgeTree(t *Tree, e *Edge, alltips []string) *Tree
- func NewTree() *Tree
- func RandomBalancedBinaryTree(depth int, rooted bool) (*Tree, error)
- func RandomCaterpillarBinaryTree(nbtips int, rooted bool) (*Tree, error)
- func RandomUniformBinaryTree(nbtips int, rooted bool) (*Tree, error)
- func RandomYuleBinaryTree(nbtips int, rooted bool) (*Tree, error)
- func StarTree(nbtips int) (*Tree, error)
- func StarTreeFromName(names ...string) (*Tree, error)
- func StarTreeFromTree(t *Tree) (*Tree, error)
- func (t *Tree) AddBipartition(n *Node, edges []*Edge, length, support float64) (*Edge, error)
- func (t *Tree) AddQuotes(internals, tips bool, namemap map[string]string) error
- func (t *Tree) AllTipNames() []string
- func (t *Tree) Annotate(names [][]string, comment bool) error
- func (t *Tree) CheckTree() bool
- func (t *Tree) CheckTreePostOrder() (err error)
- func (t *Tree) ClearBitSets() error
- func (t *Tree) ClearComments()
- func (t *Tree) ClearEdgeComments()
- func (t *Tree) ClearLengths()
- func (t *Tree) ClearNodeComments()
- func (t *Tree) ClearPvalues()
- func (t *Tree) ClearSupports()
- func (t *Tree) Clone() *Tree
- func (t *Tree) CollapseLowSupport(support float64, removeRoot bool)
- func (t *Tree) CollapseShortBranches(length float64, removeRoot, removeTips bool)
- func (t *Tree) CollapseTopoDepth(mindepthThreshold, maxdepthThreshold int, removeRoot, removeTips bool) (err error)
- func (t *Tree) CollessIndex() (colless int)
- func (t *Tree) CommonEdges(t2 *Tree, tipEdges bool) (tree1 int, common int, err error)
- func (t *Tree) CompareTipIndexes(t2 *Tree) error
- func (t *Tree) ComputeDepths()
- func (t *Tree) ComputeEdgeHashes(cur, prev *Node, e *Edge)
- func (t *Tree) ConnectNodes(parent *Node, child *Node) *Edge
- func (t *Tree) CopyEdge(e *Edge, copy *Edge)
- func (t *Tree) CopyNode(n *Node) *Node
- func (t *Tree) CutEdgesMaxLength(maxlen float64) (bags []*TipBag, err error)
- func (t *Tree) DeepestEdge() (maxedge *Edge)
- func (t *Tree) DeepestNode() (maxnode *Node)
- func (t *Tree) Delete()
- func (t *Tree) Edges() []*Edge
- func (t *Tree) ExistsTip(name string) (bool, error)
- func (t *Tree) GraftTipOnEdge(n *Node, e *Edge) (*Edge, *Edge, *Node, error)
- func (t *Tree) IndexQuartets(specific bool) *hashmap.HashMap
- func (t *Tree) InsertIdenticalTip(n *Node, newTipName string) (newtipnode *Node, err error)
- func (t *Tree) InsertIdenticalTips(identicalgroups [][]string) (err error)
- func (t *Tree) InternalEdges() []*Edge
- func (t *Tree) LeastCommonAncestorRecur(current *Node, prev *Node, tipIndex map[string]*Node) (*Node, []*Edge, int, int, bool, error)
- func (t *Tree) LeastCommonAncestorRooted(nodeindex *nodeIndex, tips ...string) (*Node, []*Edge, bool, error)
- func (t *Tree) LeastCommonAncestorUnrooted(nodeindex *nodeIndex, tips ...string) (*Node, []*Edge, bool, error)
- func (t *Tree) MeanBranchLength() float64
- func (t *Tree) MeanSupport() float64
- func (t *Tree) MedianSupport() float64
- func (t *Tree) Merge(t2 *Tree) error
- func (t *Tree) NbCherries() (nbcherries int)
- func (t *Tree) NbTips() (int, error)
- func (t *Tree) NewEdge() *Edge
- func (t *Tree) NewNode() *Node
- func (t *Tree) Newick() string
- func (t *Tree) Nexus() string
- func (t *Tree) Nodes() []*Node
- func (t *Tree) PostOrder(f func(cur *Node, prev *Node, e *Edge) (keep bool))
- func (t *Tree) PreOrder(f func(cur *Node, prev *Node, e *Edge) (keep bool))
- func (t *Tree) Quartets(specific bool, it func(q *Quartet))
- func (t *Tree) ReinitIndexes() (err error)
- func (t *Tree) ReinitInternalIndexes()
- func (t *Tree) RemoveEdges(removeRoot, removeTips bool, edges ...*Edge)
- func (t *Tree) RemoveQuotes(internals, tips bool, namemap map[string]string) error
- func (t *Tree) RemoveSingleNodes()
- func (t *Tree) RemoveTips(revert bool, names ...string) error
- func (t *Tree) Rename(namemap map[string]string) error
- func (t *Tree) RenameAuto(internals, tips bool, length int, curid *int, namemap map[string]string) error
- func (t *Tree) RenameRegexp(internals, tips bool, regex, replace string, namemap map[string]string) error
- func (t *Tree) ReorderEdges(n *Node, prev *Node, reversed *[]*Edge) error
- func (t *Tree) Reroot(n *Node) error
- func (t *Tree) RerootFirst() error
- func (t *Tree) RerootMidPoint() error
- func (t *Tree) RerootOutGroup(removeoutgroup, strict bool, tips ...string) error
- func (t *Tree) Resolve()
- func (t *Tree) Root() *Node
- func (t *Tree) Rooted() bool
- func (t *Tree) RotateInternalNodes()
- func (t *Tree) RoundLengths(precision int)
- func (t *Tree) RoundSupports(precision int)
- func (t *Tree) SackinIndex() (sackin int)
- func (t *Tree) ScaleLengths(factor float64)
- func (t *Tree) ScaleSupports(factor float64)
- func (t *Tree) SelectNodes(re string) ([]*Node, error)
- func (t *Tree) SetRoot(r *Node)
- func (t *Tree) ShuffleTips()
- func (t *Tree) SortNeighborsByTips()
- func (t *Tree) SortedTips() []*Node
- func (t *Tree) String() string
- func (t *Tree) SubTree(n *Node) *Tree
- func (t *Tree) SumBranchLengths() float64
- func (t *Tree) TipEdges() []*Edge
- func (t *Tree) TipIndex(name string) (int, error)
- func (t *Tree) TipNode(name string) (tip *Node, err error)
- func (t *Tree) Tips() []*Node
- func (t *Tree) ToDistanceMatrix() [][]float64
- func (t *Tree) UnRoot()
- func (t *Tree) UpdateBitSet() error
- func (t *Tree) UpdateTipIndex() (err error)
- type Trees
Constants ¶
const ( NIL_SUPPORT = -1.0 NIL_LENGTH = -1.0 NIL_PVALUE = -1.0 NIL_ID = -1 NIL_TIPID = 0 )
Constant for uninitialized values
const ( QUARTET_EQUALS = iota QUARTET_CONFLICT QUARTET_DIFF )
const MaxInt = int(^uint(0) >> 1)
const (
NIL_DEPTH = -1
)
Uninitialized depth is coded as -1
Variables ¶
This section is empty.
Functions ¶
func CommonEdges ¶
This function compares 2 trees and returns the number of edges in common.
It does not check if the trees have different sets of tip names, but just compare the bitsets. If called on two trees with the same number of tips with different names, it will give meaningless results.
It assumes that functions
tree.UpdateTipIndex() tree.ClearBitSets() tree.UpdateBitSet()
Have been called before, otherwise will output an error
If tipedges is false: does not take into account tip edges
func Compare ¶ added in v0.2.0
func Compare(refTree *Tree, compTrees <-chan Trees, tips, comparetreeidentical bool, cpus int) (<-chan BipartitionStats, error)
This function compares bipartitions of a reference tree with a set of trees given in the input channel.
If tips is true, then comparison includes external branches. If comparetreeidentical is true, does not compute the exact number of common and specific branches, but just put sametree=true or sametree=false in the stat channel.
This function returns almost immediately because computation is done in several go routines in background. However it returns a Channel that will contain bipartition statistics computed so far. This channel is closed at the end of the computations, so on the calling functin, you can iterate over this channel in order to wait for the end of computations.
It First Initializes bitsets of the reference tree
func NewAllNodeIndex ¶ added in v0.2.9
func NewAllNodeIndex(t *Tree) *nodeIndex
Tips + internal nodes
func NewNodeIndex ¶
Only Tips Computes a node index for a given tree.
Types ¶
type BipartitionStats ¶ added in v0.2.0
type BipartitionStats struct { Id int // Identifier of the tree analyzed Tree1 int // Number of bipartitions specific to the first tree Tree2 int // Number of bipartitions specific to the second tree Common int // Number of common bipartitions specific to the second tree Sametree bool // True if the trees are identical Err error // Wether an error occured or not in the computation }
Type for channel of tree stats
type Edge ¶
type Edge struct {
// contains filtered or unexported fields
}
Structure of an edge
func MaxLengthPath ¶ added in v0.1.6
Computes the path of maximum length between the given node and any other node.
It takes as argument the node from which we want to get the farthest tip (longest possible path).
It returns the path (slice of edges), and the sum of branch lengths of this path.
Returns an error if a branch has no length
func (*Edge) AddComment ¶ added in v0.2.7
Adds a comment to the edge. It will be coded by a list of [] In the Newick format.
func (*Edge) Bitset ¶
Returns the BitSet of that edge. It may be nil if not initialized.
the ith bit corresponds position of tip i around the branch (left:0/right:1).
i is the index of the tip in the sorted tip name array
func (*Edge) ClearComments ¶ added in v0.2.7
func (e *Edge) ClearComments()
Removes all comments associated to the node
func (*Edge) CommentsString ¶ added in v0.2.7
Returns the string of comma separated comments surounded by [].
func (*Edge) DumpBitSet ¶
Returns a string representing the bitset (bipartition) defined by this edge
func (*Edge) FindEdge ¶
Return the given edge in the array of edges comparing bitsets fields Return nil if not found.
Bitsets must be initialized otherwise returns an error.
func (*Edge) HashCode ¶ added in v0.4.0
HashCode for an Edge
Used for insertion in an HashMap If the bitsets are not initialized, then returns 0
func (*Edge) HashEquals ¶ added in v0.4.0
HashCode for an edge bitset.
Used for insertion in an EdgeMap
func (*Edge) IncrementSupport ¶ added in v0.4.0
Increments the branch support by the given support
func (*Edge) Inverse ¶ added in v0.4.0
func (e *Edge) Inverse()
Inverse Edge orientation: left becomes right and right becomes left
func (*Edge) LengthString ¶ added in v0.2.1
Returns the length as a string representing the right precision float (not 0.010000000 but 0.01 for example)
func (*Edge) Locality ¶ added in v0.1.8
Returns the average difference and the max difference in support between the current edge and its neighbors.
The neighbors are defined by the branches located in a area defined by number of branches separating them (<d).
- cutoff: Cutoff to consider hx=true or hy=true
- hx=true if exists a neighbor branch with suppt > cutoff
- hy=true if the current branch has suppt > cutoff */
Returns (avg diff, min diff, max diff, hx, hy)
func (*Edge) Name ¶ added in v0.2.1
Returns the name associated to this Edge.
If rooted, the output clade name is the name of the descendent node.
Else, the clade name is the name of the node on the lightest side. In that case bitsets need to be initialized.
func (*Edge) NeigborEdges ¶ added in v0.1.8
Returns the neighbors of the given edge.
The neighbors are defined by the branches located in a area defined by number of branches separating them (<d).
func (*Edge) NumTipsLeft ¶ added in v0.2.3
Number of tips on the left side of the bipartition Used by "TopoDepth" function for example.
Must be initialized with ComputeEdgeHashes.
func (*Edge) NumTipsRight ¶ added in v0.2.3
Number of tips on the right side of the bipartition Used by "TopoDepth" function for example.
Must Be initialized with ComputeEdgeHashes.
func (*Edge) SameBipartition ¶
Returns true if this edge defines the same biparition of the tips than the edge in argument.
Bitsets must be initialized
func (*Edge) SetPValue ¶ added in v0.1.4
Sets the pvalue of this edge (if not null, pvalue is stored/parsed as "/pvalue" in the bootstrap value field.
func (*Edge) SupportString ¶ added in v0.2.1
Returns the support as a string representing the right precision float (not 0.90000000 but 0.9 for example)
func (*Edge) TipPresent ¶
Tests wether the tip with index id in the bitset is Set or not.
The index corresponds to tree.Tipindex(tipname)
func (*Edge) ToStatsString ¶ added in v0.1.3
Returns a string containing informations about the edge:
Tab delimited:
1 - length 2 - support 3 - istip? 4 - depth 5 - topo depth 6 - name of right node if any 7 - comments associated to the edge 8 - name of left node if any 9 - comment of right node if any 10 - comment of left node if any
type EdgeIndex ¶
type EdgeIndex struct {
// contains filtered or unexported fields
}
Structure for an EdgeIndex. It is basically an HashMap, storing as key the bitset of the edge, and as value, the number of occurences of this edge already stored and the average branch lengths.
func NewEdgeIndex ¶
Initializes an Edge Count Index
func (*EdgeIndex) AddEdgeCount ¶
Increments edge count for an edge if it already exists in the map. If it does not exist, adds it with count 1
Also adds edge length
func (*EdgeIndex) Edges ¶ added in v0.4.0
Returns all the Bipartitions of the index (bitset) with their counts included in ]min,max]. If min==Max==1 : [1].
Keys of the index
func (*EdgeIndex) PutEdgeValue ¶
Adds the edge in the map, with given value. If the edge already exists in the index The old value is erased
type EdgeIndexInfo ¶ added in v0.1.2
type EdgeIndexInfo struct { Count int // Number of occurences of the branch Len float64 // Mean length of branches occurences }
Value stored in the HashMap
type KeyValue ¶
type KeyValue struct {
// contains filtered or unexported fields
}
KeyValue Pair stored in the HashMap
type NNIRearranger ¶ added in v0.4.0
type NNIRearranger struct { }
func (*NNIRearranger) Rearrange ¶ added in v0.4.0
func (nnir *NNIRearranger) Rearrange(t *Tree, f func(r Rearrangement) bool)
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node structure
func (*Node) AddComment ¶
Adds a comment to the node. It will be coded by a list of [] In the Newick format.
func (*Node) ClearComments ¶ added in v0.2.3
func (n *Node) ClearComments()
Removes all comments associated to the node
func (*Node) CommentsString ¶ added in v0.2.3
Returns the string of comma separated comments surounded by [].
func (*Node) Depth ¶
Returns the depth of the node. Returns an error if the depth has not been set yet.
func (*Node) EdgeIndex ¶
Returns the index of the given edge in the list of edges going from this node.
If the edge is not connected to the node n, then returns an error.
func (*Node) Id ¶ added in v0.1.4
Returns the Id of the node. Id==NIL_ID means that it has not been set yet.
func (*Node) IsConnected ¶ added in v0.4.0
Returns if a node "next" is connected to "n" in the tree
func (*Node) NodeIndex ¶
Returns the index of the given node next in the list of neighbors of node n.
If next is not a neighbor of n, then returns an error.
func (*Node) Parent ¶
Retrieve the parent node
If several parents: Error (should not happen). If no parent: Error (it is the root?)
Parent is defined as the node n2 connected to n by an edge e with e.left == n2 and e.right == n
func (*Node) ParentEdge ¶
Retrieves the Edge going from node n to its parent node.
If several parents: Error (should not happen). If no parent: Error (it is the root?)
Parent is defined as the node n2 connected to n by an edge e with e.left == n2 and e.right == n
func (*Node) RotateNeighbors ¶ added in v0.2.10
func (n *Node) RotateNeighbors()
Randomly rotates order of neighbor nodes and edges of a given node.
Topology is not changed, just the order of the tree traversal
type NodeIndex ¶
Structure of a node index. Basically a hashmap that stores as keys node names, and values node of the trees.
type Quartet ¶ added in v0.1.4
type Quartet struct {
/** Indexes of the taxa in the node index
t1 t3
\ /
-----
/ \
t2 t4
*/
T1, T2, T3, T4 uint
}
* Structure representing a "quartets"
func (*Quartet) Compare ¶ added in v0.1.4
Compares the first quartet
(q1,q2)(q3,q4) With the second quartet (q5,q6)(q7,q8)
Returns:
- QUARTET_EQUALS if they have the same taxa and the same topology
- QUARTET_CONFLICT if they have the same taxa and different topology
- QUARTET_DIFF if they have different taxa
type QuartetSet ¶ added in v0.1.4
type QuartetSet struct {
// contains filtered or unexported fields
}
* Structure representing a "quartets set" Actually X sets of taxa defined by a bipartition (Maybe multifurcated) The enumeration of all the quartets is done by the "Quartets" function
func NewQuartetSet ¶ added in v0.1.4
func NewQuartetSet() *QuartetSet
* Initializes a new empty quartet with 4 sets of taxa
type Rearrangement ¶ added in v0.4.0
Particular rearrangement (NNI, SPR, etc.)
type Rearranger ¶ added in v0.4.0
type Rearranger interface { // List all rearragements Rearrange(t *Tree, f func(r Rearrangement) bool) }
rearranger provides functions to modify input tree in order to search tree space
type TipBag ¶ added in v0.3.0
type TipBag struct {
// contains filtered or unexported fields
}
A bag of tips
func (*TipBag) AddTip ¶ added in v0.3.0
Add a tip to the bag
- If the same tip is already present: do nothing
- If another tip of the tree with the same name is already present: returns an error. it means that the tree contains several tips that have the same name
- If t is nil or if t is not a tip: returns an error
func (*TipBag) Clear ¶ added in v0.3.0
func (tb *TipBag) Clear()
Removes all tips of the given TipBag
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree structure having a root and a tip index, that maps tip names to their index
func AllTopologies ¶ added in v0.2.11
generate all possible topologies with nb tips rooted or not
func BipartitionTree ¶ added in v0.2.1
Builds a single edge tree, given left taxa and right taxa
\ / -*---*- / \
Returns an error if size of lefTips is <=1 or size of rightTips w<= 1, or if tip names are common between left and right tip sets.
func Consensus ¶ added in v0.1.2
Builds the consensus of trees given in the input channel.
- If the cutoff is 0.5 : The majority rule consensus is computed;
- If tht cutoff is 1 : The strict consensus is computed
In the output consensus tree:
- Branch supports are computed as the proportion of trees in which the bipartitions are present
- Branch lengths are computed as the average length of the same branch over all the trees where it is present
There can be errors if:
- The cutoff <0.5 or >1
- The tip names are different in the different trees
- Incompatible bipartition are generated to build the consensus (It should not happen since cutoff should be >=0.5)
func EdgeTree ¶ added in v0.1.4
Builds a tree whose only internal edge is the given edge e The two internal nodes are multifurcated
\ / -*---*- / \
alltips is the slice containing all tip names of the tree. if it is nil, it will be recomputed from the given tree.
func RandomBalancedBinaryTree ¶ added in v0.1.6
Creates a Random Balanced Binary tree. Does it recursively until the given depth is attained. Root is at depth 0. So a depth "d" will generate a tree with 2^(d) tips.
- depth : Depth of the balanced binary tree
- rooted: if true, generates a rooted tree
- branch length: follow an exponential distribution with param lambda=1/0.1
func RandomCaterpillarBinaryTree ¶ added in v0.2.3
Creates a Random Caterpillar tree by adding new tips to the last added terminal edge of the tree.
- nbtips : Number of tips of the random binary tree to create
- rooted: if true, generates a rooted tree
- branch length: follows an exponential distribution with param lambda=1/0.1
func RandomUniformBinaryTree ¶ added in v0.1.5
Creates a Random uniform Binary tree by successively adding new tips to a random edge of the tree.
- nbtips : Number of tips of the random binary tree to create
- rooted: if true, generates a rooted tree
- branch length: follow an exponential distribution with param lambda=1/0.1
func RandomYuleBinaryTree ¶ added in v0.1.5
Creates a Random Yule tree by successively adding new tips to random terminal edges of the tree.
- nbtips : Number of tips of the random binary tree to create
- rooted: if true, generates a rooted tree (actually if false, unroots the given tree)
- branch lengths: follow an exponential distribution with param lambda=1/0.1
func StarTree ¶ added in v0.1.2
Creates a Star tree with nbtips tips.
Since there is only one possible labelled tree, no need of randomness.
- nbtips : Number of tips of the star tree.
- Branch lengths are all set to 1.0
func StarTreeFromName ¶ added in v0.1.2
Creates a star tree using tipnames in argument Since there is only one possible labelled tree, no need of randomness.
Branch lengths are all set to 1.0
func StarTreeFromTree ¶ added in v0.1.2
Creates a Star tree with the same tips as the tree in argument Lengths of branches in the star trees are the same as lengths of terminal edges of the input tree
func (*Tree) AddBipartition ¶ added in v0.1.2
This function adds a branch/bipartition between the given node n and the given edges. To do so, it creates a new node between n and the edges, and connects it with a new edge.
Imagine a star tree with central node n,
1 | | 6----n-----2 /|\ / | \ e5 e4 e3
if we call AddBipartition(n,{e3,e4,e5}), at the end we have:
1 | | 6----n-----2 | | n2 /|\ / | \ e5 e4 e3
Useful for building consensus tree.
If the edges are not initially directly connected to n, then returns an error. If ony one edge is given, returns an error (no need to add a new edge).
func (*Tree) AddQuotes ¶ added in v0.4.1
AddQuotes adds quotes arround tip and/or internal node names.
If a single quote is already present at the beginning or at the end, it leaves it unchanged.
If a double quote is already present at the bebinning or at the end, it is replaced by a single quote
internals: Adds quotes at internal nodes tips: Adds quotes at tips
func (*Tree) AllTipNames ¶
Returns all the tip name in the tree Starts with n==nil (root)
func (*Tree) Annotate ¶ added in v0.1.9
Annotates internal branches of a tree with given data using the given list of names:
- each element is a slice of names whose first element is the new name to set
- following names are internal node name or tip names defining an internal node (LCA)
For a given element different possibilities:
- If < 2 names: an error is returned
- If 2 names [n1,n2]: we search for n2 in the tree (tip or internal node) and rename it as n1
- If > 2 names [n1,n2,...,ni]: We find the LCA of every tips whose name is in [n2,...,ni] and rename it as n1
If comment is true, then we do not change the name, but the comment of the given nodes.
The output tree won't have bootstrap support at the given branches anymore.
It considers the tree as rooted (even if multifurcation at root).
func (*Tree) CheckTree ¶ added in v0.3.1
Check that tree is well structured, with the right child, parent, edges, and node pointers
func (*Tree) CheckTreePostOrder ¶ added in v0.4.0
Checks that edges are proerly oriented And that edges connect proper nodes For testing purpose
func (*Tree) ClearBitSets ¶
Clears all bitsets associated to all edges
func (*Tree) ClearComments ¶ added in v0.2.3
func (t *Tree) ClearComments()
Clears comments associated to all nodes, tips and edges of the tree
func (*Tree) ClearEdgeComments ¶ added in v0.2.7
func (t *Tree) ClearEdgeComments()
func (*Tree) ClearLengths ¶ added in v0.1.5
func (t *Tree) ClearLengths()
Clears length (set to NIL_LENGTH) of all branches of the tree
func (*Tree) ClearNodeComments ¶ added in v0.2.7
func (t *Tree) ClearNodeComments()
func (*Tree) ClearPvalues ¶ added in v0.1.8
func (t *Tree) ClearPvalues()
Clears pvalues associated with supports (set to NIL_PVALUE) of all branches of the tree
func (*Tree) ClearSupports ¶ added in v0.1.5
func (t *Tree) ClearSupports()
Clears support (set to NIL_SUPPORT) of all branches of the tree
func (*Tree) CollapseLowSupport ¶ added in v0.1.5
Collapses (removes) the branches having support < support threshold && support != NIL_SUPPORT (exists)
func (*Tree) CollapseShortBranches ¶
Collapses (removes) the branches having length <= length threshold
func (*Tree) CollapseTopoDepth ¶ added in v0.1.9
func (t *Tree) CollapseTopoDepth(mindepthThreshold, maxdepthThreshold int, removeRoot, removeTips bool) (err error)
CollapseTopoDepth Collapses (removes) the branches having their depth d (# taxa on the lightest side of the bipartition) such that mindepththreshold<=d<=maxdepththreshold
func (*Tree) CollessIndex ¶ added in v0.2.3
Returns the colless index of the tree.
It computes the colless index of a rooted tree as the Sum over nodes v of |S(left(V))-S(right(V))|. With Sleft(V)=Size of the left sublcade of V and Sright(V)=size of the right subclade of V.
If the tree is unrooted, then it takes as starting point the deepest edge of the tree (not the classical definition of Colless index which is computed only for rooted trees).
If there are multifurcations, then the index of node V will be (Smax(V)-Smin(V)), with Smax(V)=Size of the largest subclade of V and Smin(V) size the smallest subclade of V (not the classical definition of Colless index which is computed only for binary trees).
func (*Tree) CommonEdges ¶
This function compares 2 trees and returns the number of edges in common If the trees have different sets of tip names, returns an error.
It assumes that functions
tree.UpdateTipIndex() tree.ClearBitSets() tree.UpdateBitSet()
Have been called before, otherwise will output an error
If tipedges is false: does not take into account tip edges
func (*Tree) CompareTipIndexes ¶
This function compares the tip name indexes of 2 trees
If the tipindexes have the same size (!=0) and have the same set of tip names, then returns nil, otherwise returns an error
func (*Tree) ComputeDepths ¶
func (t *Tree) ComputeDepths()
Computes detphs of all nodes. Depth of internal node n is defined as the length of the path from n to the closest tip. Depth of tip nodes is 0.
Depth is then accessible by n.Depth() for any node n.
func (*Tree) ComputeEdgeHashes ¶ added in v0.4.0
func (*Tree) ConnectNodes ¶
Connects the two nodes in argument by an edge that is returned.
func (*Tree) CopyEdge ¶ added in v0.1.5
Copy attributes of the given edge to the other given edge:
- Length
- Support
- id
- bitset (if not nil)
func (*Tree) CopyNode ¶ added in v0.1.5
Clone the given node, copy attributes of the given node into a new node
func (*Tree) CutEdgesMaxLength ¶ added in v0.3.0
Get all connected components (only the tips) of the tree when edges with length less than maxLen (included) are removed If a connected components have no tips, then it is not taken into account.
The edges are not actually removed from the input tree.
func (*Tree) DeepestEdge ¶ added in v0.2.3
DeepestEdge returns the deepest edge of the tree (considered unrooted) in terms of number of tips on the light side of it.
It does not use bitsets, thus they may be uninitialized.
func (*Tree) DeepestNode ¶ added in v0.2.4
Returns the deepest node of the tree (considered unrooted).
We define the deepest node as the heavy side of the deepest edge (See tree.DeepestEdge())
It does not use bitsets, thus they may be uninitialized.
func (*Tree) ExistsTip ¶
Return true if the tip with given name exists in the tree May return an error if tip index has not been initialized With UpdateTipIndex
func (*Tree) GraftTipOnEdge ¶
This function grafts the Tip n at the middle of the Edge e.
Example:
- Before *--e--*
- After *--e1--newnode--e2--* | n
To do so, it divides the branch lenght by 2,and returns the 2 new edges and the new internal node.
func (*Tree) IndexQuartets ¶ added in v0.1.4
func (*Tree) InsertIdenticalTip ¶ added in v0.3.1
This function adds a new tip next to the given tip node. This adds two 0 length branches. The given node reference is still a tip after this function. The new node is the internal node.
Before:
l
*----*tip1 After:
*tip1 l /.0
----*
\.0 *newTipName
If l==0.0 then, after:
*tip1 /.0
*
\.0 *newTipName
Warning: This function may add polytomies if l==0.0.
It updates the tipindex temporarily but if needed in downstream analysis t.ReinitIndexes() must be called. If initialized, Bitsets and Depths are not up2date after this function. They should be updated with t.ReinitIndexes() if needed.
func (*Tree) InsertIdenticalTips ¶ added in v0.3.1
This function adds Tips to the tree, adding 0 length branches. To do so, it takes all identical tipnames of the given slice And add the new tip names next to the existing ones, by adding 0 length branches. Each identical group must contain exactly 1 already present tip otherwise returns an error If a new tip is identical to several already present tips, then returns and error.
func (*Tree) InternalEdges ¶ added in v0.1.13
Returns all internal edges of the tree (do it recursively)
func (*Tree) LeastCommonAncestorRecur ¶ added in v0.2.1
func (t *Tree) LeastCommonAncestorRecur(current *Node, prev *Node, tipIndex map[string]*Node) (*Node, []*Edge, int, int, bool, error)
recursive function for getting the least common ancestor.
func (*Tree) LeastCommonAncestorRooted ¶ added in v0.2.1
func (t *Tree) LeastCommonAncestorRooted(nodeindex *nodeIndex, tips ...string) (*Node, []*Edge, bool, error)
Given a set of tip names, this function returns the node that is the common ancestor of them and the edges that connect this LCA node to the subtree.
It considers the tree as Rooted.
The returned boolean value tell if the group is monophyletic or not (i.e. contains all tips descending from LCA).
func (*Tree) LeastCommonAncestorUnrooted ¶ added in v0.1.2
func (t *Tree) LeastCommonAncestorUnrooted(nodeindex *nodeIndex, tips ...string) (*Node, []*Edge, bool, error)
Given a set of tip names, this function returns the node that is the common ancestor of them and the edges that connects this node to the subtree.
It considers the tree as unrooted
e2---1 ----a| | e1---2 | ---3 ----| | ---4 | ---5 ----| ---6
LeastCommonAncestorUnrooted(1,2) returns a,e1,e2,true
The returned boolean value telling if the group is monophyletic (i.e. contains all tips descending from LCA).
func (*Tree) MeanBranchLength ¶ added in v0.2.3
Returns the average branch lengths
func (*Tree) MedianSupport ¶
Returns the median branch support
func (*Tree) Merge ¶ added in v0.2.3
Merge merges Two rooted trees t and t2 in t by adding a new root node with two children Corresponding to the roots of the 2 trees.
If one of the tree is not rooted, returns an error.
Tip set must be different between the two trees, otherwise returns an error.
it is advised not to use t2 after the merge, since it may conflict with t.
Edges connecting the new root with old roots have length of 1.0, but can be modified afterwards.
func (*Tree) NbCherries ¶ added in v0.2.3
Returns the number of cherries in the tree
func (*Tree) NbTips ¶
Returns the number if tips of the tree
If UpdateTipIndex has been called before ok otherwise returns an error
func (*Tree) Quartets ¶ added in v0.1.4
* Iterate over all the quartets of the tree, edge by edge (t1,t2)(t3,t4) specific: If true gives the specific quartets
b0 b2 \ / left-----right / \ b1 b3
Else gives all the quartets
b0-|\ /|-b2 | >-----< | b1-|/ \|-b3
func (*Tree) ReinitIndexes ¶ added in v0.2.2
This Function initializes or reinitializes memory consuming structures:
- bitset indexes
- Tipindex
- And computes node depths
func (*Tree) ReinitInternalIndexes ¶ added in v0.4.0
func (t *Tree) ReinitInternalIndexes()
This Function initializes or reinitializes memory consuming structures:
- bitset indexes
- Tipindex
- And computes node depths
func (*Tree) RemoveEdges ¶
RemoveEdges removes the given branches from the tree if they are not tip edges. If removeRoot is true: In the case of rooted tree, branches can be removed also.
Merges the 2 nodes and creates multifurcations.
At the end, bitsets should not need to be updated
func (*Tree) RemoveQuotes ¶ added in v0.4.1
RemoveQuotes removes potential single and double quotes surrounding tip and/or internal node names
internals: Remove quotes at internal nodes names tips: Remove quotes at tips names
func (*Tree) RemoveSingleNodes ¶ added in v0.2.2
func (t *Tree) RemoveSingleNodes()
Removes Edges for which the left node has a unique child:
Example:
t1 t1 / / n0--n1--n2 => n0--n2 \ \ t2 t2
Will remove edge n1-n2 and keep node n2 informations (name, etc.) It adds n1-n2 length to n0-n1 (if any) and keeps n0-n1 support (if any) Useful for cleaning ncbi taxonomy for example.
func (*Tree) RemoveTips ¶
Removes a set of tips from the tree, given their names
if revert is true, then keeps only tips with the given names
Removed tips
func (*Tree) Rename ¶
This function renames nodes of the tree based on the map in argument If a name in the map does not exist in the tree, then returns an error If a node/tip in the tree does not have a name in the map: OK After rename, tip index is updated, as well as bitsets of the edges
func (*Tree) RenameAuto ¶ added in v0.2.11
func (t *Tree) RenameAuto(internals, tips bool, length int, curid *int, namemap map[string]string) error
Renames automatically nodes/tips of the Tree, with names of the form T000001, N00001, etc.
internals: Renames internal nodes tips: Renames tips length: length of the generated names curid: index that is incremented, to keep track of the number of generated names namemap: map that associates old names to new names - allows to keep track of renames for previous trees
func (*Tree) RenameRegexp ¶ added in v0.2.11
func (t *Tree) RenameRegexp(internals, tips bool, regex, replace string, namemap map[string]string) error
Renames nodes/tips of the Tree, given the regexp and a replaement string
internals: Renames internal nodes tips: Renames tips regexp: the regexp to match node names replace: Replacement string namemap: map that associates old names to new names
func (*Tree) ReorderEdges ¶ added in v0.2.3
This function reorders the edges of a tree in order to always have left-edge-right with left node being parent of right node with respect to the given root node.
Important even for unrooted trees. Useful mainly after a reroot.
It updates "reversed" edge slice, edges that have been reversed
func (*Tree) Reroot ¶
This function takes a node and reroots the tree on that node.
It reorients edges left-edge-right : see ReorderEdges()
The node must be part of the tree, otherwise it returns an error
func (*Tree) RerootFirst ¶
This function takes the first node having 3 neighbors and reroot the tree on this node It then recomputes indices
func (*Tree) RerootMidPoint ¶ added in v0.1.6
This function reroots the tree at the midpoint position. To do so, it first gets the 2 farthest tips of the tree, and takes the middle of the path between these tips as the new root position.
func (*Tree) RerootOutGroup ¶ added in v0.1.5
This function first unroots the input tree and reroots it using the outgroup in argument.
If the outgroup is not monophyletic and strict is false, it will take all the descendant of the LCA and print a warning. If strict is true, it returns an error.
An error is returned if the LCA is multifurcated, and several branches are possible for the placement of the root.
If the outgroup includes a tip that is not present in the tree, this tip will not be taken into account for the rerooting.
If removeoutgroup is true, then the outgrouped is removed from the rerooted tree.
func (*Tree) Resolve ¶ added in v0.1.9
func (t *Tree) Resolve()
Resolves multifurcating nodes (>3 neighbors).
If any node has more than 3 neighbors, then neighbors are resolved randomly by adding 0 length branches until 3 neighbors are remaining.
This function does not update bitsets on edges.
If needed, the calling function must do it with:
err := t.ClearBitSets() if err != nil { return err } t.UpdateBitSet()
func (*Tree) Rooted ¶
Returns true if the tree is rooted (i.e. root node has 2 neighbors), and false otherwise.
func (*Tree) RotateInternalNodes ¶ added in v0.2.10
func (t *Tree) RotateInternalNodes()
Randomly rotates neighbors of all internal nodes
It does not change the topology, but just the way the tree is traversed.
func (*Tree) RoundLengths ¶ added in v0.2.11
Rounds branch lengths by a given precision. Precision is defined as 1/(power of 10) Example: 6, means 10^-6.
Does not do anything for branches with a length of NIL_LENGTH or if precision is <=0. If precision > 15, then 15 is taken
func (*Tree) RoundSupports ¶ added in v0.2.11
Rounds branch supports by a given precision. Precision is defined as 1/(power of 10) Example: 6, means 10^-6
Does not do anything for branches with a support of NIL_SUPPORT or if precision is <=0 If precision > 15, then 15 is taken
func (*Tree) SackinIndex ¶ added in v0.2.3
Computes the Sackin index of the tree
This functions computes the Sackin index of a rooted tree as the sum of all tip depths.
If the tree is unrooted, then it takes as starting point the deepest edge of the tree (not the classical definition of Sackin index which is computed only for rooted trees).
No problems with multifurcations.
func (*Tree) ScaleLengths ¶ added in v0.2.5
Scale branch lengths by a given factor.
Does not do anything for branches with a length of NIL_LENGTH
func (*Tree) ScaleSupports ¶ added in v0.2.5
Scale branch supports by a given factor. Precision 10^-6.
Does not do anything for branches with a support of NIL_SUPPORT
func (*Tree) SelectNodes ¶ added in v0.2.0
Returns the list of nodes having a name matching the given regexp May return an error if the regexp is malformed. In this case, returns an empty (not nil) slice of nodes.
func (*Tree) SetRoot ¶
Set a root for the tree. This does not check that the node is part of the tree. It may be useful to call
t.ReinitIndexes()
After setting a new root, to update branch bitsets.
func (*Tree) ShuffleTips ¶
func (t *Tree) ShuffleTips()
This function shuffles the tips of the tree and recompute tipindex and bitsets.
The tree have the same topology, but tip names are reassigned randomly.
func (*Tree) SortNeighborsByTips ¶ added in v0.2.10
func (t *Tree) SortNeighborsByTips()
Sort neighbors of all nodes by their number of tips
May give better results for drawing.
func (*Tree) SortedTips ¶ added in v0.1.13
Tips, sorted by their order in the bitsets
func (*Tree) SubTree ¶ added in v0.2.0
SubTree Assumes that the tree is rooted.
Otherwise, will consider the pseudo root defined by the initial newick file
func (*Tree) SumBranchLengths ¶
Returns the sum of branch lengths
func (*Tree) TipIndex ¶
Return the tip index if the tip with given name exists in the tree May return an error if tip index has not been initialized With UpdateTipIndex or if the tip does not exist
func (*Tree) TipNode ¶ added in v0.4.0
Return the tip Node if the tip with given name exists in the tree May return an error if tip index has not been initialized With UpdateTipIndex or if the tip does not exist
func (*Tree) ToDistanceMatrix ¶ added in v0.1.7
This function computes and returns the distance (sum of branch lengths) between all pairs of tips in the tree (patristic distance).
Computes patristic distance matrix.
func (*Tree) UnRoot ¶
func (t *Tree) UnRoot()
Unroots a rooted tree by removing the bifurcating root, and rerooting to one of the non tip direct children of the previous root.
func (*Tree) UpdateBitSet ¶
Updates bitsets of all edges in the tree Assumes that the hashmap tip name : index is initialized with UpdateTipIndex function
func (*Tree) UpdateTipIndex ¶
Updates the tipindex which maps tip names to their index in the bitsets.
Bitset indexes correspond to the position of the tip in the alphabetically ordered tip name list