Skip to content

Commit

Permalink
feat(visualizeNetworks): Adjust main target shape to diamond
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywu1999 committed Jan 22, 2025
1 parent ef1dc04 commit 04bcea0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions R/visualizeNetworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#' 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.
#' @param main_targets character vector of main targets to stand-out with a
#' different node shape. Default is an empty vector c(). IDs of main targets
#' should match the column used by the node_label_column parameter.
#' @importFrom RCy3 createNetworkFromDataFrames mapVisualProperty
#' createVisualStyle setVisualStyle layoutNetwork addAnnotationShape
#' addAnnotationText getNodePosition getNetworkCenter
Expand All @@ -35,29 +38,31 @@
visualizeNetworks <- function(nodes, edges,
pvalueCutoff = 0.05,
logfcCutoff = 0.5,
node_label_column = "id") {
node_label_column = "id",
main_targets = c()) {
.validateVisualizeNetworks(nodes, node_label_column)

# Add additional columns for visualization
nodes$logFC_color <- nodes$logFC
nodes$logFC_color[nodes$pvalue > pvalueCutoff |
abs(nodes$logFC) < logfcCutoff] <- 0
nodes$logFC_abs <- abs(nodes$logFC)
nodes$is_main_target <- nodes[,node_label_column] %in% main_targets

# Create network
if (interactive()) {
createNetworkFromDataFrames(nodes, edges)

# Apply visual style
DEFAULT_VISUAL_STYLE <- list(
NODE_SHAPE = "ROUNDRECT",
NODE_LABEL_POSITION = "center",
EDGE_TARGET_ARROW_SHAPE = "Arrow",
EDGE_LABEL_FONT_SIZE = 6
)
VISUAL_STYLE_NAME <- "MSstats-Indra Visual Style"

VISUAL_STYLE_MAPPINGS <- list(
mapVisualProperty('Node Shape', 'is_main_target', 'd', c(TRUE, FALSE), c('DIAMOND', 'ROUNDRECT')),
mapVisualProperty("Node Label", node_label_column, "p"),
mapVisualProperty(
"Node Fill Color", "logFC_color", "c",
Expand Down
7 changes: 6 additions & 1 deletion man/visualizeNetworks.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-visualizeNetworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test_that("visualizeNetworks works correctly", {

expect_silent(visualizeNetworks(input$nodes, input$edges))
expect_called(mock_createNetworkFromDataFrames, 1)
expect_called(mock_mapVisualProperty, 5)
expect_called(mock_mapVisualProperty, 6)
expect_called(mock_createVisualStyle, 1)
expect_called(mock_setVisualStyle, 1)
expect_called(mock_layoutNetwork, 1)
Expand Down

0 comments on commit 04bcea0

Please sign in to comment.