-
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.
add ps_venn and change name of phylo_euler
- Loading branch information
Jakob Russel
committed
Feb 19, 2020
1 parent
67b93ea
commit 8a44440
Showing
8 changed files
with
113 additions
and
41 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
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) | ||
|
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 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), ...) | ||
|
||
} |
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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.