Skip to content

Commit

Permalink
refactor: Make changes from feedback from HUPO (#26)
Browse files Browse the repository at this point in the history
* layout(visualizeNetworks): Set up cose layout for network viz

* refactor(getSubnetworkFromIndra): Add input validation

* fix visualizeNetwork tests

* Add validation tests for hgncID column being missing
  • Loading branch information
tonywu1999 authored Jan 9, 2025
1 parent 90fc510 commit fa70cfe
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(getSubnetworkFromIndra)
export(visualizeNetworks)
importFrom(RCy3,createNetworkFromDataFrames)
importFrom(RCy3,createVisualStyle)
importFrom(RCy3,layoutNetwork)
importFrom(RCy3,mapVisualProperty)
importFrom(RCy3,setVisualStyle)
importFrom(httr,POST)
Expand Down
2 changes: 1 addition & 1 deletion R/annotateProteinInfoFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This function annotates a data frame with protein information from Indra.
#'
#' @param input output of \code{\link[MSstats]{groupComparison}} function's
#' @param df output of \code{\link[MSstats]{groupComparison}} function's
#' comparisonResult table, which contains a list of proteins and their
#' corresponding p-values, logFCs, along with additional HGNC ID and HGNC
#' name columns
Expand Down
1 change: 1 addition & 0 deletions R/getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#'
getSubnetworkFromIndra <- function(input, pvalueCutoff = NULL) {
input <- .filterGetSubnetworkFromIndraInput(input, pvalueCutoff)
.validateGetSubnetworkFromIndraInput(input)
res <- .callIndraCogexApi(input$HgncId)
nodes <- .constructNodesDataFrame(input)
edges <- .constructEdgesDataFrame(res, input)
Expand Down
13 changes: 13 additions & 0 deletions R/utils_getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#' Validate input for MSstatsBioNet getSubnetworkFromIndra
#' @param input dataframe from MSstats groupComparison output
#' @keywords internal
#' @noRd
.validateGetSubnetworkFromIndraInput <- function(input) {
if (!"HgncId" %in% colnames(input)) {
stop("Invalid Input Error: Input must contain a column named 'HgncId'.")
}
if (nrow(input) >= 400) {
stop("Invalid Input Error: INDRA query must contain less than 400 proteins. Consider adding a p-value cutoff")
}
}

#' Call INDRA Cogex API and return response
#' @param hgncIds list of hgnc ids
#' @return list of INDRA statements
Expand Down
8 changes: 5 additions & 3 deletions R/visualizeNetworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param logfcCutoff log fold change cutoff for coloring significant
#' proteins. Default is 0.5
#' @importFrom RCy3 createNetworkFromDataFrames mapVisualProperty
#' createVisualStyle setVisualStyle
#' createVisualStyle setVisualStyle layoutNetwork
#'
#' @export
#'
Expand All @@ -30,7 +30,8 @@
#'
#'
visualizeNetworks <- function(nodes, edges,
pvalueCutoff = 0.05, logfcCutoff = 0.5) {
pvalueCutoff = 0.05,
logfcCutoff = 0.5) {
# Add additional columns for visualization
nodes$logFC_color <- nodes$logFC
nodes$logFC_color[nodes$pvalue > pvalueCutoff |
Expand All @@ -55,7 +56,7 @@ visualizeNetworks <- function(nodes, edges,
mapVisualProperty(
"Node Fill Color", "logFC_color", "c",
c(-logfcCutoff, 0.0, logfcCutoff),
c("#5588DD", "#5588DD", "#D3D3D3", "#DD8855", "#DD8855")
c("#ADD8E6", "#ADD8E6", "#D3D3D3", "#FFA590", "#FFA590")
)
)
createVisualStyle(
Expand All @@ -64,6 +65,7 @@ visualizeNetworks <- function(nodes, edges,
VISUAL_STYLE_MAPPINGS
)
setVisualStyle(VISUAL_STYLE_NAME)
layoutNetwork("cose")
} else {
warning("Visualization is not available in non-interactive mode.")
}
Expand Down
5 changes: 4 additions & 1 deletion man/annotateProteinInfoFromIndra.Rd

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

17 changes: 17 additions & 0 deletions man/dot-populateHgncIdsInDataFrame.Rd

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

17 changes: 17 additions & 0 deletions man/dot-populateHgncNamesInDataFrame.Rd

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

17 changes: 17 additions & 0 deletions man/dot-populateKinaseInfoInDataFrame.Rd

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

17 changes: 17 additions & 0 deletions man/dot-populatePhophataseInfoInDataFrame.Rd

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

17 changes: 17 additions & 0 deletions man/dot-populateTranscriptionFactorInfoInDataFrame.Rd

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

20 changes: 20 additions & 0 deletions man/dot-populateUniprotIdsInDataFrame.Rd

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

17 changes: 17 additions & 0 deletions man/dot-validateAnnotateProteinInfoFromIndraInput.Rd

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

7 changes: 4 additions & 3 deletions man/getSubnetworkFromIndra.Rd

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

25 changes: 25 additions & 0 deletions tests/testthat/test-getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@ test_that("getSubnetworkFromIndra with pvalue filter works correctly", {
expect_equal(nrow(subnetwork$nodes), 6)
expect_equal(nrow(subnetwork$edges), 1)
})

test_that("Exception is thrown for 400+ proteins in dataframe", {
input_400 <- data.frame(
Protein = paste0("Protein", 1:400),
HgncId = paste0("HGNCID", 1:400),
issue = NA,
adj.pvalue = 0.05
)
expect_error(
getSubnetworkFromIndra(input_400),
"Invalid Input Error: INDRA query must contain less than 400 proteins. Consider adding a p-value cutoff"
)
})

test_that("Exception is thrown for missing columns in input", {
input_missing_hgnc_id <- data.frame(
Protein = paste0("Protein", 1:10),
issue = NA,
adj.pvalue = 0.05
)
expect_error(
getSubnetworkFromIndra(input_missing_hgnc_id),
"Invalid Input Error: Input must contain a column named 'HgncId'."
)
})
11 changes: 11 additions & 0 deletions tests/testthat/test-visualizeNetworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ test_that("visualizeNetworks works correctly", {
visualizeNetworks, "setVisualStyle",
mock_setVisualStyle
)
mock_layoutNetwork <- mock()
stub(
visualizeNetworks, "layoutNetwork",
mock_layoutNetwork
)

expect_silent(visualizeNetworks(input$nodes, input$edges))
expect_called(mock_createNetworkFromDataFrames, 1)
expect_called(mock_mapVisualProperty, 2)
expect_called(mock_createVisualStyle, 1)
expect_called(mock_setVisualStyle, 1)
expect_called(mock_layoutNetwork, 1)
})


Expand Down Expand Up @@ -67,6 +73,11 @@ test_that("visualizeNetworks with p-value and logFC constraints works", {
visualizeNetworks, "setVisualStyle",
mock_setVisualStyle
)
mock_layoutNetwork <- mock()
stub(
visualizeNetworks, "layoutNetwork",
mock_layoutNetwork
)

expect_silent(visualizeNetworks(input$nodes, input$edges,
pvalueCutoff = 0.01, logfcCutoff = 2.5
Expand Down

0 comments on commit fa70cfe

Please sign in to comment.