Mercurial > repos > tomnl > create_sqlite_db
diff create_sqlite_db.R @ 12:225009d1f603 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 97c9122c9af9ddca3a2498185ce8c7919c0df03a
author | tomnl |
---|---|
date | Tue, 08 May 2018 05:37:10 -0400 |
parents | c59965822dc8 |
children | 4acad02faf32 |
line wrap: on
line diff
--- a/create_sqlite_db.R Mon May 07 12:09:36 2018 -0400 +++ b/create_sqlite_db.R Tue May 08 05:37:10 2018 -0400 @@ -59,7 +59,8 @@ make_option("--db_name", type="character", default='lcms_data.sqlite'), make_option("--raw_rt_columns", action="store_true"), make_option("--metfrag_result", type="character"), - make_option("--sirius_csifingerid_result", type="character") + make_option("--sirius_csifingerid_result", type="character"), + make_option("--probmetab_result", type="character") ) @@ -133,11 +134,8 @@ add_extra_table_elucidation <- function(name, pth){ - print('CHECK1') - print(name) - print(pth) if (!is.null(pth)){ - print('CHECK2') + print(pth) df <- read.table(pth, header = TRUE, sep='\t', stringsAsFactors = FALSE, comment.char = "") # bug for repeating headers @@ -156,8 +154,54 @@ } + +add_probmetab <- function(pth){ + if (!is.null(pth)){ + + df <- read.table(pth, header = TRUE, sep='\t', stringsAsFactors = FALSE, comment.char = "") + df$grp_id <- 1:nrow(df) + start <- T + for (i in 1:nrow(df)){ + + x <- df[i,] + + + if(is.na(x$proba) | x$proba =='NA'){ + + next + } + + mpc <- stringr::str_split(x$mpc, ';') + proba <- stringr::str_split(x$proba, ';') + + for (j in 1:length(mpc[[1]])){ + + row <- c(x$grp_id, x$propmz, mpc[[1]][j], proba[[1]][j]) + + if (start){ + df_out <- data.frame(t(row), stringsAsFactors=F) + start <- F + }else{ + df_out <- data.frame(rbind(df_out, row), stringsAsFactors=F) + } + print(df_out) + + } + + } + + colnames(df_out) <- c('grp_id', 'propmz', 'mpc', 'proba') + DBI::dbWriteTable(con, name='probmetab_results', value=df_out, row.names=FALSE) + + } + + +} + add_extra_table_elucidation('metfrag_results', opt$metfrag_result) add_extra_table_elucidation('sirius_csifingerid_results', opt$sirius_csifingerid_result) +add_probmetab(opt$probmetab_result) +