Example using Negative Binomial in Microbiome Differential Abundance Testing

In this example I use the publicly available data from a study on colorectal cancer:

Genomic analysis identifies association of Fusobacterium with colorectal carcinoma. Kostic, A. D., Gevers, D., Pedamallu, C. S., Michaud, M., Duke, F., Earl, A. M., et al. (2012). Genome research, 22(2), 292-298.

As a side-note, this work was published ahead of print in Genome Research alongside a highly-related article from a separate group of researchers (long-live reproducible observations!): Fusobacterium nucleatum infection is prevalent in human colorectal carcinoma. In case you are interested. For the purposes of example, however, we will stick to the data from the former study, with data available at the microbio.me/qiime server.

Study ID: 1457

Project Name: Kostic_colorectal_cancer_fusobacterium

Study Abstract: The tumor microenvironment of colorectal carcinoma is a complex community of genomically altered cancer cells, nonneoplastic cells, and a diverse collection of microorganisms. Each of these components may contribute to carcino genesis; however, the role of the microbiota is the least well understood. We have characterized the composition of the microbiota in colorectal carcinoma using whole genome sequences from nine tumor/normal pairs. Fusobacterium sequences were enriched in carcinomas, confirmed by quantitative PCR and 16S rDNA sequence analysis of 95 carcinoma/normal DNA pairs, while the Bacteroidetes and Firmicutes phyla were depleted in tumors. Fusobacteria were also visualized within colorectal tumors using FISH. These findings reveal alterations in the colorectal cancer microbiota; however, the precise role of Fusobacteria in colorectal carcinoma pathogenesis requires further investigation.

Import data with phyloseq, convert to DESeq2

Start by loading phyloseq.

library("phyloseq"); packageVersion("phyloseq")
## [1] '1.15.0'

Defined file path, and import the published OTU count data into R.

filepath = system.file("extdata", "study_1457_split_library_seqs_and_mapping.zip", package="phyloseq")
kostic = microbio_me_qiime(filepath)
## Found biom-format file, now parsing it... 
## Done parsing biom... 
## Importing Sample Metdadata from mapping file...
## Merging the imported objects... 
## Successfully merged, phyloseq-class created. 
##  Returning...

Here I had to use a relative file path so that this example works on all systems that have phyloseq installed. In practice, your file path will look like this (if you've downloaded the data ahead of time):

filepath = "~/Downloads/study_1457_split_library_seqs_and_mapping.zip"
kostic = microbio_me_qiime(filepath)

Or like this (if you're accessing data directly from the microbio.me/qiime server directly):

kostic = microbio_me_qiime(1457)

Convert to DESeq2's DESeqDataSet class

In this example I'm using the major sample covariate, DIAGNOSIS, as the study design factor. The focus of this study was to compare the microbiomes of pairs of healthy and cancerous tissues, so this makes sense. Your study could have a more complex or nested design, and you should think carefully about the study design formula, because this is critical to the test results and their meaning. You might even need to define a new factor if none of the variables in your current table appropriately represent your study's design. See the DESeq2 home page for more details.

Here is the summary of the data variable kostic that we are about to use, as well as the first few entries of the DIAGNOSIS factor.

## phyloseq-class experiment-level object
## otu_table()   OTU Table:         [ 2505 taxa and 190 samples ]
## sample_data() Sample Data:       [ 190 samples by 71 sample variables ]
## tax_table()   Taxonomy Table:    [ 2505 taxa by 7 taxonomic ranks ]
head(sample_data(kostic)$DIAGNOSIS, 10)
##  [1] Healthy Tumor   Tumor   Healthy Healthy Healthy Tumor   Healthy
##  [9] Healthy Healthy
## Levels: Healthy None Tumor

DESeq2 conversion and call

First load DESeq2.

library("DESeq2"); packageVersion("DESeq2")
## [1] '1.11.0'

The following two lines actually do all the complicated DESeq2 work. The function phyloseq_to_deseq2 converts your phyloseq-format microbiome data into a DESeqDataSet with dispersions estimated, using the experimental design formula, also shown (the ~DIAGNOSIS term). The DESeq function does the rest of the testing, in this case with default testing framework, but you can actually use alternatives.

First remove the 5 samples that had no DIAGNOSIS attribute assigned. These introduce a spurious third design class that is actually a rare artifact in the dataset. Also remove samples with less than 500 reads (counts). Note that this kind of data cleanup is useful, necessary, and should be well-documented because it can also be dangerous to alter or omit data without clear documentation. In this case I actually explored the data first, and am omitting some of the details (and explanatory plots) here for clarity.

kostic <- subset_samples(kostic, DIAGNOSIS != "None")
kostic <- prune_samples(sample_sums(kostic) > 500, kostic)
## phyloseq-class experiment-level object
## otu_table()   OTU Table:         [ 2505 taxa and 177 samples ]
## sample_data() Sample Data:       [ 177 samples by 71 sample variables ]
## tax_table()   Taxonomy Table:    [ 2505 taxa by 7 taxonomic ranks ]
diagdds = phyloseq_to_deseq2(kostic, ~ DIAGNOSIS)
# calculate geometric means prior to estimate size factors
gm_mean = function(x, na.rm=TRUE){
  exp(sum(log(x[x > 0]), na.rm=na.rm) / length(x))
geoMeans = apply(counts(diagdds), 1, gm_mean)
diagdds = estimateSizeFactors(diagdds, geoMeans = geoMeans)
diagdds = DESeq(diagdds, fitType="local")

Note: The default multiple-inference correction is Benjamini-Hochberg, and occurs within the DESeq function.

Investigate test results table

The following results function call creates a table of the results of the tests. Very fast. The hard work was already stored with the rest of the DESeq2-related data in our latest version of the diagdds object (see above). I then order by the adjusted p-value, removing the entries with an NA value. The rest of this example is just formatting the results table with taxonomic information for nice(ish) display in the HTML output.

res = results(diagdds)
res = res[order(res$padj, na.last=NA), ]
alpha = 0.01
sigtab = res[(res$padj < alpha), ]
sigtab = cbind(as(sigtab, "data.frame"), as(tax_table(kostic)[rownames(sigtab), ], "matrix"))
##           baseMean log2FoldChange     lfcSE      stat       pvalue
## 64396  123.2307314       2.112195 0.4122077  5.124103 2.989581e-07
## 88701    0.3916123       4.182832 0.8545597  4.894722 9.844467e-07
## 72853   19.4337252      -1.568284 0.3219215 -4.871634 1.106789e-06
## 180285 114.2661657      -1.184742 0.2729667 -4.340243 1.423255e-05
## 184729   9.8379508      -1.804469 0.4310183 -4.186525 2.832573e-05
## 194648   6.1917263      -1.242530 0.3008820 -4.129625 3.633552e-05
##                padj  Kingdom        Phylum                Class
## 64396  0.0001931270 Bacteria  Fusobacteria Fusobacteria (class)
## 88701  0.0002383285 Bacteria Bacteroidetes          Bacteroidia
## 72853  0.0002383285 Bacteria    Firmicutes           Clostridia
## 180285 0.0022985560 Bacteria    Firmicutes           Clostridia
## 184729 0.0036596844 Bacteria    Firmicutes           Clostridia
## 194648 0.0038018039 Bacteria    Firmicutes           Clostridia
##                  Order           Family            Genus
## 64396  Fusobacteriales Fusobacteriaceae    Fusobacterium
## 88701    Bacteroidales   Prevotellaceae       Prevotella
## 72853    Clostridiales  Ruminococcaceae Faecalibacterium
## 180285   Clostridiales  Ruminococcaceae Faecalibacterium
## 184729   Clostridiales  Lachnospiraceae     Ruminococcus
## 194648   Clostridiales             <NA>             <NA>
##                    Species
## 64396                 <NA>
## 88701                 <NA>
## 72853                 <NA>
## 180285                <NA>
## 184729 Ruminococcus gnavus
## 194648                <NA>

Let's look at just the OTUs that were significantly enriched in the carcinoma tissue. First, cleaning up the table a little for legibility.

posigtab = sigtab[sigtab[, "log2FoldChange"] > 0, ]
posigtab = posigtab[, c("baseMean", "log2FoldChange", "lfcSE", "padj", "Phylum", "Class", "Family", "Genus")]
OTU baseMean log2FoldChange lfcSE padj Phylum Class Family Genus
64396 123.2307314 2.112195 0.4122077 0.0001931270 Fusobacteria Fusobacteria (class) Fusobacteriaceae Fusobacterium
88701 0.3916123 4.182832 0.8545597 0.0002383285 Bacteroidetes Bacteroidia Prevotellaceae Prevotella
374052 42.0724838 2.064697 0.5041057 0.0038018039 Fusobacteria Fusobacteria (class) Fusobacteriaceae Fusobacterium
307981 1.9105637 1.791758 0.4513741 0.0040584102 Proteobacteria Gammaproteobacteria Enterobacteriaceae Klebsiella
298806 0.3148653 2.113592 0.5573007 0.0064215312 Actinobacteria Actinobacteria (class) Coriobacteriaceae Collinsella

As expected from the original study abstract and title, a Fusobacterium OTU was among the most-significantly differentially abundant between the cancerous and healthy samples.

Here is a bar plot showing the log2-fold-change, showing Genus and Phylum. Uses some ggplot2 commands.

scale_fill_discrete <- function(palname = "Set1", ...) {
    scale_fill_brewer(palette = palname, ...)
sigtabgen = subset(sigtab, !is.na(Genus))
# Phylum order
x = tapply(sigtabgen$log2FoldChange, sigtabgen$Phylum, function(x) max(x))
x = sort(x, TRUE)
sigtabgen$Phylum = factor(as.character(sigtabgen$Phylum), levels=names(x))
# Genus order
x = tapply(sigtabgen$log2FoldChange, sigtabgen$Genus, function(x) max(x))
x = sort(x, TRUE)
sigtabgen$Genus = factor(as.character(sigtabgen$Genus), levels=names(x))
ggplot(sigtabgen, aes(x=Genus, y=log2FoldChange, color=Phylum)) + geom_point(size=6) + 
  theme(axis.text.x = element_text(angle = -90, hjust = 0, vjust=0.5))

plot of chunk bar-plot