From 6fc871940de7bc1d5f94a8135ede5b3e2a50b658 Mon Sep 17 00:00:00 2001 From: lalo-caballero Date: Mon, 27 May 2024 13:06:16 +0000 Subject: [PATCH] calculate inv_k0 in initiaize sampe + document --- R/aaa-class-GCIMSChromatogram.R | 10 +++++++--- R/aaa-class-GCIMSSample.R | 13 ++++++++++++- R/utils-io-mea.R | 12 ------------ man/GCIMSChromatogram-class.Rd | 2 ++ man/GCIMSChromatogram.Rd | 3 +++ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/R/aaa-class-GCIMSChromatogram.R b/R/aaa-class-GCIMSChromatogram.R index 786189ba..59d79a23 100644 --- a/R/aaa-class-GCIMSChromatogram.R +++ b/R/aaa-class-GCIMSChromatogram.R @@ -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. @@ -20,6 +21,7 @@ methods::setClass( Class = "GCIMSChromatogram", slots = c( retention_time = "numeric", + retention_index = "numericOrNULL", intensity = "numeric", baseline = "numericOrNULL", drift_time_idx = "integer", @@ -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 @@ -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. @@ -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) } diff --git a/R/aaa-class-GCIMSSample.R b/R/aaa-class-GCIMSSample.R index 76f0320f..ff957474 100644 --- a/R/aaa-class-GCIMSSample.R +++ b/R/aaa-class-GCIMSSample.R @@ -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", @@ -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 diff --git a/R/utils-io-mea.R b/R/utils-io-mea.R index 19e9ac02..92dc9cb4 100644 --- a/R/utils-io-mea.R +++ b/R/utils-io-mea.R @@ -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, diff --git a/man/GCIMSChromatogram-class.Rd b/man/GCIMSChromatogram-class.Rd index 87a348bb..cb60b1db 100644 --- a/man/GCIMSChromatogram-class.Rd +++ b/man/GCIMSChromatogram-class.Rd @@ -82,6 +82,8 @@ or the aggregation of several chromatograms. \describe{ \item{\code{retention_time}}{A numeric vector with retention times} +\item{\code{retention_index}}{A numeric vector with retention indexes} + \item{\code{intensity}}{A numeric vector with the corresponding intensities} \item{\code{baseline}}{A numeric vector of the same length as \code{intensity} with the corresponding baseline, diff --git a/man/GCIMSChromatogram.Rd b/man/GCIMSChromatogram.Rd index beecdae5..47ee86ff 100644 --- a/man/GCIMSChromatogram.Rd +++ b/man/GCIMSChromatogram.Rd @@ -6,6 +6,7 @@ \usage{ GCIMSChromatogram( retention_time, + retention_index = NULL, intensity, drift_time_idx = NA_integer_, drift_time_ms = NA_real_, @@ -18,6 +19,8 @@ GCIMSChromatogram( \arguments{ \item{retention_time}{A numeric vector with retention times} +\item{retention_index}{A numeric vector with retention indexes} + \item{intensity}{A numeric vector with the corresponding intensities} \item{drift_time_idx}{The index or indices used to get the intensity}