Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkamvar/3c3f12926de648431937 to your computer and use it in GitHub Desktop.
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
#==============================================================================#
#' 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