Skip to content

Commit ab887dc

Browse files
committed
d
1 parent 3ca63f7 commit ab887dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+12128
-38264
lines changed

.Rhistory

+42-42
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,3 @@
1-
labs(y = "Diversity", x = "", title = paste0("Kruskal test p=", round(pv, 2)))
2-
df <- meta(phy)
3-
df <- bind_cols(df, A)
4-
df$index <- df[[index]]
5-
pv <- kruskal.test(data = df, index ~ factor(bmi_group))$p.value
6-
p1 <- ggplot(df, aes(x = bmi_group, y = index, fill = bmi_group)) + geom_boxplot() +
7-
labs(y = "Diversity", x = "", title = paste0("Kruskal test p=", round(pv, 2)))
8-
print(p1)
9-
p2 <- ggplot(df, aes(fill = bmi_group, x = index)) +
10-
geom_density(alpha = 0.5) + labs(x = "Diversity", y = "Density")
11-
print(p2)
12-
p1 <- ggplot(df, aes(x = bmi_group, y = index, fill = bmi_group)) + geom_boxplot() +theme(axis.line.x = element_text(angle = 60, hjust = 1)) +
13-
labs(y = "Diversity", x = "", title = paste0("Kruskal test p=", round(pv, 2)))
14-
df <- meta(phy)
15-
df <- bind_cols(df, A)
16-
df$index <- df[[index]]
17-
pv <- kruskal.test(data = df, index ~ factor(bmi_group))$p.value
18-
p1 <- ggplot(df, aes(x = bmi_group, y = index, fill = bmi_group)) + geom_boxplot() + theme(axis.text.x = element_text(angle = 60, hjust = 1)) +
19-
labs(y = "Diversity", x = "", title = paste0("Kruskal test p=", round(pv, 2)))
20-
print(p1)
21-
p2 <- ggplot(df, aes(fill = bmi_group, x = index)) +
22-
geom_density(alpha = 0.5) + labs(x = "Diversity", y = "Density")
23-
print(p2)
24-
library(dplyr)
25-
source("functions.R")
26-
library(dplyr)
27-
#source("functions.R")
28-
phy.clr <- phy %>% microbiome::transform("compositional")
29-
genus.stress.clr <- phy.clr %>% abundances() %>% t
30-
permutations <- 999
31-
controls <- c()
32-
independent_vars <- "Group" # Groupings to compare
33-
alpha_level <- 0.05
34-
library(vegan)
35-
library(magrittr)
36-
library(tibble)
37-
permanova_results <- lapply(independent_vars, function(var) do_permanova(pseq = phy.clr,
38-
group = var,
39-
permutations = permutations)) %>%
40-
set_names(independent_vars) %>%
41-
do.call(rbind, .) %>%
42-
m_neat(colnames = c("variable", "R2", "p_value")) %>%
431
mutate(padj_value = p.adjust(p_value, "BH")) %>%
442
arrange(variable)
453
library(dplyr)
@@ -510,3 +468,45 @@ rmarkdown::render('continuous_variable.rmd','md_document')
510468
getwd()
511469
setwd('D:/Seafile/My Library/Important/Final_microbiome/tutorials')
512470
rmarkdown::render('Tutorial.rmd','all')
471+
# Load libraries
472+
library(microbiome)
473+
library(ggplot2)
474+
library(magrittr)
475+
library(dplyr)
476+
# Probiotics intervention example data
477+
data(dietswap)
478+
# Only check the core taxa to speed up examples
479+
pseq <- core(dietswap, detection = 50, prevalence = 80/100)
480+
library(phyloseq)
481+
library(reshape2)
482+
library(DESeq2)
483+
library(knitr)
484+
library(magrittr)
485+
# Running the DESeq2 analysis
486+
ds2 <- phyloseq_to_deseq2(pseq, ~ nationality)
487+
dds <- DESeq(ds2)
488+
res <- results(dds)
489+
df <- as.data.frame(res)
490+
df$taxon <- rownames(df)
491+
df <- df %>% arrange(log2FoldChange, padj)
492+
library(knitr)
493+
print(head(kable((df))))
494+
# Identify top taxa based on standard ANOVA
495+
source(system.file("extdata/check_anova.R", package = "microbiome"))
496+
ano <- check_anova(pseq, "nationality");
497+
ano$log2FC <- log2(ano$ave.AFR) - log2(ano$ave.AAM)
498+
taxa.anova <- as.character(subset(ano, padj < 0.01 & abs(log2FC) > log2(2))$taxa)
499+
# lowPick the top taxa based on DESEq2
500+
taxa.deseq <- subset(res, padj < 0.01 & abs(log2FoldChange) > log2(2))$taxon
501+
# Check overlap
502+
# Most DESEq2 taxa are confirmed with ANOVA
503+
library(gplots)
504+
#venn( list(ANOVA = taxa.anova,DESeq2 = taxa.deseq) )
505+
# Also the est p-values are well correlated (higher not so)
506+
mf<-data.frame(df$padj, ano$padj)
507+
p<-ggplot(mf, aes(x = log10(df$padj), y = log10(ano$padj))) + xlab('DESeq2 adjusted p-value') + ylab('ANOVA adjusted p-value')
508+
p<- p + geom_point()
509+
#plot(xlim=log10(df$padj), log10(ano$padj), type = 'l', xlim = "DESeq2 adjusted p-value", ylim("ANOVA adjusted p-value"))
510+
venn( list(ANOVA = taxa.anova,DESeq2 = taxa.deseq))
511+
print(p)
512+
rmarkdown::render('deseq2.Rmd','all')

Atlas.html

+222-1,364
Large diffs are not rendered by default.

Betadiversity.html

+280-1,425
Large diffs are not rendered by default.

Bimodality.html

+278-1,424
Large diffs are not rendered by default.

Clustering.html

+252-1,396
Large diffs are not rendered by default.

Comparisons.html

+217-1,300
Large diffs are not rendered by default.

Composition.html

+338-1,481
Large diffs are not rendered by default.

CompositionAmplicondata.html

+263-1,403
Large diffs are not rendered by default.

CompositionAmplicondata2.html

+483-237
Large diffs are not rendered by default.

Contributing.html

+216-1,297
Large diffs are not rendered by default.

Core.Rmd

+2-58
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ p <- plot_core(pseq, plot.type = "heatmap",
135135
prevalences = prevalences,
136136
detections = detections,
137137
colours = rev(brewer.pal(5, "Spectral")),
138-
min.prevalence = .2, horizontal = TRUE)
138+
min.prevalence = .2, horizontal = TRUE)
139139
print(p)
140140
```
141141

@@ -323,7 +323,7 @@ detections <- 10^seq(log10(1e-5), log10(.2), length = 10)
323323
gray <- gray(seq(0,1,length=5))
324324
p <- plot_core(pseq.rel, plot.type = "heatmap", colours = gray,
325325
prevalences = prevalences, detections = detections, min.prevalence = .5) +
326-
xlab("Detection Threshold (Relative Abundance (%))")
326+
labs(x = "Detection Threshold (Relative Abundance (%))")
327327
print(p)
328328
329329
@@ -336,59 +336,3 @@ library(viridis)
336336
print(p + scale_fill_viridis())
337337
```
338338

339-
As it can be seen, we see only OTu IDs and this may not be useful to interpret the data. We need to repreoccess this figure to include taxonomic information. We can do this as follows:
340-
341-
```{r,core-example4, fig.width=14, fig.heigth=18, fig.show='hold', out.width = '200px', warning=FALSE, eval=FALSE}
342-
library(RColorBrewer)
343-
library(knitr)
344-
# Core with absolute counts and vertical view:
345-
# and minimum population prevalence (given as percentage)
346-
detections <- 10^seq(log10(1), log10(max(abundances(pseq.2))/10), length = 10)
347-
348-
healthycore <- plot_core(pseq.2, plot.type = "heatmap",
349-
prevalences = prevalences,
350-
detections = detections,
351-
colours = rev(brewer.pal(5, "Spectral")),
352-
min.prevalence = .90, horizontal = F)
353-
# get the data used for plotting
354-
df <- healthycore$data
355-
356-
# get the list of OTUs
357-
list <- df$Taxa
358-
359-
# check the OTU ids
360-
# print(list)
361-
362-
# get the taxonomy data
363-
tax <- tax_table(pseq.2)
364-
tax <- as.data.frame(tax)
365-
366-
# add the OTus to last column
367-
tax$OTU <- rownames(tax)
368-
369-
# select taxonomy of only
370-
# those OTUs that are used in the plot
371-
tax2 <- dplyr::filter(tax, rownames(tax) %in% list)
372-
373-
# head(tax2)
374-
375-
# We will merege all the column into one except the Doamin as all is bacteria in this case
376-
tax.unit <- tidyr::unite(tax2, Taxa_level,c("Domain", "Phylum", "Class", "Order", "Family", "Genus", "Species", "OTU"), sep = "_;", remove = TRUE)
377-
378-
tax.unit$Taxa_level <- gsub(pattern="[a-z]__",replacement="", tax.unit$Taxa_level)
379-
380-
# add this new information into the plot data df
381-
382-
df$Taxa <- tax.unit$Taxa_level
383-
384-
# you can see now we have the taxonomic information
385-
knitr::kable(head(df))
386-
387-
# replace the data in the plot object
388-
healthycore$data <- df
389-
390-
plot(healthycore + theme(axis.text.y = element_text(face="italic")))
391-
```
392-
393-
394-

Core.html

+415-1,569
Large diffs are not rendered by default.

CoremicrobiotaAmplicon.html

+368-1,512
Large diffs are not rendered by default.

Data.html

+381-105
Large diffs are not rendered by default.

Experimental.html

+373-1,536
Large diffs are not rendered by default.

Heatmap.html

+452-182
Large diffs are not rendered by default.

Installation.html

+233-1,379
Large diffs are not rendered by default.

Interactive.html

+1,430-123
Large diffs are not rendered by default.

Landscaping.html

+285-1,429
Large diffs are not rendered by default.

Mixedmodels.html

+242-1,385
Large diffs are not rendered by default.

Negativebinomial.html

+238-1,380
Large diffs are not rendered by default.

Networks.html

+266-1,406
Large diffs are not rendered by default.

Ordination.html

+421-148
Large diffs are not rendered by default.

Output.html

+226-1,366
Large diffs are not rendered by default.

PERMANOVA.html

+397-124
Large diffs are not rendered by default.

PlotDiversity.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ This returns a table with selected diversity indicators. Check a separate page o
4646
4747
ps1 <- prune_taxa(taxa_sums(pseq) > 0, pseq)
4848
49-
tab <- alpha(ps1, index = "all")
49+
tab <- microbiome::alpha(ps1, index = "all")
5050
kable(head(tab))
5151
5252
```

PlotDiversity.html

+243-1,396
Large diffs are not rendered by default.

Preprocessing.Rmd

+3-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ data(dietswap)
158158
x <- dietswap
159159
# Compositional data
160160
x2 <- microbiome::transform(x, "compositional")
161+
```
161162

163+
```{r data10bb, echo=FALSE, warning=FALSE, message=FALSE, results="hide"}
162164
# library(zCompositions)
163165
# This would be recommended for compositional zero-inflated data:
164166
# KMSS replacement for zero-inflated compositional values
@@ -186,7 +188,7 @@ Assign new fields to metadata
186188

187189
```{r preprocess4b2, warning=FALSE, message=FALSE}
188190
# Calculate diversity for samples
189-
div <- alpha(pseq, index = "shannon")
191+
div <- microbiome::alpha(pseq, index = "shannon")
190192
191193
# Assign the estimated diversity to sample metadata
192194
sample_data(pseq)$diversity <- div

Preprocessing.html

+335-1,475
Large diffs are not rendered by default.

Probelevel.html

+239-1,382
Large diffs are not rendered by default.

RDA.html

+391-119
Large diffs are not rendered by default.

README.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ <h3>Contribute</h3>
382382
<ul>
383383
<li><a href="https://github.com/microbiome/microbiome/issues">Issue Tracker</a></li>
384384
<li><a href="https://github.com/microbiome/microbiome/">Pull requests</a></li>
385-
<li>Subscribe to the <a href="https://groups.google.com/forum/#!forum/microbiome-devel">mailing list</a> (<a href="mailto:[email protected]" class="email">[email protected]</a>)</li>
385+
<li>Subscribe to the <a href="https://groups.google.com/forum/#!forum/microbiome-devel">mailing list</a> (<a href="mailto:[email protected]">[email protected]</a>)</li>
386386
<li><a href="https://github.com/microbiome/microbiome">Star us on the Github page</a></li>
387387
</ul>
388388
</div>
389389
<div id="publications-using-the-microbiome-package" class="section level3">
390390
<h3>Publications using the microbiome package</h3>
391-
<p><strong>Kindly cite this work</strong> as follows: &quot;Leo Lahti <a href="https://github.com/microbiome/microbiome/graphs/contributors">et al.</a> (2017). Tools for microbiome analysis in R. Microbiome package version 1.6.0. URL: <a href="https://microbiome.github.io/tutorials">http://microbiome.github.com/microbiome</a>, and the relevant references listed in the manual page of each function. The list of publications is not exhaustive. Let us know if you know of further publications using the microbiome package; we are collecting these on the website.</p>
391+
<p><strong>Kindly cite this work</strong> as follows: &quot;Leo Lahti <a href="https://github.com/microbiome/microbiome/graphs/contributors">et al.</a> (2017). Tools for microbiome analysis in R. Microbiome package version 1.9.1. URL: <a href="https://microbiome.github.io/tutorials">http://microbiome.github.com/microbiome</a>, and the relevant references listed in the manual page of each function. The list of publications is not exhaustive. Let us know if you know of further publications using the microbiome package; we are collecting these on the website.</p>
392392
<p><a href="https://academic.oup.com/femsre/article/doi/10.1093/femsre/fuw045/2979411/Intestinal-microbiome-landscaping-insight-in#58802539">Intestinal microbiome landscaping: Insight in community assemblage and implications for microbial modulation strategies</a>. Shetty S, Hugenholtz F, Lahti L, Smidt H, de Vos WM, Danchin A. <em>FEMS Microbiology Reviews</em> fuw045, 2017.</p>
393393
<p><a href="http://dx.doi.org/10.1016/j.mib.2015.04.004">Metagenomics meets time series analysis: unraveling microbial community dynamics</a> Faust K, Lahti L, Gonze D, de Vos WM, Raes J. <em>Current Opinion in Microbiology</em> 15:56-66 2015.</p>
394394
<p><a href="http://www.nature.com/ncomms/2014/140708/ncomms5344/full/ncomms5344.html">Tipping elements in the human intestinal ecosystem</a> Lahti L, Salojärvi J, Salonen A, Scheffer M, de Vos WM. <em>Nature Communications</em> 5:4344, 2014.</p>

Stability.html

+276-1,421
Large diffs are not rendered by default.

TODO.Rmd

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ List of issues to improve the package and tutorials:
1818
* Lay out overall project roadmap
1919
* Consider package/tutorial collection instead of a single package
2020

21+
### Missing examples
22+
23+
* is_compositional
24+
2125
### Related work
2226

2327
* [metagenomeSeq](https://bioconductor.org/packages/release/bioc/html/metagenomeSeq.html)

Themes.html

+294-1,438
Large diffs are not rendered by default.

Tutorial.html

+252-1,407
Large diffs are not rendered by default.

Visualization.html

+365-88
Large diffs are not rendered by default.

all.Rmd

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ Long tails of rare taxa:
318318

319319
```{r tail, warning=FALSE, message=print, fig.width=16, fig.height=8, out.width="200px"}
320320
medians <- apply(abundances(d),1,median)/1e3
321+
library(reshape2)
321322
A <- melt(abundances(d))
322323
A$Var1 <- factor(A$Var1, levels = rev(names(sort(medians))))
323324
p <- ggplot(A, aes(x = Var1, y = value)) +

all.html

+611-338
Large diffs are not rendered by default.

deseq2.html

+4-4
Large diffs are not rendered by default.

index.html

+218-1,311
Large diffs are not rendered by default.

limma.html

+279-1,424
Large diffs are not rendered by default.

misc.Rmd

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
As it can be seen, we see only OTu IDs and this may not be useful to interpret the data. We need to reprccess this figure to include taxonomic information. We can do this as follows:
2+
3+
```{r,core-example4, fig.width=14, fig.heigth=18, fig.show='hold', out.width = '200px', warning=FALSE, eval=FALSE}
4+
library(RColorBrewer)
5+
library(knitr)
6+
# Core with absolute counts and vertical view:
7+
# and minimum population prevalence (given as percentage)
8+
detections <- 10^seq(log10(1), log10(max(abundances(pseq.2))/10), length = 10)
9+
10+
healthycore <- plot_core(pseq.2, plot.type = "heatmap",
11+
prevalences = prevalences,
12+
detections = detections,
13+
colours = rev(brewer.pal(5, "Spectral")),
14+
min.prevalence = .9)
15+
# get the data used for plotting
16+
df <- healthycore$data
17+
18+
# get the list of OTUs
19+
list <- df$Taxa
20+
21+
# check the OTU ids
22+
# print(list)
23+
24+
# get the taxonomy data
25+
tax <- tax_table(pseq.2)
26+
tax <- as.data.frame(tax)
27+
28+
# add the OTus to last column
29+
tax$OTU <- rownames(tax)
30+
31+
# select taxonomy of only
32+
# those OTUs that are used in the plot
33+
tax2 <- dplyr::filter(tax, rownames(tax) %in% list)
34+
35+
# head(tax2)
36+
37+
# We will merege all the column into one except the Doamin as all is bacteria in this case
38+
tax.unit <- tidyr::unite(tax2, Taxa_level,c("Domain", "Phylum", "Class", "Order", "Family", "Genus", "Species", "OTU"), sep = "_;", remove = TRUE)
39+
40+
tax.unit$Taxa_level <- gsub(pattern="[a-z]__",replacement="", tax.unit$Taxa_level)
41+
42+
# add this new information into the plot data df
43+
44+
df$Taxa <- tax.unit$Taxa_level
45+
46+
# you can see now we have the taxonomic information
47+
knitr::kable(head(df))
48+
49+
# replace the data in the plot object
50+
healthycore$data <- df
51+
52+
plot(healthycore + theme(axis.text.y = element_text(face="italic")))
53+
```
54+
55+
56+

rstanarm.html

+234-1,386
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)