Learn R Programming

Rsampletrees (version 1.0.3)

addTreeStat: Add tree statistics to a treeoutput object

Description

This function computes a summary statistic on each of the trees given in the treeoutput object. The results are stored in the procdata component of the treeoutput object.

Usage

addTreeStat(output, myfunc, funcname=NULL, maxlines=1000, treerange=NULL, ...)

Arguments

output

An object of class `treeoutput'

myfunc

The function to be applied to each tree

funcname

The name of the function to be used for the column name of the TreeStat data frame

maxlines

The maximum number of lines of the tree file to read in at a time. This avoids large tree files from fully being read in.

treerange

A vector giving the indices of the trees to which the function should be applied. Only used if the trees haven't been read in

...

further arguments that can be passed to treeapply.

Value

Returns an object of class `treeoutput' that is the same as output, except that the tree statistics have been added to the data frame TreeStats in the procdata component.

The data frame TreeStats consists of a column for the tree index and a column for each of the tree statistics computed.

Details

As with the function treeapply, the tree statistics can be computed on a subset of all the trees (provided by treerange). Note, however, that if TreeStats already exists due to previous call to addTreeStat(), the function is applied to the same trees as indexed in the first column of TreeStats even if these are different from treerange (a warning is given). This ensures a data frame of the correct dimensions.

References

Burkett KM, McNeney B, Graham J. Sampletrees and Rsampletrees: sampling gene genealogies conditional on SNP genotype data. Bioinformatics. 32:1580-2, 2016

See Also

readOutput, treeapply

Examples

Run this code
# NOT RUN {
# A function that computes the time to MRCA of a tree using the ape package
require(ape)
mrca.age=function(tree)
{
	return(coalescent.intervals(tree)$total.depth)
}
#\dontrun{
 # Read in the settings; Must change the RunName so that the example files can be found
#system.file("Examples/example_g_pars",package="Rsampletrees")
 filename=paste(path.package("Rsampletrees"),"/extdata/example_g_pars",sep="")
 runpars=readArgs(filename, check=FALSE)
 
#paste(system.file(package="Rsampletrees"),runpars$RunName, sep="/")
 runname=paste(path.package("Rsampletrees"),"extdata",runpars$RunName,sep="/")
 runpars=changeArgs(runpars, RunName=runname)
 
 # Read in the output and add the summary statistic
 results=readOutput(argobj=runpars)
 results=addTreeStat(results, myfunc=mrca.age, funcname="Time.to.MRCA")
#}
# }

Run the code above in your browser using DataLab