Skip to content

Commit 8a44440

Browse files
author
Jakob Russel
committed
add ps_venn and change name of phylo_euler
1 parent 67b93ea commit 8a44440

8 files changed

Lines changed: 113 additions & 41 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: MicEco
22
Title: Various functions for microbial community data
3-
Version: 0.9.6
3+
Version: 0.9.7
44
Authors@R: person("Jakob", "Russel", email = "[email protected]", role = c("aut", "cre"))
55
Description: Collection of functions for microbiome analyses. E.g. fitting neutral models and standardized effect sizes of phylogenetic beta diversities, and much more.
66
Depends: R (>= 3.2.5)

NAMESPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export(comdistnt.par)
77
export(community_rrna)
88
export(neutral.fit)
99
export(neutral.rand)
10-
export(phylo_euler)
1110
export(proportionality)
11+
export(ps_euler)
1212
export(ps_refactor)
13+
export(ps_venn)
1314
export(rarefy_rrna)
1415
export(rarefy_rrna.matrix)
1516
export(rarefy_rrna.phyloseq)

R/phylo_euler.R renamed to R/ps_euler.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#' Make Euler (Venn) diagram of shared taxa (ASVs, OTUs) across sample groups
1+
#' Make Euler diagram of shared taxa (ASVs, OTUs) across sample groups
22
#'
3-
#' Make Euler (Venn) diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
3+
#' Make Euler diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
44
#' @param ps A phyloseq object
55
#' @param group The grouping factor. Should match variable in sample_data(ps)
66
#' @param weight If TRUE, the overlaps are weighted by abundance
7-
#' @param type "percent" or "count"
7+
#' @param type "percent" or "counts"
88
#' @param relative Should abundances be made relative
99
#' @param ... Additional arguments
10-
#' @keywords venn euler diagram
10+
#' @keywords euler diagram
1111
#' @return An euler plot
1212
#' @import phyloseq
1313
#' @import eulerr
1414
#' @importFrom stats aggregate as.formula
1515
#' @export
1616

17-
phylo_euler <- function(ps, group, weight = FALSE, type = "percent", relative = TRUE, ...){
17+
ps_euler <- function(ps, group, weight = FALSE, type = "percent", relative = TRUE, ...){
1818

1919
if(relative){
2020
ps <- transform_sample_counts(ps, function(x) x/sum(x))
@@ -30,9 +30,9 @@ phylo_euler <- function(ps, group, weight = FALSE, type = "percent", relative =
3030
ps_mat_bin <- (ps_mat>0)*1
3131

3232
if(weight){
33-
df <- euler(ps_mat_bin, weights = rowMeans(ps_mat))
33+
df <- eulerr::euler(ps_mat_bin, weights = rowMeans(ps_mat))
3434
} else {
35-
df <- euler(ps_mat_bin)
35+
df <- eulerr::euler(ps_mat_bin)
3636
}
3737

3838
plot(df, quantities = list(type=type), ...)

R/ps_venn.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' Make Venn diagram of shared taxa (ASVs, OTUs) across sample groups
2+
#'
3+
#' Make Venn diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
4+
#' @param ps A phyloseq object
5+
#' @param group The grouping factor. Should match variable in sample_data(ps)
6+
#' @param weight If TRUE, the overlaps are weighted by abundance
7+
#' @param type "percent" or "counts"
8+
#' @param relative Should abundances be made relative
9+
#' @param ... Additional arguments
10+
#' @keywords venn diagram
11+
#' @return An venn plot
12+
#' @import phyloseq
13+
#' @import eulerr
14+
#' @importFrom stats aggregate as.formula
15+
#' @export
16+
17+
ps_venn <- function(ps, group, weight = FALSE, type = "percent", relative = TRUE, ...){
18+
19+
if(relative){
20+
ps <- transform_sample_counts(ps, function(x) x/sum(x))
21+
}
22+
23+
ps_melted <- psmelt(ps)
24+
25+
ps_agg <- aggregate(as.formula(paste("Abundance ~ OTU +",group)), data = ps_melted, function(x) mean(x))
26+
27+
ps_mat <- reshape2::dcast(as.formula(paste("OTU ~ ",group)), data = ps_agg, value.var = "Abundance")
28+
29+
ps_mat <- ps_mat[, -1]
30+
ps_mat_bin <- (ps_mat>0)*1
31+
32+
if(weight){
33+
df <- eulerr::venn(ps_mat_bin, weights = rowMeans(ps_mat))
34+
} else {
35+
df <- eulerr::venn(ps_mat_bin)
36+
}
37+
38+
plot(df, quantities = list(type=type), ...)
39+
40+
}

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ MicEco: Various functions for analysis for microbial community data
1212
### Citation
1313
[![DOI](https://zenodo.org/badge/83547545.svg)](https://zenodo.org/badge/latestdoi/83547545)
1414

15+
#### ps_venn
1516

16-
#### phylo_euler
17+
Make Venn diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
1718

18-
Make Euler (Venn) diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
19+
#### ps_euler
20+
21+
Make Euler diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
1922

2023
#### adonis_OmegaSq
2124

man/phylo_euler.Rd

Lines changed: 0 additions & 30 deletions
This file was deleted.

man/ps_euler.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/ps_venn.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)