# HG changeset patch # User tomnl # Date 1525771813 14400 # Node ID eea94e398c26e763d2857e5d5b0f312559d9278c # Parent cea46ee6596debbb87f435c02f5f95f2f04488cb planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 97c9122c9af9ddca3a2498185ce8c7919c0df03a diff -r cea46ee6596d -r eea94e398c26 create_sqlite_db.R --- a/create_sqlite_db.R Mon May 07 12:02:54 2018 -0400 +++ b/create_sqlite_db.R Tue May 08 05:30:13 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") ) @@ -131,13 +132,10 @@ con <- DBI::dbConnect(RSQLite::SQLite(), db_pth) -add_extra_table <- function(name, pth){ +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_extra_table('metfrag_results', opt$metfrag_result) -add_extra_table('sirius_csifingerid_results', opt$sirius_csifingerid_result) + +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) +