trann2trdat: trann2trdat. extract annontations from a nexus tree.

View source: R/trann2trdat.R

trann2trdatR Documentation

trann2trdat. extract annontations from a nexus tree.

Description

Convert a tree with annotations from BEAST to a data frame with the annotations for the rate, the branch lengths in substitions and the branch lengths in time. The tree should be read with funtion read.annotated.nexus from the epibase package.

Usage

trann2trdat(tree)

Arguments

tree

An object of class 'phylo' with annotations as attributes of the object. Normally the tree can be the output of BEAST or MRBayes, and it would be loaded in R with the function read.annotated.nexus from the epibase package.

Details

To load the tree use read.annotated.nexus("BEAST_output.tree"). This reads the annotations for each branch.

Value

A data frame with the branch name, parent node, daughter node, mid age, rate, number of substitutions, and time.

Note

see read.annotated.nexus

Author(s)

David Duchene

References

None

See Also

see read.annotated.nexus from package epibase (defunct)

Examples

## Not run: 
myAnnotatedTree <- read.annotated.nexus("annotated.tree")
annnotationData <- trann2trdat(myAnnotatedTree)
head(annotationData)

## End(Not run)
## The function is currently defined as
function (tree) 
{
    
    tree$edge.length <- unlist(sapply(tree$annotations, function(x) {
        x$length
    }))[1:length(tree$edge.length)]
    rates <- unlist(sapply(tree$annotations, function(x) {
        x$rate_median
    }))
    midages <- mid.edge.ages(tree)

      timelen <- tree$edge.length
    subslen <- tree$edge.length * rates
    return(data.frame(branch = rownames(as.data.frame(tree$edge)), 
        parent = tree$edge[, 1], daughter = tree$edge[, 2], midage = midages, 
        rate = rates, blensubs = subslen, blentime = timelen))
  }

sebastianduchene/NELSI documentation built on Sept. 5, 2024, 3:08 a.m.