diff purityA.R @ 6:52d48bcd3608 draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
author computational-metabolomics
date Thu, 04 Mar 2021 12:29:17 +0000
parents 4207233ead9c
children
line wrap: on
line diff
--- a/purityA.R	Fri Nov 13 09:55:01 2020 +0000
+++ b/purityA.R	Thu Mar 04 12:29:17 2021 +0000
@@ -3,91 +3,90 @@
 print(sessionInfo())
 
 option_list <- list(
-  make_option(c("-o", "--out_dir"), type="character"),
-  make_option("--mzML_files", type="character"),
-  make_option("--galaxy_names", type="character"),
-  make_option("--minOffset", type="numeric"),
-  make_option("--maxOffset", type="numeric"),
-  make_option("--ilim", type="numeric"),
-  make_option("--iwNorm", default="none", type="character"),
-  make_option("--exclude_isotopes", action="store_true"),
-  make_option("--isotope_matrix", type="character"),
-  make_option("--mostIntense", action="store_true"),
-  make_option("--plotP", action="store_true"),
-  make_option("--nearest", action="store_true"),
-  make_option("--cores", default=4),
-  make_option("--ppmInterp", default=7)
+  make_option(c("-o", "--out_dir"), type = "character"),
+  make_option("--mzML_files", type = "character"),
+  make_option("--galaxy_names", type = "character"),
+  make_option("--minOffset", type = "numeric"),
+  make_option("--maxOffset", type = "numeric"),
+  make_option("--ilim", type = "numeric"),
+  make_option("--iwNorm", default = "none", type = "character"),
+  make_option("--exclude_isotopes", action = "store_true"),
+  make_option("--isotope_matrix", type = "character"),
+  make_option("--mostIntense", action = "store_true"),
+  make_option("--plotP", action = "store_true"),
+  make_option("--nearest", action = "store_true"),
+  make_option("--cores", default = 4),
+  make_option("--ppmInterp", default = 7)
 )
 
-opt <- parse_args(OptionParser(option_list=option_list))
+opt <- parse_args(OptionParser(option_list = option_list))
 print(opt)
 
-
-if (opt$iwNorm=='none'){
-    iwNorm = FALSE
-    iwNormFun = NULL
-}else if (opt$iwNorm=='gauss'){
-    iwNorm = TRUE
-    if (is.null(opt$minOffset) || is.null(opt$maxOffset)){
-      print('User has to define offsets if using Gaussian normalisation')
+if (opt$iwNorm == "none") {
+    iwNorm <- FALSE
+    iwNormFun <- NULL
+}else if (opt$iwNorm == "gauss") {
+    iwNorm <- TRUE
+    if (is.null(opt$minOffset) || is.null(opt$maxOffset)) {
+      print("User has to define offsets if using Gaussian normalisation")
     }else{
-      iwNormFun = msPurity::iwNormGauss(minOff=-as.numeric(opt$minOffset), 
-                                      maxOff=as.numeric(opt$maxOffset))
+      iwNormFun <- msPurity::iwNormGauss(minOff = -as.numeric(opt$minOffset),
+                                         maxOff = as.numeric(opt$maxOffset))
     }
-}else if (opt$iwNorm=='rcosine'){
-    iwNorm = TRUE
-    if (is.null(opt$minOffset) || is.null(opt$maxOffset)){
-      print('User has to define offsets if using R-cosine normalisation')
+}else if (opt$iwNorm == "rcosine") {
+    iwNorm <- TRUE
+    if (is.null(opt$minOffset) || is.null(opt$maxOffset)) {
+      print("User has to define offsets if using R-cosine normalisation")
     }else{
-      iwNormFun = msPurity::iwNormRcosine(minOff=-as.numeric(opt$minOffset), 
-                                          maxOff=as.numeric(opt$maxOffset))
+      iwNormFun <- msPurity::iwNormRcosine(minOff = -as.numeric(opt$minOffset),
+                                           maxOff = as.numeric(opt$maxOffset))
     }
-}else if (opt$iwNorm=='QE5'){
-    iwNorm = TRUE
-    iwNormFun = msPurity::iwNormQE.5()
+}else if (opt$iwNorm == "QE5") {
+    iwNorm <- TRUE
+    iwNormFun <- msPurity::iwNormQE.5()
 }
 
-filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
+filepaths <- trimws(strsplit(opt$mzML_files, ",")[[1]])
 filepaths <- filepaths[filepaths != ""]
 
 
 
-if(is.null(opt$minOffset) || is.null(opt$maxOffset)){
-    offsets = NA
+if (is.null(opt$minOffset) || is.null(opt$maxOffset)) {
+    offsets <- NA
 }else{
-    offsets = as.numeric(c(opt$minOffset, opt$maxOffset))
+    offsets <- as.numeric(c(opt$minOffset, opt$maxOffset))
 }
 
 
-if(is.null(opt$mostIntense)){
-    mostIntense = FALSE
+if (is.null(opt$mostIntense)) {
+    mostIntense <- FALSE
 }else{
-    mostIntense = TRUE
+    mostIntense <- TRUE
 }
 
-if(is.null(opt$nearest)){
-    nearest = FALSE
+if (is.null(opt$nearest)) {
+    nearest <- FALSE
 }else{
-    nearest = TRUE
+    nearest <- TRUE
 }
 
-if(is.null(opt$plotP)){
-    plotP = FALSE
-    plotdir = NULL
+if (is.null(opt$plotP)) {
+    plotP <- FALSE
+    plotdir <- NULL
 }else{
-    plotP = TRUE
-    plotdir = opt$out_dir
+    plotP <- TRUE
+    plotdir <- opt$out_dir
 }
 
 
-if (is.null(opt$isotope_matrix)){
+if (is.null(opt$isotope_matrix)) {
     im <- NULL
 }else{
     im <- read.table(opt$isotope_matrix,
-                     header = TRUE, sep='\t', stringsAsFactors = FALSE)
+                     header = TRUE, sep = "\t", stringsAsFactors = FALSE)
 }
 
-if (is.null(opt$exclude_isotopes)){
+if (is.null(opt$exclude_isotopes)) {
     isotopes <- FALSE
 }else{
     isotopes <- TRUE
@@ -110,20 +109,16 @@
                         ppmInterp = opt$ppmInterp)
 
 
-if (!is.null(opt$galaxy_names)){
-    galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]])
+if (!is.null(opt$galaxy_names)) {
+    galaxy_names <- trimws(strsplit(opt$galaxy_names, ",")[[1]])
     galaxy_names <- galaxy_names[galaxy_names != ""]
     names(pa@fileList) <- galaxy_names
 }
 
 print(pa)
-save(pa, file=file.path(opt$out_dir, 'purityA_output.RData'))
+save(pa, file = file.path(opt$out_dir, "purityA_output.RData"))
 
 pa@puritydf$filename <- sapply(pa@puritydf$fileid, function(x) names(pa@fileList)[as.integer(x)])
 
 print(head(pa@puritydf))
-write.table(pa@puritydf, file.path(opt$out_dir, 'purityA_output.tsv'), 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')
+write.table(pa@puritydf, file.path(opt$out_dir, "purityA_output.tsv"), row.names = FALSE, sep = "\t")