Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(annotateProteinInfoFromIndra)
export(cytoscapeNetwork)
export(cytoscapeNetworkOutput)
export(deleteEdgeFromNetwork)
export(exportNetworkToHTML)
export(filterSubnetworkByContext)
export(getSubnetworkFromIndra)
Expand Down
54 changes: 54 additions & 0 deletions R/deleteEdgeFromNetwork.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#' Delete an edge from a network edges data frame
#'
#' Removes the row(s) from an edges data frame that match the given
#' \code{source}, \code{target}, and \code{interaction} values. This is
#' the programmatic counterpart of the interactive Ctrl+click / right-click
#' edge deletion available in \code{\link{cytoscapeNetwork}}.
#'
#' @param edges Data frame with at minimum columns \code{source},
#' \code{target}, and \code{interaction}.
#' @param source Character. The source node identifier of the edge to
#' remove.
#' @param target Character. The target node identifier of the edge to
#' remove.
#' @param interaction Character. The interaction type of the edge to remove.
#'
#' @return The \code{edges} data frame with the matching row(s) removed.
#'
#' @examples
#' edges <- data.frame(
#' source = c("TP53", "MDM2", "CDKN1A"),
#' target = c("MDM2", "TP53", "TP53"),
#' interaction = c("Activation", "Inhibition", "Activation"),
#' stringsAsFactors = FALSE
#' )
#' deleteEdgeFromNetwork(edges, "MDM2", "TP53", "Inhibition")
#'
#' @export
deleteEdgeFromNetwork <- function(edges, source, target, interaction) {
if (!is.data.frame(edges)) {
stop("`edges` must be a data frame.")
}
if (!is.character(source) || length(source) != 1L || is.na(source)) {
stop("`source` must be a single, non-NA character value.")
}
if (!is.character(target) || length(target) != 1L || is.na(target)) {
stop("`target` must be a single, non-NA character value.")
}
if (!is.character(interaction) || length(interaction) != 1L || is.na(interaction)) {
stop("`interaction` must be a single, non-NA character value.")
}
required_cols <- c("source", "target", "interaction")
if (!all(required_cols %in% names(edges))) {
stop("`edges` must contain columns: source, target, interaction.")
}
match_row <- !is.na(edges$source) &
!is.na(edges$target) &
!is.na(edges$interaction) &
edges$source == source &
edges$target == target &
edges$interaction == interaction
keep <- !match_row
edges[keep, , drop = FALSE]
Comment thread
tonywu1999 marked this conversation as resolved.
}

39 changes: 39 additions & 0 deletions man/deleteEdgeFromNetwork.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading