From 9413f2212ff90bec626f66c077c01d958689820a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Todor=20Kondi=C4=87?= <todor.kondic@uni.lu> Date: Thu, 1 Oct 2020 11:18:03 +0200 Subject: [PATCH] api: Add sort_spectra * R/api.R(sort_spectra): New function to sort the spectral table. * R/resources.R(DEF_ORDER_SPECTRA): New parameter defining the default order of the spectral table. * NAMESPACE: Update exports. --- NAMESPACE | 3 +++ R/api.R | 15 +++++++++++++-- R/resources.R | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 88439a8..fe5d4c0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(concurrency) export(conf_trans) export(extr_data) export(extract) @@ -9,8 +10,10 @@ export(load_compound_input) export(load_data_input) export(load_inputs) export(mk_comp_tab) +export(mk_tol_funcs) export(prescreen) export(run) export(run_in_dir) +export(sort_spectra) import(data.table) importFrom(shiny,validate) diff --git a/R/api.R b/R/api.R index 3cb675b..e011f54 100644 --- a/R/api.R +++ b/R/api.R @@ -172,7 +172,7 @@ verify_data <- function(conf,all_sets) { return(conf) } -## @export +#' @export concurrency <- function(m) { ## Reads the concurrency entry in the config. It is optional, if ## not given, then it is up to the user to define the plan of the @@ -204,6 +204,7 @@ concurrency <- function(m) { m } +#' @export mk_tol_funcs <- function(m) { ## Depending on units given when the user specified the errors, ## generate functions that calculate errors given the concrete @@ -277,7 +278,7 @@ extr_data <- function(m) { msk <- sapply(tmp,future::resolved) curr_done <- which(msk) - names(msk) <- files + names(msk) <- ftags$Files for (x in curr_done) { message("Done extraction for ", names(msk)[[x]]) @@ -324,3 +325,13 @@ prescreen <- function(m) { m$out$tab$ftab <- merge(m$out$tab$comp,m$qa$ms[,..fields],by=c("Files","adduct","ID")) m } + +##' @export +sort_spectra <- function(m) { + ## Sorts the spectral table (ftab) in order specified either in + ## `order spectra` sublist of m$conf, or if that is null, the + ## DEF_ORDER_SPECTRA. + order <- if (!is.null(m$conf[["order spectra"]])) m$conf[["order spectra"]] else DEF_ORDER_SPECTRA + data.table::setkeyv(m$out$tab$ftab,order) + m +} diff --git a/R/resources.R b/R/resources.R index d62a74f..60c37f5 100644 --- a/R/resources.R +++ b/R/resources.R @@ -183,3 +183,5 @@ QA_NUM_INT <- c("sel_ms2","ind_ms1_rt") QA_COLS <- c(QA_FLAGS,QA_NUM_REAL,QA_NUM_INT) +## Default order of spectra in spectral table +DEF_ORDER_SPECTRA <- c("set","qa_pass","int_ms1","adduct","mz","tag") -- GitLab