Skip to content

Instantly share code, notes, and snippets.

@joey711
Last active December 17, 2015 13:18
Show Gist options
  • Save joey711/5615670 to your computer and use it in GitHub Desktop.
Save joey711/5615670 to your computer and use it in GitHub Desktop.
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="_")
# Add concatenated labels as a new rank after strain
tax_table(x10) <- cbind(tax_table(x10), catglab=mylabels)
# Check this out on a tree
plot_tree(x10, label.tips="catglab",
color="SampleType", shape="Phylum", nodelabf=nodeplotboot(),
ladderize="left", plot.margin=2.15, size="abundance")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment