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
28 changes: 12 additions & 16 deletions R/visualizeNetworksWithHTML.R
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ createEdgeElements <- function(edges) {
#' used to render a network visualization. It's decoupled from any specific
#' UI framework.
#'
#' @param node_elements List of node elements created by createNodeElements()
#' @param edge_elements List of edge elements created by createEdgeElements()
#' @param nodes List of nodes from getSubnetworkFromIndra
#' @param edges List of edges from getSubnetworkFromIndra
#' @param display_label_type column of nodes table for displaying node names
#' @param container_id ID of the HTML container element (default: 'network-cy')
#' @param event_handlers Optional list of event handler configurations
#' @param layout_options Optional list of layout configuration options
Expand All @@ -293,11 +294,16 @@ createEdgeElements <- function(edges) {
#' - layout: Layout configuration
#' - container_id: Container element ID
#' - js_code: Complete JavaScript code (for backward compatibility)
generateCytoscapeConfig <- function(node_elements, edge_elements,
generateCytoscapeConfig <- function(nodes, edges,
display_label_type = "id",
container_id = "network-cy",
event_handlers = NULL,
layout_options = NULL) {
Comment on lines +297 to 301
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

API change to accept raw nodes/edges looks good; verify all call sites are updated

Great simplification. Please ensure no callers still pass node_elements/edge_elements.

Run this to find any outdated usages:


🏁 Script executed:

#!/bin/bash
# Find any calls still passing node_elements/edge_elements
rg -nP -C2 --glob '!**/renv/**' "generateCytoscapeConfig\\s*\\(\\s*node_elements\\s*,\\s*edge_elements"

# List all call sites for manual inspection (arity, named args)
rg -nP -C2 --glob '!**/renv/**' "\\bgenerateCytoscapeConfig\\s*\\("

Length of output: 4102


Update documentation examples to use nodes, edges instead of node_elements, edge_elements

The code itself no longer has any live call sites passing the old parameter names, but the examples and manual pages still reference them. Please update the following:

  • In R/visualizeNetworksWithHTML.R (lines ~524–528), update the roxygen “dontrun” example:
    #' \dontrun{
    #' # Assuming you have nodes and edges data

-#' config <- generateCytoscapeConfig(node_elements, edge_elements)
+#' config <- generateCytoscapeConfig(nodes, edges)
#'
#' # Export to HTML
#' }


- In man/generateCytoscapeConfig.Rd (lines 7–9), update the `\usage{}` section:
```diff
\usage{
- generateCytoscapeConfig(
-   node_elements,
-   edge_elements,
+ generateCytoscapeConfig(
+   nodes,
+   edges,
  display_label_type = "id",
  container_id = "network-cy",
  event_handlers = NULL,
  layout_options = NULL
}

Once those are adjusted, all references to the old API will be removed.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
generateCytoscapeConfig <- function(nodes, edges,
display_label_type = "id",
container_id = "network-cy",
event_handlers = NULL,
layout_options = NULL) {
# In R/visualizeNetworksWithHTML.R (around lines 524–528)
#' \dontrun{
#' # Assuming you have nodes and edges data
#' config <- generateCytoscapeConfig(nodes, edges)
#'
#' # Export to HTML
#' }
Suggested change
generateCytoscapeConfig <- function(nodes, edges,
display_label_type = "id",
container_id = "network-cy",
event_handlers = NULL,
layout_options = NULL) {
# In man/generateCytoscapeConfig.Rd (around lines 7–9)
\usage{
generateCytoscapeConfig(
nodes,
edges,
display_label_type = "id",
container_id = "network-cy",
event_handlers = NULL,
layout_options = NULL
}
🤖 Prompt for AI Agents
In R/visualizeNetworksWithHTML.R around lines 524–528 and
man/generateCytoscapeConfig.Rd around lines 7–9, update doc examples/usages that
still reference the old parameter names `node_elements` and `edge_elements` to
use the current API parameter names `nodes` and `edges` instead; specifically
modify the roxygen dontrun example in R/visualizeNetworksWithHTML.R to call
generateCytoscapeConfig(nodes, edges, ...) and edit the \usage{} section in
man/generateCytoscapeConfig.Rd to show generateCytoscapeConfig(nodes, edges,
display_label_type = "id", container_id = "network-cy", event_handlers = NULL,
layout_options = NULL) so the docs match the function signature.


# Create elements
node_elements <- createNodeElements(nodes, display_label_type)
edge_elements <- createEdgeElements(edges)

Comment on lines +303 to +306
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Validate inputs before element creation + fix downstream NA label handling

Two actionable items:

  1. Add explicit input validation for required columns to fail fast with clear messages.
  2. createNodeElements uses apply over a data.frame, coercing NAs to the string "NA" when display_label_type = "hgncName" — labels can incorrectly render as "NA". Implement vectorised construction to preserve real NA semantics.

Minimal validation immediately before element creation:

-    # Create elements
+    # Validate required columns before element creation
+    req_node_cols <- c("id")
+    miss_node <- setdiff(req_node_cols, names(nodes))
+    if (length(miss_node) > 0) {
+        stop("nodes is missing required column(s): ", paste(miss_node, collapse = ", "))
+    }
+    req_edge_cols <- c("source", "target", "interaction")
+    miss_edge <- setdiff(req_edge_cols, names(edges))
+    if (length(miss_edge) > 0) {
+        stop("edges is missing required column(s): ", paste(miss_edge, collapse = ", "))
+    }
+
+    # Create elements
     node_elements <- createNodeElements(nodes, display_label_type)
     edge_elements <- createEdgeElements(edges)

Outside this hunk (in createNodeElements), replace the apply() block with a NA-safe, vectorised version like:

createNodeElements <- function(nodes, displayLabelType = "id") {
  # colors as before ...
  if ("logFC" %in% names(nodes)) node_colors <- mapLogFCToColor(nodes$logFC) else node_colors <- rep("#D3D3D3", nrow(nodes))

  label_column <- if (displayLabelType == "hgncName" && "hgncName" %in% names(nodes)) "hgncName" else "id"

  df <- nodes
  df$color <- node_colors
  labels <- if (label_column == "hgncName") ifelse(!is.na(df$hgncName) & nzchar(df$hgncName), df$hgncName, df$id) else df$id

  # optionally escape single quotes in labels/ids to avoid breaking JS strings
  esc <- function(x) gsub("'", "\\\\'", x, fixed = TRUE)

  mapply(function(id, label, color) {
    paste0("{ data: { id: '", esc(id), "', label: '", esc(label), "', color: '", color, "' } }")
  }, df$id, labels, df$color, USE.NAMES = FALSE)
}
🤖 Prompt for AI Agents
In R/visualizeNetworksWithHTML.R around lines 303 to 306, add explicit input
validation immediately before creating elements to assert required columns exist
(e.g., id, and optionally hgncName/logFC) and fail fast with clear messages;
then update createNodeElements to stop using apply over the data.frame and
instead use vectorised operations that preserve NA semantics: compute node
colors vectorised (use default color if logFC missing), select label_column
based on displayLabelType and availability, build labels with an NA-safe
fallback (if hgncName is NA or empty, use id), escape single quotes in
ids/labels to avoid breaking generated JS, and construct the element strings
with mapply or paste0 over the column vectors.

# Default layout options
default_layout <- list(
name = "dagre",
Expand Down Expand Up @@ -517,8 +523,6 @@ convertLayoutToJS <- function(layout_list) {
#' @examples
#' \dontrun{
#' # Assuming you have nodes and edges data
#' node_elements <- createNodeElements(nodes)
#' edge_elements <- createEdgeElements(edges)
#' config <- generateCytoscapeConfig(node_elements, edge_elements)
#'
#' # Export to HTML
Expand Down Expand Up @@ -894,12 +898,8 @@ exportNetworkToHTML <- function(nodes, edges,
displayLabelType = "id",
...) {

# Create elements
node_elements <- createNodeElements(nodes, displayLabelType)
edge_elements <- createEdgeElements(edges)

# Generate configuration
config <- generateCytoscapeConfig(node_elements, edge_elements)
config <- generateCytoscapeConfig(nodes, edges, display_label_type = displayLabelType)

# Export to HTML
exportCytoscapeToHTML(config, filename, ...)
Expand All @@ -917,13 +917,9 @@ exportNetworkToHTML <- function(nodes, edges,
previewNetworkInBrowser <- function(nodes, edges,
displayLabelType = "id",
...) {

# Create elements
node_elements <- createNodeElements(nodes, displayLabelType)
edge_elements <- createEdgeElements(edges)


# Generate configuration
config <- generateCytoscapeConfig(node_elements, edge_elements)
config <- generateCytoscapeConfig(nodes, edges, display_label_type = displayLabelType)

# Create temporary filename
temp_file <- tempfile(fileext = ".html")
Expand Down
11 changes: 7 additions & 4 deletions man/generateCytoscapeConfig.Rd

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

Loading