Skip to content

Instantly share code, notes, and snippets.

@fmichonneau
Created May 14, 2014 18:11
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 fmichonneau/b11f88689ed367f4983c to your computer and use it in GitHub Desktop.
Save fmichonneau/b11f88689ed367f4983c to your computer and use it in GitHub Desktop.
##' Converts a tree created by RAxML so that the bootstrap values are
##' assigned to nodes instead of edges.
##'
##' By default, (and rightly so), RAxML returns the bootstrap values
##' on an unrooted tree assigned to the edges. Most often, users want
##' the bootstrap values assigned to nodes instead. This function uses
##' a little regular expression to assign the boostrap values to the
##' nodes. It might not always work, use with caution.
##' @title Convert RAxML edge labels bootstrap values to node labels
##' @param f the tree file generated by RAxML
##' @param out the tree file generated by this function
##' @return TRUE is the function succeed. Used for this side effect
##' that creates a new tree where the bootstrap values are assigned to
##' nodes.
##' @author François Michonneau
convertRAxMLedgeLabels <- function(f, out) {
eachTr <- scan(f, what="character", sep="\n")
stopifnot(!file.exists(out))
for (i in 1:length(eachTr)) {
tmpStr <- eachTr[i]
tmpStr <- gsub("\\):([0-9]+\\.[0-9]+)\\[([0-9]{1,3})\\]", "\\)\\2:\\1", tmpStr)
cat(tmpStr, file = out, append = TRUE)
}
TRUE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment