diff --git a/R/api.R b/R/api.R index 75b3b556f5c3109c99e4614c836bd0ecf6471305..2f0c870da9ab9672eed036c36e376f1c4e1d272d 100644 --- a/R/api.R +++ b/R/api.R @@ -406,58 +406,10 @@ prescreen <- function(m) { confpres <- conf_trans_pres(m$conf$prescreen) - ## TODO need to fix max spec intensity [is this still relevant? i think not.] - gen_ms2_spec_tab <- function(ms) {data.table::rbindlist(lapply(1:nrow(ms), function (nr) { - adduct <- ms$adduct[[nr]] - ID <- ms$ID[[nr]] - tag <- ms$tag[[nr]] - spec <- ms$specs_by_an[[nr]] - ms2_sel <- ms$ms2_sel[[nr]] - dt <- if (NROW(spec[[1]]) == 0) - dtable(CE=NA_real_, - rt=NA_real_, - spec=list(dtable(mz=NA_real_,intensity=NA_real_)), - ms2_sel=NA) else { - spec[,.(CE=head(CE,1), - rt=head(rt,1), - spec=list(.SD)),by="an",.SDcols=c("mz","intensity")] - spec[, ms2_sel := F] - ## dtable( - ## CE=sapply(spec, - ## function (x) x$CE), - ## rt=sapply(spec, - ## function (x) x$rt), - ## spec=lapply(spec, - ## function (x) x$spec), - ## ms2_sel=F) - - } - if (!is.na(ms2_sel)) dt$ms2_sel[[ms2_sel]] <- T - - - - dt$ID <- ID - dt$adduct <- adduct - dt$tag <- tag - dt[,ms2_max_int := .(sapply(spec,function (sp) sp[,max(intensity)]))] - dt - }))} - - gen_ms1_spec_tab <- function(ms) { - cols <- MS1_SPEC_COLS - ms[,..cols] - } - - m$qa <- create_qa_table(m$extr,confpres) - ## m$qa$prescreen <- confpres - ## TODO UNCOMMENT mms1 <- assess_ms1(m) m1 <- assess_ms1(m) m <- assess_ms2(m1) - m$out$tab$summ <- gen_summ(m$out$tab$comp,m$qa$ms1,m$qa$ms2) - ## data.table::setkeyv(m$out$tab$ms2_spec,BASE_KEY) - ## data.table::setkeyv(m$out$tab$ms1_spec,BASE_KEY) m } @@ -481,9 +433,6 @@ sort_spectra <- function(m) { ## `order spectra` sublist of m$conf, or if that is null, the ## DEF_INDEX_SUMM. - ## Here set default sorting keys. - data.table::setkeyv(m$out$tab$summ,DEF_KEY_SUMM) - ## Now, add secondary indexing. cols <- if (!is.null(m$conf[["summary table"]]$order)) m$conf[["summary table"]]$order else DEF_INDEX_SUMM @@ -500,7 +449,7 @@ sort_spectra <- function(m) { tmp <- quote(data.table::setorder()) tmp[[2]] <- quote(m$out$tab$summ) for (n in 1:length(cols)) tmp[[2+n]] <- parse(text=cols[[n]])[[1]] - message("Ordering expression: ",tmp) + message("Ordering expression: \n",deparse(tmp)) eval(tmp) #Execute the setorder call m @@ -527,9 +476,6 @@ subset_summary <- function(m) { } else m$out$tab$summ - - m$out$tab$flt_summ[,wd:=NULL] # TODO: Handle this more gracefully - # somewhere upstream. m } diff --git a/R/mix.R b/R/mix.R index 86cc2c8b859eb85533258ccf9e8f5250ac5a27ee..1a88fc553803bbcd3169fcb5e96d33b287fc69ce 100644 --- a/R/mix.R +++ b/R/mix.R @@ -189,6 +189,7 @@ gen_summ <- function(comp,qa_ms1,qa_ms2) { summ[,qa_ms2_exists:=the_ifelse(!is.na(CE),T,F)] summ[,qa_pass:=apply(.SD,1,all),.SDcols=QA_FLAGS[!(QA_FLAGS %in% "qa_pass")]] summ$Comments<-"" + data.table::setkeyv(summ,DEF_KEY_SUMM) data.table::setcolorder(summ,SUMM_COLS) summ } diff --git a/R/resources.R b/R/resources.R index 7d6271371440990b8b604ffde4ecd12a0b71979d..9f31a6ff87b930b38df458eb6260c86cacf0e6d2 100644 --- a/R/resources.R +++ b/R/resources.R @@ -175,8 +175,7 @@ MS2_SPEC_COLS <- c("adduct","tag","ID","CE","rt","Files","spec","ms2_max_int") ## MS1 spectral table columns MS1_SPEC_COLS <- c("adduct","tag","ID","eicMS1","ms1_int","ms1_rt","ms1_mean") -## Default sorting keys of spectra in the summary table -DEF_KEY_SUMM <- c("set","qa_pass","ms1_int","adduct","mz","tag") + ## Default secondary indexing in the summary table DEF_INDEX_SUMM <- c("set", "-qa_pass", "-ms1_int", "adduct","-mz") @@ -239,3 +238,6 @@ EMPTY_SUMM <- data.table::data.table(set=character(0), Files=character(0), known=character(0), Comments=character(0)) + +## Default sorting keys of spectra in the summary table +DEF_KEY_SUMM <- c(BASE_KEY_MS2,"an")