Skip to content

Commit

Permalink
- more tests for normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-enzlein committed Sep 5, 2024
1 parent 0eeafd7 commit 9084ea4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion R/normalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ normalize <- function(spec, peaks, normMeth, normMz, normTol) {
u_fil <- unique(nm[included_specIdx])
if(length(u_nm) != length(u_fil)) {
# stop if a single condition got filtered completely

label_removed <- u_nm[which(!(u_nm %in% u_fil))]

stop("Could not find ", normMz, " in all spectra with label ",
Expand Down
39 changes: 39 additions & 0 deletions tests/testthat/test-normalize.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# helper
spectraListConstructor <- function(n = 3, metaData = list(test = "test")) {
l <- lapply(1:n,
function(x)
{MALDIquant::createMassSpectrum(mass = 1:10,
intensity = abs(rnorm(10, 0, 1)),
metaData = metaData)
})
return(l)
}

peakListConstructor <- function(n = 3, metaData = list(test = "test")) {
l <- lapply(1:n,
function(x)
{MALDIquant::createMassPeaks(mass = 1:10,
intensity = abs(rnorm(10, 0, 1)),
snr = 1:10,
metaData = metaData)
})
return(l)
}

test_that("normalize stops like intended", {
data("Blank2022peaks")
data("Blank2022spec")
Expand All @@ -21,6 +43,23 @@ test_that("normalize stops like intended", {
normalize(spec = Blank2022spec, peaks = Blank2022peaks, normMeth = "mz", normMz = 0, normTol = 0.1)
)
)

# normMz absent in a specific concentration
spec <- spectraListConstructor()
peaks <- peakListConstructor()

names(spec) <-1:3
names(peaks) <- 1:3

MALDIquant::mass(spec[[2]])[10] <- 11
MALDIquant::mass(peaks[[2]])[10] <- 11

expect_error(
suppressWarnings(
normalize(spec = spec, peaks = peaks, normMeth = "mz", normMz = 10, normTol = 0.1)
)
)

})

test_that("normalize works", {
Expand Down

0 comments on commit 9084ea4

Please sign in to comment.