Updated Practical 3 Processing 16S rRNA amplicon data (markdown) authored by Ben Francis's avatar Ben Francis
...@@ -111,13 +111,13 @@ For now though, we're just going to use a (relatively) simple plotting function ...@@ -111,13 +111,13 @@ For now though, we're just going to use a (relatively) simple plotting function
library(reshape2) library(reshape2)
library(RColorBrewer) library(RColorBrewer)
plotTaxon <- function(seqtab, taxon, min_abund, taxonomicLevel) { plotTaxon <- function(seqtab, taxtable, taxon, min_abund, taxonomicLevel) {
seqtab.copy <- seqtab seqtab <- data.frame(seqtab)
seqtab.copy <- data.frame(seqtab.copy) colnames(seqtab) <- paste(taxtable[, 1], taxtable[, 2], taxtable[, 3], taxtable[, 4],
colnames(seqtab.copy) <- paste(tax[, 1], tax[, 2], tax[, 3], tax[, 4], tax[, 5], tax[, 6], as.character(1:length(tax[, 1])), sep="-") taxtable[, 5], taxtable[, 6], as.character(1:length(taxtable[, 1])), sep="-")
seqtab.copy <- seqtab.copy/rowSums(seqtab.copy) seqtab <- seqtab/rowSums(seqtab)
seqtab.copy <- seqtab.copy[, sapply(seqtab.copy, function(x) max(x)) >= min_abund] seqtab <- seqtab[, sapply(seqtab, function(x) max(x)) >= min_abund]
seqtab.copy$sample <- rownames(seqtab.copy) seqtab$sample <- rownames(seqtab)
seqtab.m <- melt(seqtab.copy) seqtab.m <- melt(seqtab.copy)
seqtab.m <- seqtab.m[grep(taxon, seqtab.m$variable),] seqtab.m <- seqtab.m[grep(taxon, seqtab.m$variable),]
seqtab.m$variable <- gsub("NA", "uncultured", seqtab.m$variable) seqtab.m$variable <- gsub("NA", "uncultured", seqtab.m$variable)
...@@ -139,4 +139,4 @@ For now though, we're just going to use a (relatively) simple plotting function ...@@ -139,4 +139,4 @@ For now though, we're just going to use a (relatively) simple plotting function
theme_classic() + theme_classic() +
theme(axis.text.x=element_text(angle=45, hjust=1)) theme(axis.text.x=element_text(angle=45, hjust=1))
} }
plotTaxon(seqtab, "Bacteroidetes", 0.01, "Genus") plotTaxon(seqtab.nochim, taxa, "Bacteroidetes", 0.01, "Genus")