Skip to content

Instantly share code, notes, and snippets.

@lwaldron
Created August 7, 2017 22:51
Show Gist options
  • Save lwaldron/75e8226c319965189c4d084c41a932c1 to your computer and use it in GitHub Desktop.
Save lwaldron/75e8226c319965189c4d084c41a932c1 to your computer and use it in GitHub Desktop.
Write a one-column table of all metaphlan2 taxa at all levels of taxonomy
library(curatedMetagenomicData)
newicklabs <- getMetaphlanTree(simplify=FALSE)$tip.label
delims <- paste0("\\|", c("p", "c", "o", "f", "g", "s"), "__.+")
res <- lapply(delims, function(x) sub(x, "", newicklabs))
res <- unique(unlist(res))
res <- c(res, grep("s__", newicklabs, val=TRUE))
res <- sort(res)
res <- grep("GCF", res, invert=TRUE, val=TRUE)
res <- grep("noname$", res, invert = TRUE, value = TRUE)
write.table(res, file="~/Downloads/metaphlantaxa.tsv", row.names=FALSE, col.names = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment