Skip to content
Snippets Groups Projects
Commit 416d2ec3 authored by Todor Kondić's avatar Todor Kondić
Browse files

mefrag, errors, test: Complete the system for running MetFrag on `summ' entries.

* metfrag(metrag_run): Update.
parent 43d6b7a2
No related branches found
No related tags found
No related merge requests found
Pipeline #67505 failed
...@@ -31,3 +31,9 @@ check_file_absent <- function(file,what) { ...@@ -31,3 +31,9 @@ check_file_absent <- function(file,what) {
check_not_one <- function(value,what) { check_not_one <- function(value,what) {
if (length(value)!=1L) stop(errorCondition(paste0("Size of", what, " is not one."), class=paste0(what,'-not-one'))) if (length(value)!=1L) stop(errorCondition(paste0("Size of", what, " is not one."), class=paste0(what,'-not-one')))
} }
check_extension <- function(extfileval,what) {
check_notastring(extfileval[[1]],what = what)
if (extfileval[[1]]==extfileval[[2]]) stop(errorCondition(paste0("We could not find the extension for ",what, ". The returned value was: ", extfileval[[2]]),
class = paste0(what,'-no-ext-found')))
}
...@@ -41,7 +41,7 @@ metfrag_get_ms2_spec <- function(ms2,stag_entry) { ...@@ -41,7 +41,7 @@ metfrag_get_ms2_spec <- function(ms2,stag_entry) {
x x
} }
metfrag_run <- function(param,path,subpaths,db_path,stag_tab,ms2,runtime,java_bin) { metfrag_run <- function(param,path,subpaths,db_path,stag_tab,ms2,runtime,java_bin,nproc = 1L) {
keys = intersect(colnames(stag_tab),colnames(ms2)) keys = intersect(colnames(stag_tab),colnames(ms2))
message("Generating MetFrag configs.") message("Generating MetFrag configs.")
file_tab = ms2[stag_tab,{ file_tab = ms2[stag_tab,{
...@@ -60,8 +60,21 @@ metfrag_run <- function(param,path,subpaths,db_path,stag_tab,ms2,runtime,java_bi ...@@ -60,8 +60,21 @@ metfrag_run <- function(param,path,subpaths,db_path,stag_tab,ms2,runtime,java_bi
withr::with_dir(path,{ withr::with_dir(path,{
metfrag_run_many(fn_jar = runtime, metfrag_run_many(fn_jar = runtime,
file_tab = file_tab, file_tab = file_tab,
java_bin = java_bin) java_bin = java_bin,
nproc = nproc)
}) })
## We don't know (so well) in advance what are the endings of the
## results files. Lets find this out.
pth = file.path(path,subpaths[["results"]])
a_res_f = list.files(path = pth,
pattern = param$SampleName)[[1]]
ext = sub(pattern = r"(^.*\.([[:alnum:]]+)$)",r"(\1)", a_res_f)
check_extension(c(ext=ext,file=a_res_f),what="mf-res-file")
file_tab[,f_res:=paste0(param$SampleName,"_",stag,".",(ext))]
} }
...@@ -203,7 +216,8 @@ metfrag_run_many_w_futures <- function(fn_jar,fn_conf,fn_log, mem = NA_character ...@@ -203,7 +216,8 @@ metfrag_run_many_w_futures <- function(fn_jar,fn_conf,fn_log, mem = NA_character
metfrag_run_many <- function(fn_jar,file_tab, mem = NA_character_, java_bin = "java",nproc=1L) { metfrag_run_many <- function(fn_jar,file_tab, mem = NA_character_, java_bin = "java",nproc=1L) {
ntasks = NROW(file_tab) ntasks = NROW(file_tab)
k = ntasks %/% nproc todo = min(nproc,ntasks)
k = ntasks %/% todo
ndone = 0L ndone = 0L
lc = 1L lc = 1L
while (ndone < ntasks) { while (ndone < ntasks) {
...@@ -212,7 +226,6 @@ metfrag_run_many <- function(fn_jar,file_tab, mem = NA_character_, java_bin = "j ...@@ -212,7 +226,6 @@ metfrag_run_many <- function(fn_jar,file_tab, mem = NA_character_, java_bin = "j
for (i in (ndone + 1):ncurr_last) { for (i in (ndone + 1):ncurr_last) {
fn_conf = file_tab[i,f_conf] fn_conf = file_tab[i,f_conf]
fn_log = file_tab[i,f_log] fn_log = file_tab[i,f_log]
message("fn_conf:", fn_conf)
procs[[i-ndone]] = metfrag_run_one(fn_jar, procs[[i-ndone]] = metfrag_run_one(fn_jar,
fn_conf= fn_conf, fn_conf= fn_conf,
fn_log = fn_log, fn_log = fn_log,
......
...@@ -18,3 +18,27 @@ ...@@ -18,3 +18,27 @@
[13] "MetFragDatabaseType = \nFragmentPeakMatchAbsoluteMassDeviation = 0.001\nFragmentPeakMatchRelativeMassDeviation = 5\nDatabaseSearchRelativeMassDeviation = 5\nMetFragScoreTypes = FragmenterScore,OfflineIndividualMoNAScore\nMetFragScoreWeights = 1,1\nMetFragCandidateWriter = CSV\nSampleName = sample_a_[M+]+_a\nMaximumTreeDepth = 2\nMetFragPreProcessingCandidateFilter = UnconnectedCompoundFilter,IsotopeFilter\nMetFragPostProcessingCandidateFilter = InChIKeyFilter\nIonizedPrecursorMass = 777.7789\nIsPositiveIonMode = True\nPrecursorIonMode = 0\nResultsPath = results\nPeakListPath = spec/sample_a_[M+]+_a.csv\n\n" [13] "MetFragDatabaseType = \nFragmentPeakMatchAbsoluteMassDeviation = 0.001\nFragmentPeakMatchRelativeMassDeviation = 5\nDatabaseSearchRelativeMassDeviation = 5\nMetFragScoreTypes = FragmenterScore,OfflineIndividualMoNAScore\nMetFragScoreWeights = 1,1\nMetFragCandidateWriter = CSV\nSampleName = sample_a_[M+]+_a\nMaximumTreeDepth = 2\nMetFragPreProcessingCandidateFilter = UnconnectedCompoundFilter,IsotopeFilter\nMetFragPostProcessingCandidateFilter = InChIKeyFilter\nIonizedPrecursorMass = 777.7789\nIsPositiveIonMode = True\nPrecursorIonMode = 0\nResultsPath = results\nPeakListPath = spec/sample_a_[M+]+_a.csv\n\n"
[14] "MetFragDatabaseType = \nFragmentPeakMatchAbsoluteMassDeviation = 0.001\nFragmentPeakMatchRelativeMassDeviation = 5\nDatabaseSearchRelativeMassDeviation = 5\nMetFragScoreTypes = FragmenterScore,OfflineIndividualMoNAScore\nMetFragScoreWeights = 1,1\nMetFragCandidateWriter = CSV\nSampleName = sample_a_[M-]-_a\nMaximumTreeDepth = 2\nMetFragPreProcessingCandidateFilter = UnconnectedCompoundFilter,IsotopeFilter\nMetFragPostProcessingCandidateFilter = InChIKeyFilter\nIonizedPrecursorMass = 777.7789\nIsPositiveIonMode = False\nPrecursorIonMode = 0\nResultsPath = results\nPeakListPath = spec/sample_a_[M-]-_a.csv\n\n" [14] "MetFragDatabaseType = \nFragmentPeakMatchAbsoluteMassDeviation = 0.001\nFragmentPeakMatchRelativeMassDeviation = 5\nDatabaseSearchRelativeMassDeviation = 5\nMetFragScoreTypes = FragmenterScore,OfflineIndividualMoNAScore\nMetFragScoreWeights = 1,1\nMetFragCandidateWriter = CSV\nSampleName = sample_a_[M-]-_a\nMaximumTreeDepth = 2\nMetFragPreProcessingCandidateFilter = UnconnectedCompoundFilter,IsotopeFilter\nMetFragPostProcessingCandidateFilter = InChIKeyFilter\nIonizedPrecursorMass = 777.7789\nIsPositiveIonMode = False\nPrecursorIonMode = 0\nResultsPath = results\nPeakListPath = spec/sample_a_[M-]-_a.csv\n\n"
# function metfrag_run returns correct result.
Code
ftab
Output
ID adduct tag an CE
1: 100 [M+H]+ AA 5413 10
2: 100 [M+H]+ KO 5434 10
f_conf
1: config/testsample_setNTs_ID100_adduct[M+H]+_tagAA_an5413.conf
2: config/testsample_setNTs_ID100_adduct[M+H]+_tagKO_an5434.conf
f_log
1: log/testsample_setNTs_ID100_adduct[M+H]+_tagAA_an5413.log
2: log/testsample_setNTs_ID100_adduct[M+H]+_tagKO_an5434.log
f_spec
1: spec/testsample_setNTs_ID100_adduct[M+H]+_tagAA_an5413.csv
2: spec/testsample_setNTs_ID100_adduct[M+H]+_tagKO_an5434.csv
stag
1: setNTs_ID100_adduct[M+H]+_tagAA_an5413
2: setNTs_ID100_adduct[M+H]+_tagKO_an5434
f_res
1: testsample_setNTs_ID100_adduct[M+H]+_tagAA_an5413.csv
2: testsample_setNTs_ID100_adduct[M+H]+_tagKO_an5434.csv
...@@ -54,13 +54,22 @@ ok_return_val("metfrag_run",{ ...@@ -54,13 +54,22 @@ ok_return_val("metfrag_run",{
withr::with_dir(m$run$metfrag$path,{ withr::with_dir(m$run$metfrag$path,{
stagtab = metfrag_get_stag_tab(m$out$tab$summ[ms2_sel == T]) stagtab = metfrag_get_stag_tab(m$out$tab$summ[ms2_sel == T])
metfrag_run(param = m$conf$metfrag$param, ftab = metfrag_run(param = m$conf$metfrag$param,
path = m$run$metfrag$path, path = m$run$metfrag$path,
subpaths = m$run$metfrag$subpaths, subpaths = m$run$metfrag$subpaths,
db_path = m$run$metfrag$db_path, db_path = m$run$metfrag$db_path,
stag_tab = stab, ms2 = m$extr$ms2, stag_tab = stagtab, ms2 = m$extr$ms2,
runtime=m$run$metfrag$runtime, runtime=m$run$metfrag$runtime,
java_bin=m$run$metfrag$java_bin) java_bin=m$run$metfrag$java_bin,
nproc = 2)
expect_snapshot(ftab)
for (f in ftab[,f_res]) {
expect_true(file.exists(file.path(m$run$metfrag$path,
m$run$metfrag$subpaths['results'],
f)))
}
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment