diff combineAnnotations.R @ 3:0a3e6c28f1ab draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit e05cb49ba56d359fec34f132d1c9ace582e5b483-dirty
author tomnl
date Tue, 18 Jun 2019 10:02:43 -0400
parents fc9bb7e49a3a
children e96c518a3f06
line wrap: on
line diff
--- a/combineAnnotations.R	Fri Jun 14 09:05:29 2019 -0400
+++ b/combineAnnotations.R	Tue Jun 18 10:02:43 2019 -0400
@@ -13,7 +13,8 @@
   make_option(c("-cw","--sirius_csi_weight"),type="numeric"),
   make_option(c("-pw","--probmetab_weight"),type="numeric"),
   make_option("--create_new_database", action="store_true"),
-  make_option(c("-o","--outdir"),type="character", default=".")
+  make_option(c("-o","--outdir"),type="character", default="."),
+  make_option("--eic", action="store_true")
 )
 opt <- parse_args(OptionParser(option_list=option_list))
 
@@ -45,3 +46,33 @@
                              weights = weights)
 
 write.table(summary_output, file.path(opt$outdir, 'combined_annotations.tsv'), sep = '\t', row.names = FALSE)
+
+if (!is.null(opt$eic)){
+
+  if (is.null(xset)){
+    xset <- xa@xcmsSet
+  }
+  # previous check should have matched filelists together
+  xset@filepaths <- unname(pa@fileList)
+
+  convert2Raw <- function(x, xset){
+    sid <- unique(x$sample)
+    # for each file get list of peaks
+    x$rt_raw <- xset@rt$raw[[sid]][match(x$rt, xset@rt$corrected[[sid]])]
+    x$rtmin_raw <- xset@rt$raw[[sid]][match(x$rtmin, xset@rt$corrected[[sid]])]
+    x$rtmax_raw <- xset@rt$raw[[sid]][match(x$rtmax, xset@rt$corrected[[sid]])]
+    return(x)
+
+  }
+
+  xset@peaks <- as.matrix(plyr::ddply(data.frame(xset@peaks), ~ sample, convert2Raw, xset=xset))
+
+  # Saves the EICS into the previously created database
+  px <- msPurity::purityX(xset, saveEIC = TRUE,
+                          cores=1, sqlitePth=db_pth,
+                          rtrawColumns = TRUE)
+
+}
+
+closeAllConnections()
+