Skip to content

Commit

Permalink
calculate inv_k0 in initiaize sampe + document
Browse files Browse the repository at this point in the history
  • Loading branch information
lalo-caballero committed May 27, 2024
1 parent 806ee72 commit 6fc8719
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
10 changes: 7 additions & 3 deletions R/aaa-class-GCIMSChromatogram.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' or the aggregation of several chromatograms.
#'
#' @slot retention_time A numeric vector with retention times
#' @slot retention_index A numeric vector with retention indexes
#' @slot intensity A numeric vector with the corresponding intensities
#' @slot baseline A numeric vector of the same length as `intensity` with the corresponding baseline,
#' or `NULL` if not set. Use [estimateBaseline()] to estimate it, [baseline()] to directly access it.
Expand All @@ -20,6 +21,7 @@ methods::setClass(
Class = "GCIMSChromatogram",
slots = c(
retention_time = "numeric",
retention_index = "numericOrNULL",
intensity = "numeric",
baseline = "numericOrNULL",
drift_time_idx = "integer",
Expand All @@ -32,12 +34,13 @@ methods::setClass(

methods::setMethod(
"initialize", "GCIMSChromatogram",
function(.Object, retention_time, intensity, drift_time_idx = NA_integer_,
function(.Object, retention_time, retention_index = NULL, intensity, drift_time_idx = NA_integer_,
drift_time_ms = NA_real_, description = "", baseline = NULL,
peaks = NULL, peaks_debug_info = NULL) {
stopifnot(length(retention_time) == length(intensity))
stopifnot(is.null(baseline) || length(retention_time) == length(baseline))
.Object@retention_time <- retention_time
.Object@retention_index <- retention_index
.Object@drift_time_idx <- as.integer(drift_time_idx)
.Object@drift_time_ms <- drift_time_ms
.Object@intensity <- intensity
Expand All @@ -52,6 +55,7 @@ methods::setMethod(
#' Create a [GCIMSChromatogram-class] object
#'
#' @param retention_time A numeric vector with retention times
#' @param retention_index A numeric vector with retention indexes
#' @param intensity A numeric vector with the corresponding intensities
#' @param baseline A numeric vector of the same length as `intensity` with the corresponding baseline,
#' or `NULL` if not set. Use [estimateBaseline()] to estimate it, [baseline()] to directly access it.
Expand All @@ -69,10 +73,10 @@ methods::setMethod(
#' @export
#' @family GCIMSChromatogram
GCIMSChromatogram <- function(
retention_time, intensity, drift_time_idx = NA_integer_,
retention_time, retention_index = NULL, intensity, drift_time_idx = NA_integer_,
drift_time_ms = NA_real_, description = "",
baseline = NULL, peaks = NULL, peaks_debug_info = NULL) {
methods::new("GCIMSChromatogram", retention_time, intensity, drift_time_idx,
methods::new("GCIMSChromatogram", retention_time, retention_index, intensity, drift_time_idx,
drift_time_ms, description, baseline = NULL, peaks = NULL,
peaks_debug_info = NULL)
}
Expand Down
13 changes: 12 additions & 1 deletion R/aaa-class-GCIMSSample.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ methods::setClass(
)
)

.CURRENT_GCIMSSAMPLE_CLASS_VERSION <- numeric_version("0.0.4")
.CURRENT_GCIMSSAMPLE_CLASS_VERSION <- numeric_version("0.1.1")

methods::setMethod(
"initialize", "GCIMSSample",
Expand Down Expand Up @@ -114,6 +114,17 @@ methods::setMethod(
}
}

#Calculate inv_k0 if possible
if (exists("drift_tube_length") & exists("params")){
ims_temp_k <- params$`Temp 1 setpoint`$value + 273.15
pressure_ims <- mean(as.numeric(strsplit(strsplit(params$`Pressure Ambient`$value, "\"")[[1]][2]," ")[[1]]))
drift_tube_length_cm <- drift_tube_length / 10
.Object@inverse_reduced_mobility <- get_inv_k0(drift_time,
drift_tube_length_cm,
pressure_ims,
params$`nom Drift Potential Difference`$value,
ims_temp_k)
}
.Object@class_version <- .CURRENT_GCIMSSAMPLE_CLASS_VERSION
.Object@drift_time <- drift_time
.Object@retention_time <- retention_time
Expand Down
12 changes: 0 additions & 12 deletions R/utils-io-mea.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,9 @@ read_mea <- function(filename) {
description <- tools::file_path_sans_ext(basename(filename), compression = TRUE)
}

#Calculate inv_k0
ims_temp_k <- params$`Temp 1 setpoint`$value + 273.15
pressure_ims <- mean(as.numeric(strsplit(strsplit(params$`Pressure Ambient`$value, "\"")[[1]][2]," ")[[1]]))
drift_tube_length_cm <- drift_tube_length / 10
inv_k0 <- get_inv_k0(drift_time,
drift_tube_length_cm,
pressure_ims,
params$`nom Drift Potential Difference`$value,
ims_temp_k)

GCIMSSample(
drift_time = drift_time,
retention_time = ret_time,
inverse_reduced_mobility = inv_k0,
retention_index = NULL,
data = data,
gc_column = gc_column,
drift_tube_length = drift_tube_length,
Expand Down
2 changes: 2 additions & 0 deletions man/GCIMSChromatogram-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/GCIMSChromatogram.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6fc8719

Please sign in to comment.