Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Russel committed Feb 19, 2020
1 parent ceedc85 commit 67b93ea
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: MicEco
Title: Various functions for microbial community data
Version: 0.9.5
Version: 0.9.6
Authors@R: person("Jakob", "Russel", email = "russel2620@gmail.com", 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)
Imports: stats, utils, phyloseq, foreach, doSNOW, picante, vegan, snow, bbmle, Hmisc, abind, reshape2
Imports: stats, utils, phyloseq, foreach, doSNOW, picante, vegan, snow, bbmle, Hmisc, abind, reshape2, eulerr
License: GPL (>= 3) | file LICENSE
Encoding: UTF-8
LazyData: true
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(comdistnt.par)
export(community_rrna)
export(neutral.fit)
export(neutral.rand)
export(phylo_euler)
export(proportionality)
export(ps_refactor)
export(rarefy_rrna)
Expand All @@ -24,6 +25,7 @@ export(ses.permtest)
import(Hmisc)
import(bbmle)
import(doSNOW)
import(eulerr)
import(foreach)
import(parallel)
import(phyloseq)
Expand All @@ -32,9 +34,13 @@ import(utils)
import(vegan)
importFrom(abind,abind)
importFrom(reshape2,dcast)
importFrom(stats,aggregate)
importFrom(stats,as.dist)
importFrom(stats,as.formula)
importFrom(stats,cov)
importFrom(stats,dist)
importFrom(stats,dnorm)
importFrom(stats,hclust)
importFrom(stats,na.omit)
importFrom(stats,p.adjust)
importFrom(stats,pbeta)
Expand Down
40 changes: 40 additions & 0 deletions R/phylo_euler.R
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), ...)

}
1 change: 1 addition & 0 deletions R/ps_refactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' @param psmelted A phyloseq object melted into a data.frame with psmelt
#' @param ... Arguments passed to hclust
#' @importFrom reshape2 dcast
#' @importFrom stats dist hclust
#' @export
ps_refactor <- function(psmelted, ...){
if(!is(psmelted, "data.frame")){
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ MicEco: Various functions for analysis for microbial community data
### Citation
[![DOI](https://zenodo.org/badge/83547545.svg)](https://zenodo.org/badge/latestdoi/83547545)


#### phylo_euler

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

#### adonis_OmegaSq

Calculate the unbiased effect size estimation (partial) omega-squared for adonis (PERMANOVA) models
Expand Down
30 changes: 30 additions & 0 deletions man/phylo_euler.Rd

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

0 comments on commit 67b93ea

Please sign in to comment.