forked from YuLab-SMU/MicrobiotaProcess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrobiotaProcess-basics.Rmd
198 lines (161 loc) · 7.88 KB
/
MicrobiotaProcess-basics.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
---
title: "basics analysis using MicrobiotaProcess"
author: |
| Shuangbin Xu
| School of Basic Medical Sciences, Southern Medical University
date: "`r Sys.Date()`"
bibliography: MicrobiotaProcess.bib
biblio-style: apalike
output:
prettydoc::html_pretty:
toc: true
theme: cayman
highlight: vignette
pdf_document:
toc: true
vignette: >
%\VignetteIndexEntry{ MicrobiotaProcess: basics analysis using MicrobiotaProcess.}
%\VignetteEngine{knitr::rmarkdown}
%\usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
---
```{r, echo=FALSE, results="asis", message=FALSE, KnitrSetUp}
knitr::opts_chunk$set(tidy=FALSE,warning=FALSE,message=FALSE)
Biocpkg <- function (pkg){
sprintf("[%s](http://bioconductor.org/packages/%s)", pkg, pkg)
}
CRANpkg <- function(pkg){
cran <- "https://CRAN.R-project.org/package"
fmt <- "[%s](%s=%s)"
sprintf(fmt, pkg, cran, pkg)
}
```
```{r, echo=FALSE, results="hide", message=FALSE, Loadpackages}
library(ggplot2)
library(DT)
library(tidyverse)
library(phyloseq)
library(ggtree)
library(treeio)
library(tidytree)
library(MicrobiotaProcess)
```
# 1. Introduction
`MicrobiotaProcess` is an R package for analysis, visualization and biomarker discovery of microbial datasets. It supports the import of microbiome census data, calculating alpha index and provides functions to visualize rarefaction curves. Moreover, it also supports visualizing the abundance of taxonomy of samples. And It also provides functions to perform the `PCA`, `PCoA` and hierarchical cluster analysis. In addition, `MicrobiotaProcess` also provides a method for the biomarker discovery of metagenome or other datasets.
# 2. `MicrobiotaProcess` profiling
## 2.1 import function
`MicrobiotaProcess` has an feature to import phylogenetic sequencing data from `r Biocpkg("dada2")`[@callahan2016dada2] and [qiime2](https://qiime2.org/)[@bolyen2019qiime2] taxonomic clustering pipelines. The resulting object after import is `r Biocpkg("phyloseq")` object[@Paul2013phyloseq]
```{r, error=FALSE, importFunction}
# import data from dada2 pipeline.
seqtabfile <- system.file("extdata", "seqtab.nochim.rds", package="MicrobiotaProcess")
seqtab <- readRDS(seqtabfile)
taxafile <- system.file("extdata", "taxa_tab.rds",package="MicrobiotaProcess")
seqtab <- readRDS(seqtabfile)
taxa <- readRDS(taxafile)
# the seqtab and taxa are output of dada2
sampleda <- system.file("extdata", "mouse.time.dada2.txt", package="MicrobiotaProcess")
ps_dada2 <- import_dada2(seqtab=seqtab, taxatab=taxa, sampleda=sampleda)
ps_dada2
# import data from qiime2 pipeline
otuqzafile <- system.file("extdata", "table.qza", package="MicrobiotaProcess")
taxaqzafile <- system.file("extdata", "taxa.qza", package="MicrobiotaProcess")
mapfile <- system.file("extdata", "metadata_qza.txt", package="MicrobiotaProcess")
ps_qiime2 <- import_qiime2(otuqza=otuqzafile, taxaqza=taxaqzafile, mapfilename=mapfile)
ps_qiime2
```
## 2.2 Rarefaction visualization
Rarefaction, based on sampling technique, was used to compensate for the effect of sample size on the number of units observed in a sample[@siegel2004rarefaction]. `MicrobiotaProcess` provided `ggrarecurve` to plot the curves, based on `rrarefy` of `r CRANpkg("vegan")`[@Jari2019vegan].
```{r, error=FALSE, fig.align="center", fig.height=3.2, fig.width=7.5, rarefaction}
# for reproducibly random number
set.seed(1024)
p_rare <- ggrarecurve(obj=ps_dada2,
indexNames=c("Observe","Chao1","ACE"),
chunks=300) +
theme(legend.spacing.y=unit(0.02,"cm"),
legend.text=element_text(size=6))
p_rare
```
## 2.3 calculate alpha index and visualization
`MicrobiotaProcess` provides `get_alphaindex` to calculate alpha index and the `ggbox` to visualize the result
```{r, error=FALSE, fig.width=7.5, fig.height=3.2, fig.align="center", alphaindex}
alphaobj <- get_alphaindex(ps_dada2)
head(as.data.frame(alphaobj))
p_alpha <- ggbox(alphaobj, geom="violin", factorNames="time") +
scale_fill_manual(values=c("#2874C5", "#EABF00"))+
theme(strip.background = element_rect(colour=NA, fill="grey"))
p_alpha
```
## 2.4 The visualization of taxonomy abundance
`MicrobiotaProcess` presents the `ggbartax` for the visualization of composition of microbial communities.
```{r, error=FALSE, fig.align="center", fig.height=4.5, fig.width=7, taxabar}
# relative abundance
otubar <- ggbartax(obj=ps_dada2) +
xlab(NULL) +
ylab("relative abundance (%)")
otubar
```
If you want to get the abundance of specific levels of class, You can use `get_taxadf` then use `ggbartax` to visualize.
```{r, error=FALSE, fig.align="center", fig.height=4.5, fig.width=7, phylumAbundance}
phytax <- get_taxadf(obj=ps_dada2, taxlevel=2)
phybar <- ggbartax(obj=phytax) +
xlab(NULL) + ylab("relative abundance (%)")
phybar
```
Moreover, the abundance (count) of taxonomy also can be visualized by setting count to TRUE, and the facet of plot can be showed by setting the facetNames.
```{r, error=FALSE, fig.align="center", fig.height=4.5, fig.width=7, classAbundance}
phybar2 <- ggbartax(obj=phytax, facetNames="time", count=TRUE) + xlab(NULL) + ylab("abundance")
phybar2
classtax <- get_taxadf(obj=ps_dada2, taxlevel=3)
classbar <- ggbartax(obj=classtax, facetNames="time", count=FALSE) +
xlab(NULL) + ylab("relative abundance (%)")
classbar
```
## 2.5 PCA and PCoA analysis
`PCA` (Principal component analysis) and `PCoA` (Principal Coordinate Analysis) are general statistical procedures to compare groups of samples. And `PCoA` can based on the phylogenetic or count-based distance metrics, such as `Bray-Curtis`, `Jaccard`, `Unweighted-UniFrac` and `weighted-UniFrac`. `MicrobiotaProcess` presents the `get_pca`, `get_pcoa` and `ggordpoint` for the analysis.
```{r, error=FALSE, fig.align="center", fig.height=4.5, fig.width=6, ordanalysis}
pcares <- get_pca(obj=ps_dada2, method="hellinger")
# Visulizing the result
pcaplot <- ggordpoint(obj=pcares, biplot=TRUE, speciesannot=TRUE,
factorNames=c("time"), ellipse=TRUE) +
scale_color_manual(values=c("#2874C5", "#EABF00"))
pcaplot
pcoares <- get_pcoa(obj=ps_dada2, distmethod="euclidean", method="hellinger")
# Visualizing the result
pcoaplot <- ggordpoint(obj=pcoares, biplot=TRUE, speciesannot=TRUE,
factorNames=c("time"), ellipse=TRUE) +
scale_color_manual(values=c("#2874C5", "#EABF00"))
pcoaplot
```
## 2.6 Hierarchical cluster analysis
`beta diversity` metrics can assess the differences between microbial communities. It can be visualized with `PCA` or `PCoA`, this can also be visualized with hierarchical clustering. `MicrobiotaProcess` also implements the analysis based on ggtree[@yu2017ggtree].
```{r, fig.align="center", fig.height=5, fig.width=6, error=FALSE, hclustAnalysis}
hcsample <- get_clust(obj=ps_dada2, distmethod="euclidean",
method="hellinger", hclustmethod="average")
# rectangular layout
clustplot1 <- ggclust(obj=hcsample,
layout = "rectangular",
pointsize=1,
fontsize=0,
factorNames=c("time")) +
scale_color_manual(values=c("#2874C5", "#EABF00")) +
theme_tree2(legend.position="right",
plot.title = element_text(face="bold", lineheight=25,hjust=0.5))
clustplot1
# circular layout
clustplot2 <- ggclust(obj=hcsample,
layout = "circular",
pointsize=1,
fontsize=2,
factorNames=c("time")) +
scale_color_manual(values=c("#2874C5", "#EABF00")) +
theme(legend.position="right")
clustplot2
```
# 3. Need helps?
If you have questions/issues, please visit [github issue tracker](https://github.com/YuLab-SMU/MicrobiotaProcess/issues).
# 4. Session information
Here is the output of sessionInfo() on the system on which this document was compiled:
```{r, echo=FALSE}
sessionInfo()
```
# 5. References