Skip to content

Commit

Permalink
feat(visualizeNetworks): Enable use of other columns for node labels (#…
Browse files Browse the repository at this point in the history
…31)

* feat(visualizeNetworks): Enable use of other columns for node labels
  • Loading branch information
tonywu1999 authored Jan 22, 2025
1 parent c33b317 commit fbac585
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' "extdata/groupComparisonModel.csv",
#' package = "MSstatsBioNet"
#' ))
#' subnetwork <- getSubnetworkFromIndra(input, pvalueCutoff = 0.05)
#' subnetwork <- getSubnetworkFromIndra(input)
#' head(subnetwork$nodes)
#' head(subnetwork$edges)
#'
Expand Down
4 changes: 4 additions & 0 deletions R/utils_getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
if (nrow(input) >= 400) {
stop("Invalid Input Error: INDRA query must contain less than 400 proteins. Consider lowering your p-value cutoff")
}
if (nrow(input) == 0) {
stop("Invalid Input Error: Input must contain at least one protein after filtering.")
}
}

#' Call INDRA Cogex API and return response
Expand Down Expand Up @@ -189,6 +192,7 @@
id = input$Protein,
logFC = input$log2FC,
pvalue = input$adj.pvalue,
hgncName = if ("HgncName" %in% colnames(input) && is.character(input$HgncName)) input$HgncName else NA,
stringsAsFactors = FALSE
)
nodes <- nodes[which(nodes$id %in% edges$source | nodes$id %in% edges$target),]
Expand Down
6 changes: 5 additions & 1 deletion R/utils_visualizeNetworks.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#' Validate input for MSstatsBioNet visualizeNetworks
#' @param nodes dataframe of nodes
#' @param node_label_column column of nodes dataframe for node labeling
#' @keywords internal
#' @noRd
.validateVisualizeNetworks <- function(nodes) {
.validateVisualizeNetworks <- function(nodes, node_label_column) {
if (!node_label_column %in% colnames(nodes)) {
stop("The specified node_label_column does not exist in the nodes dataframe.")
}
if (!"logFC" %in% colnames(nodes)) {
stop("The 'logFC' column is missing from the nodes dataframe.")
}
Expand Down
9 changes: 6 additions & 3 deletions R/visualizeNetworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' Default is 0.05
#' @param logfcCutoff log fold change cutoff for coloring significant
#' proteins. Default is 0.5
#' @param node_label_column The column of the nodes dataframe to use as the
#' node label. Default is "id". "hgncName" can be used for gene name.
#' @importFrom RCy3 createNetworkFromDataFrames mapVisualProperty
#' createVisualStyle setVisualStyle layoutNetwork addAnnotationShape
#' addAnnotationText getNodePosition getNetworkCenter
Expand All @@ -32,8 +34,9 @@
#'
visualizeNetworks <- function(nodes, edges,
pvalueCutoff = 0.05,
logfcCutoff = 0.5) {
.validateVisualizeNetworks(nodes)
logfcCutoff = 0.5,
node_label_column = "id") {
.validateVisualizeNetworks(nodes, node_label_column)

# Add additional columns for visualization
nodes$logFC_color <- nodes$logFC
Expand All @@ -55,7 +58,7 @@ visualizeNetworks <- function(nodes, edges,
VISUAL_STYLE_NAME <- "MSstats-Indra Visual Style"

VISUAL_STYLE_MAPPINGS <- list(
mapVisualProperty("Node Label", "id", "p"),
mapVisualProperty("Node Label", node_label_column, "p"),
mapVisualProperty(
"Node Fill Color", "logFC_color", "c",
c(-logfcCutoff, 0.0, logfcCutoff),
Expand Down
2 changes: 1 addition & 1 deletion man/getSubnetworkFromIndra.Rd

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

11 changes: 10 additions & 1 deletion man/visualizeNetworks.Rd

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

0 comments on commit fbac585

Please sign in to comment.