changeset 12:3c4a548b5237 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 4116082655a03d3007a49e4a4b00fc6ad4698412-dirty
author tomnl
date Mon, 07 May 2018 12:06:15 -0400
parents 2ccfae7470b3
children 889ef201dea5
files create_sqlite_db.R
diffstat 1 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/create_sqlite_db.R	Thu May 03 07:31:13 2018 -0400
+++ b/create_sqlite_db.R	Mon May 07 12:06:15 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 <- 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('metfrag_results', opt$metfrag_result)
+add_extra_table('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, ',