Created
May 4, 2016 17:05
-
-
Save DomBennett/72ea9843a4f6717fc028badc95e80c2c to your computer and use it in GitHub Desktop.
Extract list of node IDs and descendant tips from a phylogeny in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Libraries | |
library(MoreTreeTools) # package in dev, install via github: https://github.com/DomBennett/MoreTreeTools | |
library(doMC) # use doSNOW if using Windows | |
# find out how many cores you have | |
n <- detectCores() | |
# set-up | |
registerDoMC(cores=n) | |
# example tree | |
tree <- rtree(1000) | |
# find all internal nodes in tree | |
nds <- (getSize(tree) + 1):(tree$Nnode + getSize(tree)) | |
# generate inital 'loop dataframe' for plyr | |
l_data <- data.frame(node=nds, stringsAsFactors=FALSE) | |
res <- plyr::mlply(.data=l_data, .fun=getChildren, tree=tree, .parallel=TRUE) | |
res <- res[1:length(res)] # remove the 'attr's | |
# add children for each tip, which is just the tip, for consistency | |
res[tree$tip.label] <- tree$tip.label |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Libraries | |
library(treeman) | |
library(doMC) # use doSNOW if using Windows | |
# find out how many cores you have | |
n <- detectCores() | |
# set-up | |
registerDoMC(cores=n) | |
# random tree, otherwise use readTree() | |
tree <- randTree(10000) | |
# get all internal node IDs of tree | |
nids <- tree['nds'] | |
# find all children for each node | |
res <- getNdsKids(tree, ids=nids, .parallel=TRUE) | |
# add children for each tip, which is just the tip, for consistency | |
res[tree['tips']] <- tree['tips'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment