# 16S Visualization Pipeline

##### ampvis2 and Plotly

Nephele uses the ampvis2 R package v2.3.2 for statistical computation. We also make use of the Plotly R interface for the plotly.js charting library. The plots can be minimally edited interactively. However, they also have a link to export the data to the Plotly Chart Studio which allows for making a variety of charts. We have a tutorial for making simple edits to the plots here.

### Rarefaction Curve

The rarefaction curves are made with the amp_rarecurve function. The table is written to rarecurve.txt and the plot to rarecurve.html.

``rarecurve <- amp_rarecurve(amp, color_by = "TreatmentGroup")``

### Filtering and rarefying/subsampling OTU table

The `sampling depth` is used to filter out samples with few counts. Samples with counts which fall below the `sampling depth` are removed from the OTU table using amp_subset_samples. The names of samples that are removed are output to samples_being_ignored.txt.

Additionally, the `sampling depth` is used to rarefy the counts for the Bray-Curtis PCoA and the alpha diversity plots. The OTU table is rarefied using rrarefy from the vegan R package. The table of the filtered, rarefied counts is saved as rarefied_OTU_table.txt.

If you do not provide a `sampling depth`, please see FAQ:How is the sampling depth calculated? for more information.

``````amp <- amp_subset_samples(amp, minreads = sampdepth)
otu <- rrarefy(t(amp\$abund), sampdepth)
amprare <- ampsub
amprare\$abund <- t(otu)``````

### PCoA

Principal coordinates analysis using binomial and Bray-Curtis distances is carried out using amp_ordinate. For more information on the formulae for the distance measures, see `vegdist`.

The binomial distance is able to handle varying sample sizes, so the raw counts from the OTU table are used. For the Bray-Curtis distance, the rarefied counts are used. The coordinates from the plots are written to pcoa_binomial.txt and pcoa_bray.txt and the plots to pcoa_binomial.html and pcoa_bray.html. At least 3 samples are needed for these plots.

``````pcoa_binomial <- amp_ordinate(amp, filter_species = 0.01, type = "PCOA",
distmeasure = "binomial", sample_color_by = "TreatmentGroup",
detailed_output = TRUE, transform = "none")

pcoa_bray <- amp_ordinate(amprare, filter_species = 0.01, type = "PCOA",
distmeasure = "bray", sample_color_by = "TreatmentGroup",
detailed_output = TRUE, transform = "none")``````

### Alpha diversity

The Shannon diversity and Chao species richness are computed using amp_alphadiv. The rarefied counts are used for this computation. The diversity values are saved in alphadiv.txt, and boxplots are output to alphadiv.html. At least 3 samples are needed to produce these plots.

``alphadiv <- amp_alphadiv(amprare, measure = "shannon", richness = TRUE, rarefy = sampdepth)``

### Heatmap

The interactive heatmap is implemented using the morpheus R API developed at the Broad Institute. Documentation for how to use the heatmap can be found on the morpheus website.

The heatmap, seq_heatmap.html, is made from the raw OTU table with the counts normalized to 100 to represent the relative abundances using amp_subset_samples before the heatmap is made with morpheus. If there are too many OTUs or sequence variants, then the heatmap is made at the species level instead. A heatmap is also made from the rarefied counts, seq_heatmap_rarefied.html.

``````amptax <-amp_subset_samples(amp, normalise = TRUE)
heatmap <- morpheus(amp\$abund, columns = columns, rows = rows,
columnColorModel = list(type = as.list(colors)),
colorScheme = list(scalingMode = "fixed", stepped = FALSE),
columnAnnotations = amptax\$metadata, rowAnnotations = amptax\$tax)``````
##### Output Files

Complete descriptions of the output files can be found in the Plots section above. To learn how to edit the plots, see the visualization tutorial.

• rarecurve.html: rarefaction curve plot
• rarecurve.txt: tabular data used to make the rarefaction curve plot
• samples_being_ignored.txt: list of samples removed from the analysis
• pcoa_*.html: PCoA plots
• pcoa_*.txt: tabular data used to make the PCoA plots
• rarefied_OTU_table.txt: rarefied OTU table used for Bray-Curtis PCoA and alpha diversity plots