From c94f3d2a28bc6408edc56acb8502386089ffd451 Mon Sep 17 00:00:00 2001 From: Danielle Callan Date: Thu, 25 Apr 2024 23:24:40 -0400 Subject: [PATCH] clean up correlation coef and pvalue filtering helpers --- R/methods-CorrelationNetwork.R | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/R/methods-CorrelationNetwork.R b/R/methods-CorrelationNetwork.R index 730ff9a..ce8dd9a 100644 --- a/R/methods-CorrelationNetwork.R +++ b/R/methods-CorrelationNetwork.R @@ -5,49 +5,43 @@ setMethod("getCorrelationCoefThreshold", "CorrelationNetwork", function(object) setGeneric("getPValueThreshold", function(object) standardGeneric("getPValueThreshold")) setMethod("getPValueThreshold", "CorrelationNetwork", function(object) object@pValueThreshold) - -#' @include methods-CorrelationLinks.R -linkAboveCorrelationCoefThreshold <- function(link, threshold) { - return(abs(correlationCoef(link)) >= threshold) -} - #' Prune Links by Correlation Coefficient #' #' Removes links that have an absolute correlation coefficient below a -#' threshold. This is a convenience function that calls pruneLinksByPredicate. +#' threshold. This is a convenience function that calls pruneCorrelationLinks. #' @param net A CorrelationNetwork object #' @param correlationCoefThreshold The threshold #' @param verbose If TRUE, will print messages #' @export -pruneLinksByCorrelationCoef <- function(net, correlationCoefThreshold, verbose = c(TRUE, FALSE)) { +pruneLinksByCorrelationCoef <- function(net, correlationCoefThreshold = NULL, verbose = c(TRUE, FALSE)) { verbose <- veupathUtils::matchArg(verbose) - return(pruneLinksByPredicate(net = net, predicate = linkAboveCorrelationCoefThreshold, threshold = correlationCoefThreshold, verbose = verbose)) -} - - -linkBelowPValueThreshold <- function(link, threshold) { - return(pValue(link) <= threshold) + return(pruneCorrelationLinks(net = net, correlationCoefThreshold = correlationCoefThreshold, verbose = verbose)) } #' Prune Links by P-Value #' #' Removes links that have a p-value above a threshold. This is a convenience -#' function that calls pruneLinksByPredicate. +#' function that calls pruneCorrelationLinks. #' @param net A Network object #' @param pValueThreshold The threshold #' @param verbose If TRUE, will print messages #' @export -pruneLinksBelowWeight <- function(net, threshold, verbose = c(TRUE, FALSE)) { +pruneLinksByPValue <- function(net, pValueThreshold = NULL, verbose = c(TRUE, FALSE)) { verbose <- veupathUtils::matchArg(verbose) - return(pruneLinksByPredicate(net = net, predicate = linkBelowPValueThreshold, threshold = pValueThreshold, verbose = verbose)) + return(pruneCorrelationLinks(net = net, pValueThreshold = pValueThreshold, verbose = verbose)) } #' @rdname pruneCorrelationLinks #' @aliases pruneCorrelationLinks,CorrelationNetwork-method -setMethod("pruneCorrelationLinks", "CorrelationNetwork", function(object, correlationCoefThreshold, pValueThreshold, verbose = c(TRUE, FALSE)) { - +setMethod("pruneCorrelationLinks", "CorrelationNetwork", +function( + object, + correlationCoefThreshold = NULL, + pValueThreshold = NULL, + verbose = c(TRUE, FALSE) +) { verbose <- veupathUtils::matchArg(verbose) object@links <- pruneCorrelationLinks(