Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(visualizeNetworks): Enable use of other columns for node labels #31

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

tonywu1999
Copy link
Contributor

@tonywu1999 tonywu1999 commented Jan 22, 2025

PR Type

Enhancement, Documentation


Description

  • Added support for custom node label columns in network visualization.

  • Updated .constructNodesDataFrame to include hgncName column if available.

  • Modified visualizeNetworks function to accept node_label_column parameter.

  • Enhanced documentation to reflect new parameter and functionality.


Changes walkthrough 📝

Relevant files
Enhancement
utils_getSubnetworkFromIndra.R
Include `hgncName` column in nodes dataframe                         

R/utils_getSubnetworkFromIndra.R

  • Added hgncName column to nodes dataframe if available.
  • Ensured compatibility with existing edge filtering logic.
  • +1/-0     
    visualizeNetworks.R
    Add `node_label_column` parameter to `visualizeNetworks` 

    R/visualizeNetworks.R

  • Introduced node_label_column parameter for custom node labels.
  • Updated visual style mapping to use the specified column.
  • Adjusted function signature and internal logic accordingly.
  • +5/-2     
    Documentation
    visualizeNetworks.Rd
    Update documentation for `visualizeNetworks` function       

    man/visualizeNetworks.Rd

  • Documented node_label_column parameter in function usage.
  • Updated examples and descriptions to reflect new functionality.
  • +10/-1   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Possible Issue

    The addition of the hgncName column in .constructNodesDataFrame assumes that the column HgncName exists in the input dataframe. If it does not, it defaults to NA. This behavior should be validated to ensure it does not cause unintended issues downstream.

    hgncName = if ("HgncName" %in% colnames(input)) input$HgncName else NA,
    stringsAsFactors = FALSE
    Parameter Validation

    The new node_label_column parameter in visualizeNetworks is not validated to ensure it corresponds to an existing column in the nodes dataframe. This could lead to runtime errors if an invalid column name is provided.

    logfcCutoff = 0.5,
    node_label_column = "id") {

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Validate existence of user-specified column

    Add validation to ensure that the node_label_column parameter corresponds to a valid
    column in the nodes dataframe to prevent runtime errors.

    R/visualizeNetworks.R [35-38]

     visualizeNetworks <- function(nodes, edges,
                                   pvalueCutoff = 0.05, 
                                   logfcCutoff = 0.5,
                                   node_label_column = "id") {
    +    if (!node_label_column %in% colnames(nodes)) {
    +        stop("The specified node_label_column does not exist in the nodes dataframe.")
    +    }
    Suggestion importance[1-10]: 9

    Why: Adding validation to ensure the node_label_column exists in the nodes dataframe is crucial for preventing runtime errors. This suggestion directly addresses a potential issue introduced by the new parameter and improves the robustness of the function.

    9
    Validate column data type before usage

    Ensure that the HgncName column is properly validated before accessing it to avoid
    potential runtime errors if the column exists but contains unexpected or malformed
    data.

    R/utils_getSubnetworkFromIndra.R [192]

    -hgncName = if ("HgncName" %in% colnames(input)) input$HgncName else NA,
    +hgncName = if ("HgncName" %in% colnames(input) && is.character(input$HgncName)) input$HgncName else NA,
    Suggestion importance[1-10]: 8

    Why: This suggestion adds a validation step to ensure that the HgncName column is of the expected data type before accessing it. This is a significant improvement as it prevents potential runtime errors caused by unexpected or malformed data in the column.

    8
    General
    Handle missing values in label column

    Provide a fallback mechanism or warning if the node_label_column contains missing or
    NA values to ensure robust visualization.

    R/visualizeNetworks.R [61]

    -mapVisualProperty("Node Label", node_label_column, "p"),
    +mapVisualProperty("Node Label", ifelse(is.na(nodes[[node_label_column]]), "id", node_label_column), "p"),
    Suggestion importance[1-10]: 7

    Why: This suggestion introduces a fallback mechanism for missing or NA values in the node_label_column, which enhances the robustness of the visualization process. While not critical, it is a valuable improvement for handling edge cases.

    7

    @codecov-commenter
    Copy link

    codecov-commenter commented Jan 22, 2025

    Codecov Report

    Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

    Project coverage is 87.09%. Comparing base (c33b317) to head (8fead2f).

    Files with missing lines Patch % Lines
    R/utils_getSubnetworkFromIndra.R 66.66% 1 Missing ⚠️
    R/utils_visualizeNetworks.R 50.00% 1 Missing ⚠️
    Additional details and impacted files
    @@            Coverage Diff             @@
    ##            devel      #31      +/-   ##
    ==========================================
    - Coverage   87.41%   87.09%   -0.32%     
    ==========================================
      Files           7        7              
      Lines         429      434       +5     
    ==========================================
    + Hits          375      378       +3     
    - Misses         54       56       +2     

    ☔ View full report in Codecov by Sentry.
    📢 Have feedback on the report? Share it here.

    @tonywu1999 tonywu1999 merged commit fbac585 into devel Jan 22, 2025
    3 checks passed
    @tonywu1999 tonywu1999 deleted the gene-name branch January 22, 2025 18:01
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants