Skip to content

Commit

Permalink
clean up correlation coef and pvalue filtering helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
d-callan committed Apr 26, 2024
1 parent 1952847 commit c94f3d2
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions R/methods-CorrelationNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c94f3d2

Please sign in to comment.