Skip to content

Commit

Permalink
add ps_venn and change name of phylo_euler
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Russel committed Feb 19, 2020
1 parent 67b93ea commit 8a44440
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 41 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: MicEco
Title: Various functions for microbial community data
Version: 0.9.6
Version: 0.9.7
Authors@R: person("Jakob", "Russel", email = "[email protected]", role = c("aut", "cre"))
Description: Collection of functions for microbiome analyses. E.g. fitting neutral models and standardized effect sizes of phylogenetic beta diversities, and much more.
Depends: R (>= 3.2.5)
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export(comdistnt.par)
export(community_rrna)
export(neutral.fit)
export(neutral.rand)
export(phylo_euler)
export(proportionality)
export(ps_euler)
export(ps_refactor)
export(ps_venn)
export(rarefy_rrna)
export(rarefy_rrna.matrix)
export(rarefy_rrna.phyloseq)
Expand Down
14 changes: 7 additions & 7 deletions R/phylo_euler.R → R/ps_euler.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#' Make Euler (Venn) diagram of shared taxa (ASVs, OTUs) across sample groups
#' Make Euler diagram of shared taxa (ASVs, OTUs) across sample groups
#'
#' Make Euler (Venn) diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
#' Make Euler diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
#' @param ps A phyloseq object
#' @param group The grouping factor. Should match variable in sample_data(ps)
#' @param weight If TRUE, the overlaps are weighted by abundance
#' @param type "percent" or "count"
#' @param type "percent" or "counts"
#' @param relative Should abundances be made relative
#' @param ... Additional arguments
#' @keywords venn euler diagram
#' @keywords euler diagram
#' @return An euler plot
#' @import phyloseq
#' @import eulerr
#' @importFrom stats aggregate as.formula
#' @export

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

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

if(weight){
df <- euler(ps_mat_bin, weights = rowMeans(ps_mat))
df <- eulerr::euler(ps_mat_bin, weights = rowMeans(ps_mat))
} else {
df <- euler(ps_mat_bin)
df <- eulerr::euler(ps_mat_bin)
}

plot(df, quantities = list(type=type), ...)
Expand Down
40 changes: 40 additions & 0 deletions R/ps_venn.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Make Venn diagram of shared taxa (ASVs, OTUs) across sample groups
#'
#' Make Venn diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance
#' @param ps A phyloseq object
#' @param group The grouping factor. Should match variable in sample_data(ps)
#' @param weight If TRUE, the overlaps are weighted by abundance
#' @param type "percent" or "counts"
#' @param relative Should abundances be made relative
#' @param ... Additional arguments
#' @keywords venn diagram
#' @return An venn plot
#' @import phyloseq
#' @import eulerr
#' @importFrom stats aggregate as.formula
#' @export

ps_venn <- function(ps, group, weight = FALSE, type = "percent", relative = TRUE, ...){

if(relative){
ps <- transform_sample_counts(ps, function(x) x/sum(x))
}

ps_melted <- psmelt(ps)

ps_agg <- aggregate(as.formula(paste("Abundance ~ OTU +",group)), data = ps_melted, function(x) mean(x))

ps_mat <- reshape2::dcast(as.formula(paste("OTU ~ ",group)), data = ps_agg, value.var = "Abundance")

ps_mat <- ps_mat[, -1]
ps_mat_bin <- (ps_mat>0)*1

if(weight){
df <- eulerr::venn(ps_mat_bin, weights = rowMeans(ps_mat))
} else {
df <- eulerr::venn(ps_mat_bin)
}

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

}
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ MicEco: Various functions for analysis for microbial community data
### Citation
[![DOI](https://zenodo.org/badge/83547545.svg)](https://zenodo.org/badge/latestdoi/83547545)

#### ps_venn

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

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

Make Euler diagram of shared taxa (ASVs, OTUs) across sample groups from a phyloseq object. Overlap can be weighted by relative abundance

#### adonis_OmegaSq

Expand Down
30 changes: 0 additions & 30 deletions man/phylo_euler.Rd

This file was deleted.

29 changes: 29 additions & 0 deletions man/ps_euler.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/ps_venn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a44440

Please sign in to comment.