Skip to content
Snippets Groups Projects
Commit a6d074eb authored by Jean-Karim Heriche's avatar Jean-Karim Heriche
Browse files

Store each plate as a transaction. Add fast mode option for storing screens....

Store each plate as a transaction. Add fast mode option for storing screens. Add optional screen parameter to Well$get_all_by_compound().
parent a31ca00d
No related branches found
No related tags found
No related merge requests found
......@@ -67,7 +67,7 @@ Compound <- R6Class(
cat(paste0(paste0("ID: ", self$ID), "\n",
paste0("ChEMBL ID: ", self$ChEMBL_ID), "\n",
paste0("ChEBI ID: ", self$ChEBI_ID), "\n",
paste0("Name ", self$name), "\n",
paste0("Name: ", self$name), "\n",
paste0("Usage class: ", self$usage_class), "\n",
paste0("Dose: ", self$dose), "\n",
paste0("Unit: ", self$unit), "\n",
......
......@@ -74,6 +74,7 @@ PlateHandle <- R6Class(
statement <- "INSERT IGNORE INTO Plate (ID, nrows, ncols, name, type, date_prepared, date_used)
VALUES (?, ?, ?, ?, ?, ?, ?)"
for(plate in plate.list) {
dbBegin(self$dbConnection)
result <- self$dbConnection$execute(statement, list(plate$ID,
plate$nrows,
plate$ncols,
......@@ -105,6 +106,7 @@ PlateHandle <- R6Class(
qc$ID))
}
}
dbCommit(self$dbConnection)
}
}
)
......
......@@ -62,9 +62,11 @@ Screen <- R6Class(
paste0("Ended on: ", self$date_ended), "\n"))
},
#' @description Store the object into the database
store = function() {
#' @param fast.mode (optional, default: FALSE) Speeds up data loading by
#' disabling integrity checks
store = function(fast.mode = FALSE) {
scrh <- ScreenHandle$new(self$dbConnection)
status <- scrh$store(list(self))
status <- scrh$store(list(self), fast.mode = fast.mode)
}
),
private = list(
......
......@@ -109,7 +109,14 @@ ScreenHandle <- R6Class(
},
#' @description Store Screen objects in the database
#' @param screen.list A list of Screen objects
store = function(screen.list) {
#' @param fast.mode (optional, default: FALSE) Speeds up data loading by
#' disabling integrity checks
store = function(screen.list, fast.mode = FALSE) {
if(fast.mode) { # Disable integrity checks
result <- self$dbConnection$execute("SET @@session.unique_checks = 0")
result <- self$dbConnection$execute("SET @@session.foreign_key_checks = 0")
result <- self$dbConnection$execute("SET @@global.innodb_autoinc_lock_mode = 2")
}
statement <- "INSERT IGNORE INTO Screen (ID, name, description, status, date_started, date_ended)
VALUES (?, ?, ?, ?, ?, ?)"
for(screen in screen.list) {
......@@ -138,6 +145,11 @@ ScreenHandle <- R6Class(
}
}
}
if(fast.mode) { # Re-enable integrity checks
result <- self$dbConnection$execute("SET @@session.unique_checks = 1")
result <- self$dbConnection$execute("SET @@session.foreign_key_checks = 1")
result <- self$dbConnection$execute("SET @@global.innodb_autoinc_lock_mode = 1")
}
}
)
)
\ No newline at end of file
......@@ -12,8 +12,8 @@
#' @field qc List of QC objects
#' @field datafiles List of Datafile objects representing plate-level data
#' @field phenotypes List of Phenotype objects
#' @field replicates List of Well objects from the same screen and having the
#' same samples and compounds at the same dose.
#' @field replicates Retrieves a list of Well objects from the same screen and having the
#' same samples and compounds at the same dose. Can't be set.
#'
#' @export
Well <- R6Class(
......
......@@ -94,13 +94,23 @@ WellHandle <- R6Class(
},
#' @description Retrieve all wells where a compound is found
#' @param compound A Compound object
#' @param screen (optional) a Screen object to limit to wells from this screen
#' @return List of Well objects
get_all_by_compound = function(compound) {
query <- "SELECT W.* FROM Well AS W, Well_has_Compound AS WhC
WHERE WhC.Compound_ID = ?
AND WhC.Plate_ID = W.Plate_ID
AND WhC.Well_position = W.position"
data <- self$dbConnection$get_data(query, list(compound$ID))
get_all_by_compound = function(compound, screen = NULL) {
if(is.null(screen)) {
query <- "SELECT W.* FROM Well AS W, Well_has_Compound AS WhC
WHERE WhC.Compound_ID = ?
AND WhC.Plate_ID = W.Plate_ID
AND WhC.Well_position = W.position"
data <- self$dbConnection$get_data(query, list(compound$ID))
} else {
query <- "SELECT W.* FROM Well AS W, Well_has_Compound AS WhC, Screen_has_Plate AS ShP
WHERE WhC.Compound_ID = ? AND ShP.Screen_ID = ?
AND ShP.Plate_ID = WhC.Plate_ID
AND WhC.Plate_ID = W.Plate_ID
AND WhC.Well_position = W.position"
data <- self$dbConnection$get_data(query, list(compound$ID, screen$ID))
}
if(length(data$position)>0) {
wells <- list()
df.list <- split(data, paste0(data$Plate_ID, data$position))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment