Skip to content

Commit

Permalink
Add examples, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakob Russel committed Mar 4, 2019
1 parent 9266758 commit 29e0fe4
Show file tree
Hide file tree
Showing 125 changed files with 1,364 additions and 71 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Authors@R: person("Jakob", "Russel",
Description: Runs multiple differential abundance/expressions methods,
with the same standardized input and output,
to compare their results and test which are better at finding spiked features.
Depends: R (>= 3.5)
Depends: R (>= 3.4)
biocViews: Sequencing,
RNASeq,
Microbiome,
Expand Down Expand Up @@ -50,3 +50,4 @@ License: GPL (>= 3) | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
BugReports: https://github.com/Russel88/DAtest/issues
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export(norm_alr)
export(norm_clr)
export(powerDA)
export(preDA)
export(prune.tests.DA)
export(pruneTests)
export(runtimeDA)
export(spikein)
export(testDA)
Expand Down
4 changes: 0 additions & 4 deletions NEWS

This file was deleted.

9 changes: 9 additions & 0 deletions R/DA.adx.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
#' @param predictor The predictor of interest. Factor, OR if \code{data} is a \code{phyloseq} object the name of the variable in \code{sample_data(data)} in quotation
#' @param ... Additional arguments for the \code{aldex} function
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running ALDEx2
#' res <- DA.adx(data = mat, predictor = pred)
#' @export

DA.adx <- function(data, predictor, ...){
Expand Down
11 changes: 10 additions & 1 deletion R/DA.aoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#' @param allResults If TRUE will return raw results from the \code{aov} function
#' @param ... Additional arguments for the \code{aov} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#'
#' # Running ANOVA on each feature
#' res <- DA.aoa(data = mat, predictor = pred)
#' @export

DA.aoa <- function(data, predictor, covars = NULL, p.adj = "fdr", delta = 1, allResults = FALSE, ...){
Expand Down Expand Up @@ -43,7 +52,7 @@ DA.aoa <- function(data, predictor, covars = NULL, p.adj = "fdr", delta = 1, all
}

# Zero-correction
count_table <- apply(count_table, 2, function(y) vapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
count_table <- apply(count_table, 2, function(y) sapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
if(any(count_table <= 0)) stop("Zero-correction failed. Dataset likely contains too many zeroes")

# ALR transformation
Expand Down
11 changes: 10 additions & 1 deletion R/DA.aoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#' @param allResults If TRUE will return raw results from the \code{aov} function
#' @param ... Additional arguments for the \code{aov} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#'
#' # Running ANOVA on each feature
#' res <- DA.aoc(data = mat, predictor = pred)
#' @export

DA.aoc <- function(data, predictor, covars = NULL, p.adj = "fdr", delta = 1, allResults = FALSE, ...){
Expand Down Expand Up @@ -41,7 +50,7 @@ DA.aoc <- function(data, predictor, covars = NULL, p.adj = "fdr", delta = 1, all
}

# Zero-correction
count_table <- apply(count_table, 2, function(y) vapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
count_table <- apply(count_table, 2, function(y) sapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
if(any(count_table <= 0)) stop("Zero-correction failed. Dataset likely contains too many zeroes")

# ALR transformation
Expand Down
9 changes: 9 additions & 0 deletions R/DA.aov.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#' @param allResults If TRUE will return raw results from the \code{aov} function
#' @param ... Additional arguments for the \code{aov} function
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#'
#' # Running ANOVA on each feature
#' res <- DA.aov(data = mat, predictor = pred)
#' @export

DA.aov <- function(data, predictor, covars = NULL, relative = TRUE, p.adj = "fdr", allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.bay.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
#' @param allResults If TRUE will return raw results from the \code{getLikelihoods} function
#' @param ... Additional arguments to the \code{getPriors.NB} and \code{getLikelihoods} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(100, size = 0.1, mu = 500), nrow = 50, ncol = 10)
#' rownames(mat) <- 1:50
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running baySeq
#' res <- DA.bay(data = mat, predictor = pred)
#' @export

DA.bay <- function(data, predictor, allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.ds2.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#' @param allResults If TRUE will return raw results from the \code{DESeq} function
#' @param ... Additional arguments for the \code{DESeq} function
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(200, size = 0.1, mu = 500), nrow = 20, ncol = 10)
#' rownames(mat) <- 1:20
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running DESeq2
#' res <- DA.ds2(data = mat, predictor = pred)
#' @export

DA.ds2 <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL, p.adj = "fdr", coeff = 2, coeff.ref = 1, allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.ds2x.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#' @param allResults If TRUE will return raw results from the \code{DESeq} function
#' @param ... Additional arguments for the \code{DESeq} function
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(6)
#' mat <- matrix(rnbinom(200, size = 0.2, mu = 500), nrow = 20, ncol = 10)
#' rownames(mat) <- 1:20
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running DESeq2
#' res <- DA.ds2x(data = mat, predictor = pred)
#' @export

DA.ds2x <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL, p.adj = "fdr", coeff = 2, coeff.ref = 1, allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.ere.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
#' @param p.adj Character. P-value adjustment. Default "fdr". See \code{p.adjust} for details
#' @param ... Additional arguments for the \code{calcNormFactors}, \code{estimateCommonDisp}, \code{estimateTagwiseDisp} and \code{exactTest} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running edgeR
#' res <- DA.ere(data = mat, predictor = pred)
#' @export

DA.ere <- function(data, predictor, p.adj = "fdr", ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.ere2.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
#' @param p.adj Character. P-value adjustment. Default "fdr". See \code{p.adjust} for details
#' @param ... Additional arguments for the \code{calcNormFactors}, \code{estimateCommonDisp}, \code{estimateTagwiseDisp} and \code{exactTest} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(5)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running edgeR
#' res <- DA.ere2(data = mat, predictor = pred)
#' @export

DA.ere2 <- function(data, predictor, p.adj = "fdr", ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.erq.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#' @param allResults If TRUE will return raw results from the \code{glmQLFTest} function
#' @param ... Additional arguments for the \code{calcNormFactors}, \code{estimateDisp}, \code{glmQLFit} and \code{glmQLFTest} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running edgeR
#' res <- DA.erq(data = mat, predictor = pred)
#' @export

DA.erq <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL, p.adj = "fdr", coeff = 2, allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.erq2.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#' @param allResults If TRUE will return raw results from the \code{glmQLFTest} function
#' @param ... Additional arguments for the \code{calcNormFactors}, \code{estimateDisp}, \code{glmQLFit} and \code{glmQLFTest} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(5)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running edgeR
#' res <- DA.erq2(data = mat, predictor = pred)
#' @export

DA.erq2 <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL, p.adj = "fdr", coeff = 2, allResults = FALSE, ...){
Expand Down
16 changes: 13 additions & 3 deletions R/DA.fri.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
#' @param allResults If TRUE will return raw results from the \code{friedman.test} function
#' @param ... Additional arguments for the \code{friedman.test} function
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table, predictor, and paired variable
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#' subject <- rep(1:5, 3)
#'
#' # Running Friedman test on each feature
#' res <- DA.fri(data = mat, predictor = pred, paired = subject)
#' @export

DA.fri <- function(data, predictor, paired = NULL, relative = TRUE, p.adj = "fdr", allResults = FALSE, ...){
Expand Down Expand Up @@ -44,9 +54,9 @@ DA.fri <- function(data, predictor, paired = NULL, relative = TRUE, p.adj = "fdr
if(allResults){
return(reslist)
} else {
res <- data.frame(statistic = vapply(reslist, function(x) x$statistic),
parameter = vapply(reslist, function(x) x$parameter),
pval = vapply(reslist, function(x) x$p.value))
res <- data.frame(statistic = sapply(reslist, function(x) x$statistic),
parameter = sapply(reslist, function(x) x$parameter),
pval = sapply(reslist, function(x) x$p.value))
res$pval.adj <- p.adjust(res$pval, method = p.adj)

res$Feature <- gsub(".Friedman.*","",rownames(res))
Expand Down
11 changes: 10 additions & 1 deletion R/DA.kru.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#' @param allResults If TRUE will return raw results from the \code{kruskal.test} function
#' @param ... Additional arguments for the \code{kruskal.test} function
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#'
#' # Running Kruskal-Wallis on each feature
#' res <- DA.kru(data = mat, predictor = pred)
#' @export

DA.kru <- function(data, predictor, relative = TRUE, p.adj = "fdr", allResults = FALSE, ...){
Expand Down Expand Up @@ -41,7 +50,7 @@ DA.kru <- function(data, predictor, relative = TRUE, p.adj = "fdr", allResults =
if(allResults){
return(tests)
} else {
res <- data.frame(pval = vapply(tests, function(x) x$p.value))
res <- data.frame(pval = sapply(tests, function(x) x$p.value))
res$pval.adj <- p.adjust(res$pval, method = p.adj)
res$Feature <- rownames(res)
res$Method <- "Kruskal-Wallis (kru)"
Expand Down
9 changes: 9 additions & 0 deletions R/DA.lao.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
#' @param allResults If TRUE will return raw results from the \code{aov} function
#' @param ... Additional arguments for the \code{aov} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#'
#' # Running ANOVA on each feature
#' res <- DA.lao(data = mat, predictor = pred)
#' @export

DA.lao <- function(data, predictor, covars = NULL, relative = TRUE, p.adj = "fdr", delta = 1, allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.lao2.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
#' @param allResults If TRUE will return raw results from the \code{aov} function
#' @param ... Additional arguments for the \code{aov} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1500, size = 0.1, mu = 500), nrow = 100, ncol = 15)
#' rownames(mat) <- 1:100
#' pred <- c(rep("A", 5), rep("B", 5), rep("C", 5))
#'
#' # Running ANOVA on each feature
#' res <- DA.lao2(data = mat, predictor = pred)
#' @export

DA.lao2 <- function(data, predictor, covars = NULL, p.adj = "fdr", delta = 0.001, allResults = FALSE, ...){
Expand Down
11 changes: 10 additions & 1 deletion R/DA.lia.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#' @param allResults If TRUE will return raw results from the \code{eBayes} function
#' @param ... Additional arguments for the \code{eBayes} and \code{lmFit} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running limma
#' res <- DA.lia(data = mat, predictor = pred)
#' @export

DA.lia <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL, p.adj = "fdr", delta = 1, coeff = 2, allResults = FALSE, ...){
Expand Down Expand Up @@ -46,7 +55,7 @@ DA.lia <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL
}

# Zero-correction
count_table <- apply(count_table, 2, function(y) vapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
count_table <- apply(count_table, 2, function(y) sapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
if(any(count_table <= 0)) stop("Zero-correction failed. Dataset likely contains too many zeroes")

# ALR transformation
Expand Down
11 changes: 10 additions & 1 deletion R/DA.lic.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
#' @param allResults If TRUE will return raw results from the \code{eBayes} function
#' @param ... Additional arguments for the \code{eBayes} and \code{lmFit} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running limma
#' res <- DA.lic(data = mat, predictor = pred)
#' @export

DA.lic <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL, p.adj = "fdr", delta = 1, coeff = 2, allResults = FALSE, ...){
Expand Down Expand Up @@ -46,7 +55,7 @@ DA.lic <- function(data, predictor, paired = NULL, covars = NULL, out.all = NULL
}

# Zero-correction
count_table <- apply(count_table, 2, function(y) vapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
count_table <- apply(count_table, 2, function(y) sapply(y,function(x) ifelse(x==0,delta,(1-(sum(y==0)*delta)/sum(y))*x)))
if(any(count_table <= 0)) stop("Zero-correction failed. Dataset likely contains too many zeroes")

# ALR transformation
Expand Down
9 changes: 9 additions & 0 deletions R/DA.lim.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#' @param allResults If TRUE will return raw results from the \code{eBayes} function
#' @param ... Additional arguments for the \code{eBayes} and \code{lmFit} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running limma
#' res <- DA.lim(data = mat, predictor = pred)
#' @export

DA.lim <- function(data, predictor, paired = NULL, covars = NULL, relative = TRUE, out.all = NULL, p.adj = "fdr", coeff = 2, allResults = FALSE, ...){
Expand Down
9 changes: 9 additions & 0 deletions R/DA.lli.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#' @param allResults If TRUE will return raw results from the \code{eBayes} function
#' @param ... Additional arguments for the \code{eBayes} and \code{lmFit} functions
#' @return A data.frame with with results.
#' @examples
#' # Creating random count_table and predictor
#' set.seed(4)
#' mat <- matrix(rnbinom(1000, size = 0.1, mu = 500), nrow = 100, ncol = 10)
#' rownames(mat) <- 1:100
#' pred <- c(rep("Control", 5), rep("Treatment", 5))
#'
#' # Running limma
#' res <- DA.lli(data = mat, predictor = pred)
#' @export

DA.lli <- function(data, predictor, paired = NULL, covars = NULL, relative = TRUE, out.all = NULL, p.adj = "fdr", delta = 1, coeff = 2, allResults = FALSE, ...){
Expand Down
Loading

0 comments on commit 29e0fe4

Please sign in to comment.