knitr::opts_chunk$set(fig.width=12, fig.height=8, echo=FALSE, eval=TRUE,
                      warning=FALSE, message=FALSE, comment="")
library(knitr)
knit_engines$set(asis = function(options) {
  if (options$echo && options$eval) knit_child(text = options$code)
})
# Check for various data objects

# classes <- lapply(data, class)
# classes <- lapply(classes, function(x) x[[1]])
# classes <- unlist(classes)

# info.data <- list()
# info.data$data <- grep("seqData", classes)
# info.data$richness <- grep("richRes", classes)
# info.data$abundance <- grep("abunRes", classes)
# info.data$alphaDiversity <- grep("alphaRes", classes)
# info.data$evenness <- grep("evenRes", classes)
# info.data$jaccard <- grep("jaccard", classes)
# info.data$effectiveSpecies <- grep("effspRes", classes)
# info.data$statistics <- grep("countSTAT_results", classes)
# info.data$indicator <- grep("indspRes", classes)
# 
# # Must only have one item for each class type
# if(any(unlist(lapply(info.data, function(x) length(x))) > 1)){
#   stop(paste("Multiple objects of class ", class(data[[which(unlist(lapply(info.data, length)) > 1)]]), ". This function can only accept one. In the case of multiple data objects, only use the normalized data object.", sep=""))
# }
classes <- params$classes
data <- params$data
# Have to at least have data
if(length(grep("seqData", classes)) == 0){
  stop("Must include data.")
}

Summary of data

norm_data <- data$data

This r attr(norm_data, "data_info")$data_type data had r attr(norm_data, "data_info")$num_edata reads and r attr(norm_data, "data_info")$num_samps samples. There were r attr(norm_data, "data_info")$num_miss_obs instances of missing data (i.e., r attr(norm_data, "data_info")$frac_missing * 100% missing).

There were r length(unique(attr(norm_data,"group_DF")$Group)) groupings of these samples. The samples were spread among the groups as follows.

table(attr(norm_data,"group_DF")$Group)

```{asis normalization, echo=ifelse(is.null(attr(norm_data,"data_info")$norm_method),FALSE,TRUE)}

Normalization

The data was normalized using the r attr(norm_data, "data_info")$norm_method method.

```{asis filter header, echo=ifelse(is.null(attr(norm_data, "filters")), FALSE, TRUE)}
## Filters
unname(unlist(lapply(1:length(names(attr(norm_data, "filters"))), function(x) attr(norm_data, "filters")[[x]][1])))

Finally, data was distributed as follows.

plot(norm_data)
community <- any(c(!is.null(data$rich), !is.null(data$abun), !is.null(data$adiv), !is.null(data$even), !is.null(data$jaccard)))

```{asis community metrics header, echo=ifelse(community, TRUE, FALSE)}

Community Metrics

The following is information about community metrics that were run on the data.

```{asis richness header, echo=ifelse(!is.null(data$rich), TRUE, FALSE)}
## Richness

Richness is the number of unique reads seen in a sample. This can be in the form of the observed number of reads or in the form of a richness estimator (Chao1 or ACE), which estimates the total number of species present in a community.
summary(data$rich)

plot(data$rich)

```{asis abundance header, echo=ifelse(!is.null(data$abun), TRUE, FALSE)}

Abundance

Abundance is the total number of reads seen in a sample. This can vary drastically among samples for a variety of reasons, including ecological as well as technical variability. Normalization techniques attempt to lessen the differences between samples.

```r
summary(data$abun)

plot(data$abun)

```{asis rich vs abun header, echo=ifelse(!is.null(data$rich) & !is.null(data$abun), TRUE, FALSE)}

Richness vs Abundance

A plot showing richness versus abundance can help determine how well a normalization strategy worked. Normalization should decrease the correlation between richness and abundance.

```r
plot(data$rich, data$abun)

```{asis alpha diversity header, echo=ifelse(!is.null(data$adiv), TRUE, FALSE)}

Alpha Diversity

Alpha diversity is a measure of how diverse a sample is.

```r
summary(data$adiv)

plot(data$adiv)

```{asis evenness header, echo=ifelse(!is.null(data$even), TRUE, FALSE)}

Evenness

Evenness is a measure of the spread of reads in a sample. For instance, a sample with reads of equal abundance will have a high evenness value, whereas a sample where there is a large variance in the abundance of reads will have a lower evenness.

```r
summary(data$even)

plot(data$even)

```{asis jaccard header, echo=ifelse(!is.null(data$jaccard), TRUE, FALSE)}

Jaccard r ifelse(attributes(data$jaccard)$similarity, "Similarity", "Dissimilarity")

The Jaccard index is a binary beta diversity measure. Here, it is implemented to look at the r ifelse(attributes(data$jaccard)$similarity, "similarity", "dissimilarity") between samples in the same group.

```r
summary(data$jaccard)

plot(data$jaccard)

```{asis effective species header, echo=ifelse(!is.null(data$effsp), TRUE, FALSE)}

Effective Species

```r
summary(data$effsp)

plot(data$effsp)

```{asis differential abundance header, echo=ifelse(!is.null(data$diffabun), TRUE, FALSE)}

Differential Abundance

Differential abundance analysis performs statistical pairwise comparisons to determine which reads are statistically different between the groups. This results in a p-value and log-fold-change for every read in the two groups.

```r
diffexp_data <- data$diffabun

attr(diffexp_data,"Tests")$Text
summary(diffexp_data)

``{asis diffabun flag text, echo=ifelse(!is.null(data$diffabun), TRUE, FALSE)} The number and regulatory direction of significantly differentially abundant reads (using a p-value threshold ofr attr(results,"Threshold")` for each comparison and each test performed can be seen in the following plots.

```r
plot(diffexp_data, type="flag")

```{asis diffabun volcano text, echo=ifelse(!is.null(data$diffabun), TRUE, FALSE)} The fold changes are plotted against the p-values in the following volcano plots.

```r
plot(diffexp_data, type="volcano")

```{asis diffabun logfc text, echo=ifelse(!is.null(data$diffabun), TRUE, FALSE)} The fold changes for significant features are plotted in the following heatmaps.

```r
plot(diffexp_data, type="logfc")

```{asis diffabun all diffabun text, echo=ifelse(!is.null(data$diffabun), TRUE, FALSE)} The taxonomic distribution of the significantly differentially abundant features can be seen in the following plot(s).

```r
plot_all_diffabun(diffexp_data, norm_data)

```{asis indicator species text, echo=ifelse(!is.null(data$indsp), TRUE, FALSE)}

Indicator Species

Indicator species are species which are characteristic of a group.

```r
summary(data$indsp)

plot(data$indsp, type="flag")

```{asis combined header, echo=ifelse(!is.null(data$combined), TRUE, FALSE)}

Combined

These are the features that were found significant in both the differential abundance tests and the indicator species analysis.

```r
data$combined


pmartR/pmartRseq documentation built on May 25, 2019, 9:20 a.m.