changeset 13:889ef201dea5 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 97c9122c9af9ddca3a2498185ce8c7919c0df03a
author tomnl
date Tue, 08 May 2018 05:33:47 -0400
parents 3c4a548b5237
children e05068fe15a1
files create_sqlite_db.R
diffstat 1 files changed, 52 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/create_sqlite_db.R	Mon May 07 12:06:15 2018 -0400
+++ b/create_sqlite_db.R	Tue May 08 05:33:47 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)
+