Last active
August 29, 2015 14:09
-
-
Save zkamvar/3c3f12926de648431937 to your computer and use it in GitHub Desktop.
Add tip colors and round node labels for nexus files produced via APE for use in FigTree
This file contains 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
#==============================================================================# | |
#' 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) | |
} |
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
installation: