context("test: ms1_plots")
test_that("Testing ms1 plot plotting function", {
# Download required test files------------------------------------------------
source(system.file("tests/testthat/file_check.R", package = "pspecterlib"))
downfolder <- file_check("downfolder")
BU_ScanMetadata <- file_check("BU")
# Test ms1 plot input checks--------------------------------------------------
# ScanMetadata must be of the correct class
expect_error(
ms1_plots(data.frame(test = 1)),
"ScanMetadata must be a scan_metadata object generated by get_scan_metadata."
)
# Scan number should be an integer
expect_error(
ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = "5"
),
"ScanNumber must be an integer."
)
# Scan number must be for a scan with an MS Level of 2
expect_error(
ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 5
),
"ScanNumber must be for a scan with an MS Level of 2."
)
# Window should be a single integer
expect_error(
ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728,
Window = c(2,3)
),
"Window must be a single integer."
)
# Sequence should be a real sequence
expect_error(
ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728,
Sequence = "NOTREALSEQUENCE"
),
"Sequence is not an acceptable input. See is_sequence."
)
# IsotopicPercentageFilter should be between 0 and 100
expect_error(
ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728,
IsotopicPercentageFilter = 150
),
"The IsotopicPercentageFilter must be a number between 0-100."
)
# Interactive should be true or false
expect_error(
ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728,
Interactive = "TRUE"
),
"Interactive parameter must be either TRUE or FALSE."
)
# Create a ms1 bar plot-------------------------------------------------------
# Make it static with negative isotopes and at the end of scan numbers
suppressWarnings(thePlots1 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 34291,
Interactive = NA
))
expect_null(thePlots1[[2]])
# Make it static without negative isotopes at the end of scan numbers with an
# alternative sequence
suppressWarnings(thePlots2 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 34291,
Sequence = "TESTTESTTESTTESTTESTTESTTEST",
Interactive = TRUE
))
expect_null(thePlots2[[2]])
# Make an example with a previous and next ms1 static
suppressWarnings(thePlots3 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728,
Interactive = FALSE
))
expect_true(inherits(thePlots3[[1]], "ggplot"))
# Make an example with a previous and next ms1 interactive
suppressWarnings(thePlots4 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728
))
expect_true(inherits(thePlots4[[1]], "plotly"))
# Trigger a narrow window size
suppressWarnings(suppressMessages(
thePlots5 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 31728,
Window = 1,
Interactive = FALSE
)
))
expect_true(inherits(thePlots5[[1]], "ggplot"))
# Trigger a multiple sequence message
suppressWarnings(suppressMessages(
thePlots6 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 29135,
Interactive = FALSE
)
))
expect_true(inherits(thePlots6[[1]], "ggplot"))
# Trigger a no sequence assigned example
suppressWarnings(suppressMessages(
thePlots7 <- ms1_plots(
ScanMetadata = BU_ScanMetadata,
ScanNumber = 29128,
Interactive = FALSE
)
))
expect_true(inherits(thePlots7[[1]], "ggplot"))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.