Skip to content

Commit

Permalink
optionally prune isolated nodes when filtering correlation networks b…
Browse files Browse the repository at this point in the history
…y various thresholds
  • Loading branch information
d-callan committed Apr 26, 2024
1 parent 5e518c7 commit 542411e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions R/class-CorrelationNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ setClass("CorrelationNetwork",
#' @param layout string defining the layout of the network. Options are 'force', 'circle',
#' and 'nicely' which are implemented in igraph. Default is 'nicely'.
#' @param variables VariableMetadataList
#' @param ... additional arguments for different flavors of the CorrelationNetwork constructor
#' @return CorrelationNetwork
#' @export
#' @examples
Expand Down Expand Up @@ -110,19 +111,25 @@ setMethod("CorrelationNetwork", signature("missing", "CorrelationLinkList", "Nod
pValueThreshold = 0.05,
linkColorScheme = 'posneg',
variables = VariableMetadataList(),
...
pruneIsolatedNodes = c(TRUE, FALSE)
) {
pruneIsolatedNodes <- veupathUtils::matchArg(pruneIsolatedNodes)

links <- pruneCorrelationLinks(links, correlationCoefThreshold, pValueThreshold)
# TODO filter nodes based on those remaining in links?

new("CorrelationNetwork",
net <- new("CorrelationNetwork",
links=links,
nodes=nodes,
linkColorScheme=linkColorScheme,
variableMapping=variables,
correlationCoefThreshold=ifelse(is.null(correlationCoefThreshold), NA_real_, correlationCoefThreshold),
pValueThreshold=ifelse(is.null(pValueThreshold), NA_real_, pValueThreshold)
)

if (pruneIsolatedNodes) {
net <- pruneIsolatedNodes(net)
}

return(net)
})

#' @rdname CorrelationNetwork
Expand All @@ -136,24 +143,31 @@ setMethod("CorrelationNetwork", signature("data.frame", "missing", "missing"), f
linkColorScheme = 'posneg',
layout = c("nicely", "force", "circle"),
variables = VariableMetadataList(),
...
pruneIsolatedNodes = c(TRUE, FALSE)
) {
layout <- veupathUtils::matchArg(layout)
pruneIsolatedNodes <- veupathUtils::matchArg(pruneIsolatedNodes)

# any additional validation and filtering are handled by the CorrelationLinkList constructor
new("CorrelationNetwork",
net <- new("CorrelationNetwork",
links=CorrelationLinkList(object, linkColorScheme, correlationCoefThreshold, pValueThreshold),
nodes=NodeList(object, layout),
linkColorScheme=linkColorScheme,
variableMapping=variables,
correlationCoefThreshold=ifelse(is.null(correlationCoefThreshold), NA_real_, correlationCoefThreshold),
pValueThreshold=ifelse(is.null(pValueThreshold), NA_real_, pValueThreshold)
)

if (pruneIsolatedNodes) {
net <- pruneIsolatedNodes(net)
}

return(net)
})

#' @rdname CorrelationNetwork
#' @aliases CorrelationNetwork,missing,missing,missing
setMethod("Network", signature("missing", "missing", "missing"), function(
setMethod("CorrelationNetwork", signature("missing", "missing", "missing"), function(
object,
links,
nodes,
Expand Down

0 comments on commit 542411e

Please sign in to comment.