Skip to content

Commit

Permalink
test(visualizeSubnetwork): Add unit tests for visualizeSubnetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywu1999 committed Jul 25, 2024
1 parent 4f4a970 commit 7c5b829
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Suggests:
BiocStyle,
knitr,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
mockery
VignetteBuilder: knitr
biocViews: ImmunoOncology, MassSpectrometry, Proteomics, Software,
QualityControl
Expand Down
6 changes: 3 additions & 3 deletions inst/processed_data/groupComparisonModel.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
,Protein,Label,log2FC,SE,Tvalue,DF,pvalue,adj.pvalue,issue,MissingPercentage,ImputationPercentage,HgncId
1,BRD2_HUMAN,DMSO-DbET6,2.046185244,0.114338622,17.89583616,260,0,0,NA,0.310067114,0,1103
2,BRD3_HUMAN,DMSO-DbET6,3.333427936,0.126570545,26.33652185,257,0,0,NA,0.252348993,0,1104
3,BRD4_HUMAN,DMSO-DbET6,2.668934662,0.101282782,26.35131665,257,0,0,NA,0.118120805,0,13575
1,BRD2_HUMAN,DMSO-DbET6,2.046185244,0.114338622,17.89583616,260,0,0.001,NA,0.310067114,0,1103
2,BRD3_HUMAN,DMSO-DbET6,3.333427936,0.126570545,26.33652185,257,0,0.001,NA,0.252348993,0,1104
3,BRD4_HUMAN,DMSO-DbET6,2.668934662,0.101282782,26.35131665,257,0,0.04,NA,0.118120805,0,13575
4,CLH1_HUMAN,DMSO-DbET7,0.668934662,0.101282782,2.35131665,257,0.99,0.99,NA,0.118120805,0,2092
Binary file added inst/processed_data/subnetwork.rds
Binary file not shown.
1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(mockery)
library(MSstatsBioNet)

test_check("MSstatsBioNet")
74 changes: 74 additions & 0 deletions tests/testthat/test-visualizeSubnetwork.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
test_that("visualizeSubnetwork works correctly", {
input <- readRDS(system.file("processed_data/subnetwork.rds",
package = "MSstatsBioNet"
))

mock_createNetworkFromDataFrames <- mock()
stub(
visualizeSubnetwork, "createNetworkFromDataFrames",
mock_createNetworkFromDataFrames
)
mock_mapVisualProperty <- mock()
stub(
visualizeSubnetwork, "mapVisualProperty",
mock_mapVisualProperty
)
mock_createVisualStyle <- mock()
stub(
visualizeSubnetwork, "createVisualStyle",
mock_createVisualStyle
)
mock_setVisualStyle <- mock()
stub(
visualizeSubnetwork, "setVisualStyle",
mock_setVisualStyle
)

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


test_that("visualizeSubnetwork with p-value and logFC constraints works", {
input <- readRDS(system.file("processed_data/subnetwork.rds",
package = "MSstatsBioNet"
))

mock_createNetworkFromDataFrames <- mock()
stub(
visualizeSubnetwork, "createNetworkFromDataFrames",
mock_createNetworkFromDataFrames
)
mock_mapVisualProperty <- mock()
stub(
visualizeSubnetwork, "mapVisualProperty",
mock_mapVisualProperty
)
mock_createVisualStyle <- mock()
stub(
visualizeSubnetwork, "createVisualStyle",
mock_createVisualStyle
)
mock_setVisualStyle <- mock()
stub(
visualizeSubnetwork, "setVisualStyle",
mock_setVisualStyle
)

expect_silent(visualizeSubnetwork(input$nodes, input$edges,
pvalue_cutoff = 0.01, logfc_cutoff = 2.5
))
expect_called(mock_createNetworkFromDataFrames, 1)
calls <- mock_args(mock_createNetworkFromDataFrames)
nodes <- calls[[1]][[1]]
edges <- calls[[1]][[2]]
expect_equal(edges, input$edges)
expect_equal(nodes[input$nodes$id == "BRD2_HUMAN", ]$logFC_color, 0)
expect_equal(
nodes[input$nodes$id == "BRD3_HUMAN", ]$logFC_color, 3.33342794
)
expect_equal(nodes[input$nodes$id == "BRD4_HUMAN", ]$logFC_color, 0)
})

0 comments on commit 7c5b829

Please sign in to comment.