Mercurial > repos > tomnl > create_sqlite_db
diff create_sqlite_db.R @ 11:c59965822dc8 draft
planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 4116082655a03d3007a49e4a4b00fc6ad4698412-dirty
author | tomnl |
---|---|
date | Mon, 07 May 2018 12:09:36 -0400 |
parents | 1a88758357ed |
children | 225009d1f603 |
line wrap: on
line diff
--- a/create_sqlite_db.R Thu May 03 07:34:42 2018 -0400 +++ b/create_sqlite_db.R Mon May 07 12:09:36 2018 -0400 @@ -57,9 +57,12 @@ make_option("--galaxy_names", type="character"), make_option("--grp_peaklist", type="character"), make_option("--db_name", type="character", default='lcms_data.sqlite'), - make_option("--raw_rt_columns", action="store_true") + make_option("--raw_rt_columns", action="store_true"), + make_option("--metfrag_result", type="character"), + make_option("--sirius_csifingerid_result", type="character") ) + # store options opt<- parse_args(OptionParser(option_list=option_list)) @@ -75,7 +78,7 @@ # Requires pa <- loadRData(opt$pa, 'pa') -print('TESTETSTESTETE') + print(pa@fileList) @@ -126,9 +129,37 @@ rtrawColumns = rtrawColumns) } +con <- DBI::dbConnect(RSQLite::SQLite(), db_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 + df <- df[!df$UID=='UID',] + + # get peakid, an scan id + df_ids <- stringr::str_split_fixed(df$UID, '-', 3) + colnames(df_ids) <- c('grp_id', 'file_id', 'peak_id') + df <- cbind(df_ids, df) + # export to database + + + DBI::dbWriteTable(con, name=name, value=df, row.names=FALSE) + + } + +} + +add_extra_table_elucidation('metfrag_results', opt$metfrag_result) +add_extra_table_elucidation('sirius_csifingerid_results', opt$sirius_csifingerid_result) -con <- DBI::dbConnect(RSQLite::SQLite(), db_pth) cmd <- paste('SELECT cpg.grpid, cpg.mz, cpg.mzmin, cpg.mzmax, cpg.rt, cpg.rtmin, cpg.rtmax, c_peaks.cid, ', 'c_peaks.mzmin AS c_peak_mzmin, c_peaks.mzmax AS c_peak_mzmax, ',