-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jakob Russel
committed
Feb 19, 2020
1 parent
ceedc85
commit 67b93ea
Showing
6 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' Make Euler (Venn) 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 | ||
#' @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 relative Should abundances be made relative | ||
#' @param ... Additional arguments | ||
#' @keywords venn 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, ...){ | ||
|
||
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 <- euler(ps_mat_bin, weights = rowMeans(ps_mat)) | ||
} else { | ||
df <- euler(ps_mat_bin) | ||
} | ||
|
||
plot(df, quantities = list(type=type), ...) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.