Skip to content

Instantly share code, notes, and snippets.

View joey711's full-sized avatar

Paul J. McMurdie joey711

View GitHub Profile
library("phyloseq")
data("GlobalPatterns")
x10 = prune_taxa(tail(names(sort(taxa_sums(GlobalPatterns))), 10), GlobalPatterns)
# Fix the node labels for the sake of the tree at the end:
phy_tree(x10)$node.label <- gsub("\\.[[:alnum:]]+$", "", phy_tree(x10)$node.label)
# Add a new rank, Strain, with the OTU ids
tax_table(x10) <- cbind(tax_table(x10), Strain=taxa_names(x10))
# Define the ranks you want to include
myranks = c("Genus", "Species", "Strain")
mylabels = apply(tax_table(x10)[, myranks], 1, paste, sep="", collapse="_")