changeset 4:7ae48818a229 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 97c9122c9af9ddca3a2498185ce8c7919c0df03a
author tomnl
date Tue, 08 May 2018 05:28:37 -0400
parents 3ecba7815437
children 278a7e7a84cf
files create_sqlite_db.R
diffstat 1 files changed, 78 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/create_sqlite_db.R	Thu May 03 07:26:03 2018 -0400
+++ b/create_sqlite_db.R	Tue May 08 05:28:37 2018 -0400
@@ -57,9 +57,13 @@
   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"),
+  make_option("--probmetab_result", type="character")
 )
 
+
 # store options
 opt<- parse_args(OptionParser(option_list=option_list))
 
@@ -75,7 +79,7 @@
 # Requires
 pa <- loadRData(opt$pa, 'pa')
 
-print('TESTETSTESTETE')
+
 print(pa@fileList)
 
 
@@ -126,9 +130,80 @@
                            rtrawColumns = rtrawColumns)
 }
 
+con <- DBI::dbConnect(RSQLite::SQLite(), db_pth)
+
+add_extra_table_elucidation <- function(name, pth){
+
+  if (!is.null(pth)){
+ 
+     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_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,]
 
 
-con <- DBI::dbConnect(RSQLite::SQLite(), db_pth)
+         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)
+
+
+
 
 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, ',