diff flag-remove-peaks.R @ 12:cb8dce9812ff draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit f79fa34772bbab836d89cf8bad52d49285409a98
author tomnl
date Thu, 14 Jun 2018 09:19:47 -0400
parents 0ccb8c91be19
children
line wrap: on
line diff
--- a/flag-remove-peaks.R	Tue Jun 12 12:20:38 2018 -0400
+++ b/flag-remove-peaks.R	Thu Jun 14 09:19:47 2018 -0400
@@ -1,6 +1,6 @@
-library(XCMSwrapper)
+library(msPurity)
 library(optparse)
-
+print(sessionInfo())
 option_list <- list(
   make_option(c("-o", "--out_dir"), type="character", default=getwd(),
               help="Output folder for resulting files [default = %default]"
@@ -8,20 +8,20 @@
   make_option(c("-x", "--xset_path"), type="character", default=file.path(getwd(),"xset.rds"),
               help="The path to the xcmsSet object [default = %default]"
   ),
-  make_option("--polarity", default='NA',
+  make_option("--polarity", default=NA,
               help="polarity (just used for naming purpose for files being saved) [positive, negative, NA] [default %default]"
   ),
-  make_option("--rsd_i_blank", default=NA,
+  make_option("--rsd_i_blank", default=100,
               help="RSD threshold for the blank [default = %default]"
   ),
   make_option("--minfrac_blank", default=0.5,
               help="minimum fraction of files for features needed for the blank [default = %default]"
   ),
-  make_option("--rsd_rt_blank", default=NA,
+  make_option("--rsd_rt_blank", default=100,
               help="RSD threshold for the RT of the blank [default = %default]"
   ),
 
-  make_option("--ithres_blank", default=NA,
+  make_option("--ithres_blank", default=0,
               help="Intensity threshold for the blank [default = %default]"
   ),
   make_option("--s2b", default=10,
@@ -38,13 +38,13 @@
                             if the 'verbose columns' and 'fit gauss' was used with xcms
                             [default = %default]"
   ),
-  make_option("--rsd_i_sample", default=NA,
+  make_option("--rsd_i_sample", default=100,
               help="RSD threshold for the samples [default = %default]"
   ),
   make_option("--minfrac_sample", default=0.8,
               help="minimum fraction of files for features needed for the samples [default = %default]"
   ),
-  make_option("--rsd_rt_sample", default=NA,
+  make_option("--rsd_rt_sample", default=100,
               help="RSD threshold for the RT of the samples [default = %default]"
   ),
   make_option("--ithres_sample", default=5000,
@@ -88,6 +88,11 @@
 # store options
 opt<- parse_args(OptionParser(option_list=option_list))
 
+opt <- replace(opt, opt == "NA", NA)
+
+
+
+
 if (is.null(opt$temp_save)){
     temp_save<-FALSE
 }else{
@@ -128,7 +133,7 @@
 
 
 if (is.null(opt$multilist)){
-    ffrm_out <- XCMSwrapper::flag_remove(xset,
+    ffrm_out <- flag_remove(xset,
                         pol=opt$polarity,
                         rsd_i_blank=opt$rsd_i_blank,
                         minfrac_blank=opt$minfrac_blank,
@@ -148,7 +153,7 @@
                         temp_save=temp_save,
                         remove_spectra=remove_spectra,
                         grp_rm_ids=unlist(strsplit(as.character(opt$grp_rm_ids), split=", "))[[1]])
-
+    print('flag remove finished')
     xset <- ffrm_out[[1]]
     grp_peaklist <- ffrm_out[[2]]
     removed_peaks <- ffrm_out[[3]]
@@ -156,12 +161,14 @@
     save.image(file=file.path(opt$out_dir, 'xset_filtered.RData'))
 
     # grpid needed for mspurity ID needed for deconrank... (will clean up at some up)
+    peak_pth <- file.path(opt$out_dir, 'peaklist_filtered.tsv')
+    print(peak_pth)
     write.table(data.frame('grpid'=rownames(grp_peaklist), 'ID'=rownames(grp_peaklist), grp_peaklist),
-                file.path(opt$out_dir, 'peaklist_filtered.txt'), row.names=FALSE, sep='\t')
+                peak_pth, row.names=FALSE, sep='\t')
 
     removed_peaks <- data.frame(removed_peaks)
     write.table(data.frame('ID'=rownames(removed_peaks),removed_peaks),
-        file.path(opt$out_dir, 'removed_peaks.txt'), row.names=FALSE, sep='\t')
+        file.path(opt$out_dir, 'removed_peaks.tsv'), row.names=FALSE, sep='\t')
 
 }else{