Skip to content

Instantly share code, notes, and snippets.

@shandley
Created May 10, 2018 16:19
Show Gist options
  • Save shandley/87b0017ca593c58561a8b76b98985477 to your computer and use it in GitHub Desktop.
Save shandley/87b0017ca593c58561a8b76b98985477 to your computer and use it in GitHub Desktop.
Convert Phyloseq to AmpVis2 format in R
```{r phyloseq-ampvis2}
library("ampvis2")
# Load data into ampvis
otu.table <- t(otu_table(ps1, taxa_are_rows = FALSE))
otu.table <- as.data.frame(otu.table)
otu.table <- rownames_to_column(otu.table, var = "OTU")
head(rownames(otu.table))
head(colnames(otu.table))
nrow(otu.table)
tax.table <- as.data.frame(tax_table(ps1))
tax.table <- rownames_to_column(tax.table, var = "OTU")
head(rownames(tax.table))
head(colnames(tax.table))
nrow(tax.table)
my_otu_table <- left_join(otu.table, tax.table, by = "OTU")
nrow(my_otu_table)
colnames(my_otu_table)
head(rownames(my_otu_table))
my_otu_table <- column_to_rownames(my_otu_table, var = "OTU")
head(rownames(my_otu_table))
colnames(my_otu_table)
nrow(my_otu_table)
my_metadata <- as.tibble(sample_data(ps1))
class(my_metadata)
head(rownames(my_metadata))
nrow(my_metadata)
ncol(my_metadata)
my_tree <- phy_tree(ps1)
ps1.av2 <- amp_load(otutable = my_otu_table, metadata = my_metadata, tree = my_tree)
ps1.av2
# Heatmap
amp_heatmap(ps1.av2, group_by = "day", facet_by = "randomization_arm")
# Boxplot
amp_boxplot(ps1.av2, group_by = "day", tax_add = "Phylum")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment