Skip to content

Commit

Permalink
Start introducing inv_k0
Browse files Browse the repository at this point in the history
  • Loading branch information
lalo-caballero committed Feb 21, 2024
1 parent cccb778 commit 2ab27b4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions R/aaa-AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,19 @@ setGeneric("baseline<-", function(object, value) standardGeneric("baseline<-"))
#'
#' @export
setGeneric("integratePeaks", function(object, ...) standardGeneric("integratePeaks"))

#' @describeIn GCIMS-generics get inverse reduced mobility
#' @param object An object to get its inverse reduced mobility
#' @param ... Additional arguments for downstream methods
#' @return The object with reduced inverse mobility
#'
#' @export
setGeneric("get_inv_k0", function(object, ...) standardGeneric("get_inv_k0"))

#' @describeIn GCIMS-generics get retention index
#' @param object An object to get its retention index
#' @param ... Additional arguments for downstream methods
#' @return The object with retention index
#'
#' @export
setGeneric("get_ri", function(object, ...) standardGeneric("get_ri"))
4 changes: 4 additions & 0 deletions R/aaa-class-GCIMSDataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ GCIMSDataset <- R6::R6Class("GCIMSDataset",
dt_ref = NULL, # numeric or NULL
#' @field rt_ref A numeric retention time of reference
rt_ref = NULL, # numeric or NULL
#' @field inv_k0_ref A numeric inverse reduced mobility reference
inv_k0_ref = NULL,
#' @field ri_ref A numeric retention index reference
ri_ref = NULL,
#' @field userData A list to store arbitrary data in the dataset
userData = list(), # list
# Methods:
Expand Down
4 changes: 4 additions & 0 deletions R/aaa-class-GCIMSSample.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#' @slot retention_time numeric. (required)
#' @slot data matrix A matrix with drift time in the rows and retention time
#' in columns. (required)
#' @slot inverse_reduced_mobility 1/K0 (calculated from drift_time)
#' @slot retention_index numeric. (calculated from retention_time and references)
#' @slot gc_column character. (optional) The type of chromatographic column used
#' @slot drift_tube_length numeric (optional) The length of the drift tube, in mm
#' @slot drift_gas character. (optional) The drift gas used (e.g "nitrogen")
Expand Down Expand Up @@ -52,6 +54,8 @@ methods::setClass(
drift_time = "numeric",
retention_time = "numeric",
data = "matrix", # [dt, rt]
inverse_reduced_mobility = "numeric",
retention_index = "numeric",
gc_column = "character",
drift_gas = "character",
drift_tube_length = "numeric",
Expand Down
12 changes: 12 additions & 0 deletions R/get_inv_k0-GCIMSDataset.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
methods::setMethod(
"get_inv_k0",
"GCIMSDataset",
function(object){
delayed_op <- DelayedOperation(
name = "get_inverse_reduced_mobility",
fun = get_inv_k0
)
object$appendDelayedOp(delayed_op)
invisible(object)
}
)
25 changes: 25 additions & 0 deletions R/get_inv_k0-GCIMSSample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
methods::setMethod(
"get_inv_k0",
"GCIMSSample",
function(object) {
if (is.null(object@params$`nom Drift Potential Difference`$value) |
is.null(object@params$`Temp 1 setpoint`$value)|
is.null(object@params$`Pressure Ambient`$value) |
length(object@drift_tube_length) == 0
){
stop("IMS Voltage, IMS Tube length, IMS Tempreature and pressure are
needed to calculate the inverse reduced mobility ")
}
drift_time <- object@drift_time / 1000 # in ms to s
Voltage_ims <- object@params$`nom Drift Potential Difference`$value # in V
tube_length_cm <- object@drift_tube_length / 10 # in mm to cm
ims_temp_k <- object@params$`Temp 1 setpoint`$value + 273.15 # in °C
pressure_ims <- mean(as.numeric(strsplit(
object@params$`Pressure Ambient`$value, " ")[[1]]), na.rm = TRUE) #in Pa
K0 <- (0.0027315 * (tube_length_cm ^ 2) * pressure_ims) /
(Voltage_ims* drift_time * ims_temp_k)
inv_k0 <- 1 / K0
object@inverse_reduced_mobility <- inv_k0
invisible(object)
}
)

0 comments on commit 2ab27b4

Please sign in to comment.