Skip to content

Commit

Permalink
tests: complete unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Jan 24, 2025
1 parent 1edc2e4 commit f0be11e
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 158 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ importMethodsFrom(ProtGenerics,peaksVariables)
importMethodsFrom(ProtGenerics,precScanNum)
importMethodsFrom(ProtGenerics,setBackend)
importMethodsFrom(ProtGenerics,smoothed)
importMethodsFrom(ProtGenerics,spectraData)
importMethodsFrom(ProtGenerics,spectraNames)
importMethodsFrom(ProtGenerics,spectraVariables)
importMethodsFrom(ProtGenerics,tic)
importMethodsFrom(ProtGenerics,uniqueMsLevels)
importMethodsFrom(Spectra,backendBpparam)
importMethodsFrom(Spectra,reset)
importMethodsFrom(Spectra,show)
importMethodsFrom(Spectra,spectraData)
importMethodsFrom(Spectra,spectraVariables)
importMethodsFrom(Spectra,supportsSetBackend)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*fastmatch* package and avoiding to re-order the results if not needed.
- Performance improvement for *blob* and *blob2* storage modes
by using `xda = FALSE` in `serialize()`.
- Complete unit test coverage.

## Changes in 1.7.2

Expand Down
91 changes: 38 additions & 53 deletions R/MsBackendSql-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ MsBackendSql <- function() {
tbls <- dbListTables(.dbcon(x))
tbl <- grep("msms_spectrum_peak", tbls, value = TRUE)
if (tbl == "msms_spectrum_peak_blob2") {
res <- peaksData(x[1L])
if (length(x))
res <- peaksData(x[1L])[[1L]]
else res <- matrix(
NA_real_, ncol = 2, nrow = 0,
dimnames = list(character(), c("mz", "intensity")))
} else
res <- dbGetQuery(
.dbcon(x), stri_c("select * from ", tbl, " limit 1"))
Expand Down Expand Up @@ -259,61 +263,42 @@ MsBackendSql <- function() {
res <- dbExecute(con, sql[[2L]])
}

.initialize_tables_blob_sql <- function(con, cols, partitionBy = "none",
partitionNumber = 10) {
sql_a <- stri_c("CREATE TABLE msms_spectrum (",
stri_c(names(cols), cols, sep = " ", collapse = ", "),
", spectrum_id_ INTEGER, PRIMARY KEY (spectrum_id_))")
sql_b <- stri_c("CREATE TABLE msms_spectrum_peak_blob (mz MEDIUMBLOB, ",
"intensity MEDIUMBLOB, spectrum_id_ INTEGER")
## MySQL/MariaDB supports partitioning
if (.is_maria_db(con)) {
sql_a <- stri_c(sql_a, " ENGINE=ARIA;")
if (partitionBy == "none")
sql_b <- stri_c(sql_b, ", PRIMARY KEY (spectrum_id_)) ENGINE=ARIA;")
if (partitionBy == "spectrum")
sql_b <- stri_c(sql_b, ", PRIMARY KEY (spectrum_id_)) ENGINE=ARIA ",
"PARTITION BY HASH (spectrum_id_) PARTITIONS ",
partitionNumber, ";")
if (partitionBy == "chunk")
sql_b <- stri_c(sql_b, ", partition_ SMALLINT, ",
"PRIMARY KEY (spectrum_id_)) ENGINE=ARIA ",
"PARTITION BY HASH (partition_) PARTITIONS ",
partitionNumber, ";")
} else
sql_b <- stri_c(sql_b, ");")
list(sql_a, sql_b)
}

.initialize_tables_blob2_sql <- function(con, cols, partitionBy = "none",
partitionNumber = 10) {
sql_a <- stri_c("CREATE TABLE msms_spectrum (",
stri_c(names(cols), cols, sep = " ", collapse = ", "),
", spectrum_id_ INTEGER, PRIMARY KEY (spectrum_id_))")
sql_b <- stri_c("CREATE TABLE msms_spectrum_peak_blob2 ",
"(peaks MEDIUMBLOB, spectrum_id_ INTEGER")
## MySQL/MariaDB supports partitioning
if (.is_maria_db(con)) {
sql_a <- stri_c(sql_a, " ENGINE=ARIA;")
if (partitionBy == "none")
sql_b <- stri_c(sql_b, ", PRIMARY KEY (spectrum_id_)) ENGINE=ARIA;")
if (partitionBy == "spectrum")
sql_b <- stri_c(sql_b, ", PRIMARY KEY (spectrum_id_)) ENGINE=ARIA ",
"PARTITION BY HASH (spectrum_id_) PARTITIONS ",
partitionNumber, ";")
if (partitionBy == "chunk")
sql_b <- stri_c(sql_b, ", partition_ SMALLINT, ",
"PRIMARY KEY (spectrum_id_)) ENGINE=ARIA ",
"PARTITION BY HASH (partition_) PARTITIONS ",
partitionNumber, ";")
} else
sql_b <- stri_c(sql_b, ");")
list(sql_a, sql_b)
}
.initialize_tables_blob_sql <-
function(con, cols, partitionBy = "none", partitionNumber = 10,
peaks_sql = "mz MEDIUMBLOB, intensity MEDIUMBLOB",
peaks_table = "msms_spectrum_peak_blob") {
sql_a <- stri_c("CREATE TABLE msms_spectrum (",
stri_c(names(cols), cols, sep = " ", collapse = ", "),
", spectrum_id_ INTEGER, PRIMARY KEY (spectrum_id_))")
sql_b <- stri_c("CREATE TABLE ", peaks_table, " (", peaks_sql,
", spectrum_id_ INTEGER")
## MySQL/MariaDB supports partitioning
if (.is_maria_db(con)) {
sql_a <- stri_c(sql_a, " ENGINE=ARIA;")
if (partitionBy == "none")
sql_b <- stri_c(
sql_b, ", PRIMARY KEY (spectrum_id_)) ENGINE=ARIA;")
if (partitionBy == "spectrum")
sql_b <- stri_c(
sql_b, ", PRIMARY KEY (spectrum_id_)) ENGINE=ARIA ",
"PARTITION BY HASH (spectrum_id_) PARTITIONS ",
partitionNumber, ";")
if (partitionBy == "chunk")
sql_b <- stri_c(
sql_b, ", partition_ SMALLINT, ",
"PRIMARY KEY (spectrum_id_)) ENGINE=ARIA ",
"PARTITION BY HASH (partition_) PARTITIONS ",
partitionNumber, ";")
} else
sql_b <- stri_c(sql_b, ");")
list(sql_a, sql_b)
}

.initialize_tables_blob2 <- function(con, cols, partitionBy = "none",
partitionNumber = 10) {
sql <- .initialize_tables_blob2_sql(con, cols, partitionBy, partitionNumber)
sql <- .initialize_tables_blob_sql(con, cols, partitionBy, partitionNumber,
peaks_sql = "peaks MEDIUMBLOB",
peaks_table = "msms_spectrum_peak_blob2")
res <- dbExecute(con, sql[[1L]])
res <- dbExecute(con, sql[[2L]])
}
Expand Down
2 changes: 1 addition & 1 deletion R/MsBackendSql.R
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ setReplaceMethod("$", "MsBackendSql", function(x, name, value) {
callNextMethod()
})

#' @importMethodsFrom Spectra spectraData spectraVariables
#' @importMethodsFrom ProtGenerics spectraData spectraVariables
#'
#' @exportMethod spectraData
#'
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_MsBackendOfflineSql.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_that("backendInitialize,MsBackendOfflineSql works", {

expect_output(show(res), "MsBackendOfflineSql")

## with data. LLLLLL
## with data.
data <- spectraData(mm8_be_long)
tf <- tempfile()
res <- backendInitialize(MsBackendOfflineSql(),
Expand Down
Loading

0 comments on commit f0be11e

Please sign in to comment.