changeset 3:7c0834ead235 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit e05cb49ba56d359fec34f132d1c9ace582e5b483-dirty
author tomnl
date Tue, 18 Jun 2019 10:04:42 -0400
parents 52999a8b46fb
children 7a3f8bd7757d
files combineAnnotations.R createDatabase.R createDatabase.xml
diffstat 3 files changed, 60 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/combineAnnotations.R	Fri Jun 14 07:34:13 2019 -0400
+++ b/combineAnnotations.R	Tue Jun 18 10:04:42 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()
+
--- a/createDatabase.R	Fri Jun 14 07:34:13 2019 -0400
+++ b/createDatabase.R	Tue Jun 18 10:04:42 2019 -0400
@@ -10,7 +10,7 @@
 xset_pa_filename_fix <- function(opt, pa, xset){
 
   if (!is.null(opt$mzML_files) && !is.null(opt$galaxy_names)){
-    # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables 
+    # NOTE: Relies on the pa@fileList having the names of files given as 'names' of the variables
     # needs to be done due to Galaxy moving the files around and screwing up any links to files
 
     filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
@@ -58,8 +58,7 @@
   make_option("--cores", default=4),
   make_option("--mzML_files", type="character"),
   make_option("--galaxy_names", type="character"),
-  make_option("--grpPeaklist", type="character"),
-  make_option("--raw_rt_columns", action="store_true")
+  make_option("--grpPeaklist", type="character")
 )
 
 
@@ -100,17 +99,17 @@
 
 
 if (opt$xcms_camera_option=='xcms'){
-  
+
   xset <- loadRData(opt$xset, c('xset','xdata'))
   xset <- getxcmsSetObject(xset)
-  fix <- xset_pa_filename_fix(opt, pa, xset)  
+  fix <- xset_pa_filename_fix(opt, pa, xset)
   pa <- fix[[1]]
   xset <- fix[[2]]
   xa <- NULL
 }else{
-  
+
   xa <- loadRData(opt$xset, 'xa')
-  fix <- xset_pa_filename_fix(opt, pa, xa@xcmsSet)  
+  fix <- xset_pa_filename_fix(opt, pa, xa@xcmsSet)
   pa <- fix[[1]]
   xa@xcmsSet <- fix[[2]]
   xset <- NULL
@@ -128,7 +127,7 @@
 
 dbPth <- msPurity::createDatabase(pa,
                                    xset=xset,
-                                   xsa=xa, 
+                                   xsa=xa,
                                    outDir=opt$outDir,
                                    grpPeaklist=grpPeaklist,
                                    dbName='createDatabase_output.sqlite'
@@ -136,22 +135,33 @@
 
 
 
+
+
 if (!is.null(opt$eic)){
-  if (is.null(opt$raw_rt_columns)){
-    rtrawColumns <- FALSE
-  }else{
-    rtrawColumns <- TRUE
-  }
+
   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 = rtrawColumns)
+                           rtrawColumns = TRUE)
+
 }
 
-con <- DBI::dbConnect(RSQLite::SQLite(), dbPth)
+closeAllConnections()
--- a/createDatabase.xml	Fri Jun 14 07:34:13 2019 -0400
+++ b/createDatabase.xml	Tue Jun 18 10:04:42 2019 -0400
@@ -34,9 +34,7 @@
             #if $eic
                 --eic
             #end if
-            #if $raw_rt_columns
-                --raw_rt_columns
-            #end if
+
             #if $grp_peaklist_opt.grp_peaklist_opt=="yes"
                 --grp_peaklist=$grp_peaklist
             #end if
@@ -44,8 +42,8 @@
     ]]></command>
     <inputs>
         <param type="data" name="xset_xa" label="xcmsSet or CAMERA object"
-               help="Either xcmsSet object saved as 'xset' or CAMERA 'xa' object in an RData file. 
-                     Please specify which to use below" 
+               help="Either xcmsSet object saved as 'xset' or CAMERA 'xa' object in an RData file.
+                     Please specify which to use below"
                format="rdata.xcms.raw,rdata.xcms.group,rdata.xcms.retcor,rdata.xcms.fillpeaks,rdata.camera.quick,rdata.camera.positive,rdata.camera.negative,rdata"/>
         <expand macro="camera_xcms" />
         <param type="data" name="pa" label="purityA object (frag4feature output)" format="rdata"
@@ -54,8 +52,6 @@
                help="The Extracted Ion Chromatogram can be calculated for each peak and stored in
                      the database. Note, this will take considerable time for large datasets and
                      the resulting SQLite database can be large"/>
-	      <param name="raw_rt_columns" type="boolean" label="Use user defined Raw RT columns?"
-               help="Only use if the track_rt_raw tool has been used"/>
         <expand macro="grp_peaklist" />
           <expand macro="fileload" />
     </inputs>