From bf17cb4deffd636e9f4793e3afb867ed7574f0ec Mon Sep 17 00:00:00 2001 From: suzannejin Date: Thu, 24 Oct 2024 15:45:24 +0200 Subject: [PATCH 1/4] unsort graflex output --- R/3-shared-graflex.R | 3 --- 1 file changed, 3 deletions(-) diff --git a/R/3-shared-graflex.R b/R/3-shared-graflex.R index 29825b4..e82a3fc 100644 --- a/R/3-shared-graflex.R +++ b/R/3-shared-graflex.R @@ -47,8 +47,5 @@ runGraflex <- function(A, K, p=100, ncores=1) { # change the values to numeric, except for the concept column res[,1:9] <- lapply(res[,1:9], as.numeric) - # sort the results by the odds ratio - res <- res[order(res$Odds, decreasing=TRUE),] - return(res) } From 5ceb49599fd9c32d28610ff4d4984b9f80e8ed8c Mon Sep 17 00:00:00 2001 From: suzannejin Date: Thu, 24 Oct 2024 15:45:50 +0200 Subject: [PATCH 2/4] [bug] fix bug related to using custom_cutoffs with updateCutoffs --- R/3-shared-updateCutoffs.R | 4 ++-- tests/testthat/test-SHARED-updateCutoffs-propd.R | 10 ++++++++-- tests/testthat/test-SHARED-updateCutoffs-propr.R | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/R/3-shared-updateCutoffs.R b/R/3-shared-updateCutoffs.R index 6e1b870..3006b67 100644 --- a/R/3-shared-updateCutoffs.R +++ b/R/3-shared-updateCutoffs.R @@ -71,7 +71,7 @@ updateCutoffs.propr <- object@tails <- tails # get cutoffs - if (is.na(custom_cutoffs)) { + if (length(custom_cutoffs) == 1 && is.na(custom_cutoffs)) { vals <- object@results$propr if (tails == 'right') { vals <- vals[vals >= 0] @@ -203,7 +203,7 @@ updateCutoffs.propd <- stop("Permutation testing is disabled.") # get cutoffs - if (is.na(custom_cutoffs)) { + if (length(custom_cutoffs) == 1 && is.na(custom_cutoffs)) { cutoffs <- as.numeric(quantile(object@results$theta, seq(0, 1, length.out = number_of_cutoffs))) } else { cutoffs <- custom_cutoffs diff --git a/tests/testthat/test-SHARED-updateCutoffs-propd.R b/tests/testthat/test-SHARED-updateCutoffs-propd.R index bb5d419..e2e708d 100644 --- a/tests/testthat/test-SHARED-updateCutoffs-propd.R +++ b/tests/testthat/test-SHARED-updateCutoffs-propd.R @@ -102,13 +102,19 @@ test_that("updateCutoffs.propd properly set up cutoffs", { # get propd object and update cutoffs pd <- propd(x, as.character(y), p=10) - pd <- updateCutoffs(pd, number_of_cutoffs=10) + pd1 <- updateCutoffs(pd, number_of_cutoffs=10) # get cutoffs cutoffs <- as.numeric( quantile(pd@results$theta, probs = seq(0, 1, length.out = 10)) ) + # run with cutoffs + pd2 <- updateCutoffs(pd, custom_cutoffs=cutoffs) + # check that cutoffs are properly defined - expect_equal(pd@fdr$cutoff, cutoffs) + expect_equal(pd1@fdr$cutoff, cutoffs) + + # check that the two calls agree + expect_equal(pd1@fdr, pd2@fdr) }) test_that("updateCutoffs.propd properly calculates truecounts", { diff --git a/tests/testthat/test-SHARED-updateCutoffs-propr.R b/tests/testthat/test-SHARED-updateCutoffs-propr.R index a387575..00b581b 100644 --- a/tests/testthat/test-SHARED-updateCutoffs-propr.R +++ b/tests/testthat/test-SHARED-updateCutoffs-propr.R @@ -165,7 +165,7 @@ test_that("updateCutoffs.propr properly set up cutoffs", { pr <- propr(X, metric = "pcor.bshrink", p=10) # get cutoffs - values <- pr@matrix[lower.tri(pr@matrix)] + values <- pr@results$propr cutoffs_right <- as.numeric( quantile(values[values >= 0], probs = seq(0, 1, length.out = 10)) ) cutoffs_both <- as.numeric( quantile(abs(values), probs = seq(0, 1, length.out = 10)) ) @@ -182,6 +182,14 @@ test_that("updateCutoffs.propr properly set up cutoffs", { updateCutoffs(pr, number_of_cutoffs=10)@fdr$cutoff, cutoffs_both ) + expect_equal( + updateCutoffs(pr, custom_cutoffs=cutoffs_both)@fdr, + updateCutoffs(pr, number_of_cutoffs=10)@fdr + ) + expect_equal( + updateCutoffs(pr, custom_cutoffs=cutoffs_right, tails='right')@fdr, + updateCutoffs(pr, number_of_cutoffs=10, tails='right')@fdr + ) }) test_that("updateCutoffs.propr properly calculates truecounts", { From 1da228babfef0e80781a8267f791af87989b4ecc Mon Sep 17 00:00:00 2001 From: suzannejin Date: Thu, 24 Oct 2024 16:08:53 +0200 Subject: [PATCH 3/4] make 'right' test the default for FDR tests --- R/3-shared-updateCutoffs.R | 19 ++++++------------- .../testthat/test-SHARED-getAdjacency-propr.R | 2 +- .../test-SHARED-updateCutoffs-propr.R | 8 ++++---- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/R/3-shared-updateCutoffs.R b/R/3-shared-updateCutoffs.R index 3006b67..7bfeac3 100644 --- a/R/3-shared-updateCutoffs.R +++ b/R/3-shared-updateCutoffs.R @@ -13,10 +13,10 @@ #' cutoffs will be evenly spaced across the data. #' @param custom_cutoffs A numeric vector. When provided, this vector is used as the set of #' cutoffs to test, and 'number_of_cutoffs' is ignored. -#' @param tails NA or 'right' or 'both'. 'right' is for one-sided on the right. 'both' for -#' symmetric two-sided test. If NA, use default value according to the property -#' `has_meaningful_negative_values`. This is only relevant for \code{propr} objects, as -#' \code{propd} objects are always one-sided and only have positive values. +#' @param tails 'right' or 'both'. 'right' is for one-sided on the right. 'both' for +#' symmetric two-sided test. This is only relevant for \code{propr} objects, as +#' \code{propd} objects are always one-sided and only have positive values. Default +#' is 'right'. #' @param ncores An integer. The number of parallel cores to use. #' @return A \code{propr} or \code{propd} object with the FDR slot updated. #' @@ -25,7 +25,7 @@ updateCutoffs <- function(object, number_of_cutoffs = 100, custom_cutoffs = NA, - tails = NA, + tails = 'right', ncores = 1) { if (inherits(object, "propr")) { @@ -53,7 +53,7 @@ updateCutoffs.propr <- function(object, number_of_cutoffs = 100, custom_cutoffs = NA, - tails = NA, + tails = 'right', ncores = 1) { if (identical(object@permutes, list(NULL))) { stop("Permutation testing is disabled.") @@ -61,13 +61,6 @@ updateCutoffs.propr <- if (object@metric == "phi") { warning("We recommend using the symmetric phi 'phs' for FDR permutation.") } - - # handle right/both tails FDR test - if (is.na(tails)) { - tails <- ifelse(object@has_meaningful_negative_values, 'both', 'right') # default option - } else if (!tails %in% c('right','both')) { - stop("Provided 'tails' not recognized.") - } object@tails <- tails # get cutoffs diff --git a/tests/testthat/test-SHARED-getAdjacency-propr.R b/tests/testthat/test-SHARED-getAdjacency-propr.R index 8ff9507..ce65e4e 100644 --- a/tests/testthat/test-SHARED-getAdjacency-propr.R +++ b/tests/testthat/test-SHARED-getAdjacency-propr.R @@ -134,7 +134,7 @@ test_that("getAdjacencyFDR returns the expected values for phs - 5", { test_that("getAdjacencyFDR and getSignificantResultsFDR return coherent results", { - for (metric in c('rho', 'phi', 'phs', 'pcor', 'pcor.shrink', 'pcor.bshrink')){ + for (metric in c('rho', 'phi', 'phs', 'pcor', 'pcor.bshrink')) { # pcor.shrink does not provide positive values for this dataset, and it gives error when tails = 'right' print(metric) # get propr object diff --git a/tests/testthat/test-SHARED-updateCutoffs-propr.R b/tests/testthat/test-SHARED-updateCutoffs-propr.R index 00b581b..7e33960 100644 --- a/tests/testthat/test-SHARED-updateCutoffs-propr.R +++ b/tests/testthat/test-SHARED-updateCutoffs-propr.R @@ -180,15 +180,15 @@ test_that("updateCutoffs.propr properly set up cutoffs", { ) expect_equal( updateCutoffs(pr, number_of_cutoffs=10)@fdr$cutoff, - cutoffs_both + cutoffs_right ) expect_equal( - updateCutoffs(pr, custom_cutoffs=cutoffs_both)@fdr, + updateCutoffs(pr, custom_cutoffs=cutoffs_right)@fdr, updateCutoffs(pr, number_of_cutoffs=10)@fdr ) expect_equal( - updateCutoffs(pr, custom_cutoffs=cutoffs_right, tails='right')@fdr, - updateCutoffs(pr, number_of_cutoffs=10, tails='right')@fdr + updateCutoffs(pr, custom_cutoffs=cutoffs_both, tails='both')@fdr, + updateCutoffs(pr, number_of_cutoffs=10, tails='both')@fdr ) }) From 5945efc3237af16383ea158ecd635dd77a3a706e Mon Sep 17 00:00:00 2001 From: suzannejin Date: Thu, 24 Oct 2024 16:09:48 +0200 Subject: [PATCH 4/4] update to 5.1.5 --- NEWS.md | 5 +++++ man/results_to_matrix.Rd | 4 +++- man/updateCutoffs.Rd | 12 ++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index c3b85c3..8931fbb 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# propr 5.1.5 +--------------------- +* Fixed bug in `updateCutoffs` related to the use of `custom_cutoffs` +* Fixed `runNormalization` to properly work when `theta_mod` is used + # propr 5.1.4 --------------------- * Added `results_to_matrix` function diff --git a/man/results_to_matrix.Rd b/man/results_to_matrix.Rd index 65eeb5c..af5637b 100644 --- a/man/results_to_matrix.Rd +++ b/man/results_to_matrix.Rd @@ -4,12 +4,14 @@ \alias{results_to_matrix} \title{Get Matrix from Results} \usage{ -results_to_matrix(results, what = "theta") +results_to_matrix(results, what = "theta", features = NULL) } \arguments{ \item{results}{A \code{data.frame} of results.} \item{what}{A character string. The column name of the results data frame to be converted into a matrix.} + +\item{features}{A vector of features. Default is NULL.} } \value{ A matrix. diff --git a/man/updateCutoffs.Rd b/man/updateCutoffs.Rd index 775d05e..2b512dc 100644 --- a/man/updateCutoffs.Rd +++ b/man/updateCutoffs.Rd @@ -10,7 +10,7 @@ updateCutoffs( object, number_of_cutoffs = 100, custom_cutoffs = NA, - tails = NA, + tails = "right", ncores = 1 ) @@ -18,7 +18,7 @@ updateCutoffs.propr( object, number_of_cutoffs = 100, custom_cutoffs = NA, - tails = NA, + tails = "right", ncores = 1 ) @@ -39,10 +39,10 @@ cutoffs will be evenly spaced across the data.} \item{custom_cutoffs}{A numeric vector. When provided, this vector is used as the set of cutoffs to test, and 'number_of_cutoffs' is ignored.} -\item{tails}{NA or 'right' or 'both'. 'right' is for one-sided on the right. 'both' for -symmetric two-sided test. If NA, use default value according to the property -`has_meaningful_negative_values`. This is only relevant for \code{propr} objects, as -\code{propd} objects are always one-sided and only have positive values.} +\item{tails}{'right' or 'both'. 'right' is for one-sided on the right. 'both' for +symmetric two-sided test. This is only relevant for \code{propr} objects, as +\code{propd} objects are always one-sided and only have positive values. Default +is 'right'.} \item{ncores}{An integer. The number of parallel cores to use.} }