Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Last active Aug 29, 2015
Embed
What would you like to do?
Add tip colors and round node labels for nexus files produced via APE for use in FigTree
#==============================================================================#
#' INSTALLATION
#'
#' devtools::source_gist("3c3f12926de648431937")
#==============================================================================#
#
#
#==============================================================================#
#' Adds tip colors to tiplabels of an object of class "phylo"
#'
#' Arguments:
#' x an object of class phylo with tip labels
#' tip_colors a vector of the same length as the number of tips in x
#' comprised of color designations in hexadecimal format.
#'
#' Returns:
#' an object of class "phylo"
#==============================================================================#
add.tip.color <- function(x, tip_colors){
tips <- x$tip.label
colors <- paste0("[&!color=", tip_colors, "]")
x$tip.label <- paste0(tips, colors)
return(x)
}
#==============================================================================#
#' Rounds node labels produced via bootstrap.
#'
#' Arguments:
#' x an object of class phylo with tip labels
#'
#' Returns:
#' an object of class "phylo" with rounded node labels.
#==============================================================================#
round.nodes <- function(x){
x$node.label <- round(x$node.label)
return(x)
}
@zkamvar
Copy link
Author

zkamvar commented Feb 17, 2015

installation:

devtools::source_gist("3c3f12926de648431937")

@zkamvar
Copy link
Author

zkamvar commented Feb 24, 2015

Example usage:

library("poppr")
library("ape")
devtools::source_gist("3c3f12926de648431937")
data(microbov)
micpop  <- genind2genpop(microbov)
mictree <- aboot(micpop) # generates tree based off of Nei's distance with 100 bootstrap replicates
cols    <- any2col(micpop@pop.names)
write.nexus(add.tip.color(mictree, cols), file = "myTree.nex") # saves tree in nexus format with tip colors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment