diff createMSP.R @ 6:6b9a83e08467 draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
author computational-metabolomics
date Thu, 04 Mar 2021 12:25:25 +0000
parents 1cba235b1972
children b16952cc06d2
line wrap: on
line diff
--- a/createMSP.R	Fri Nov 13 09:47:47 2020 +0000
+++ b/createMSP.R	Thu Mar 04 12:25:25 2021 +0000
@@ -4,39 +4,40 @@
 
 # Get the parameter
 option_list <- list(
-  make_option("--rdata_input",type="character"),
-  make_option("--method",type="character"),
-  make_option("--metadata",type="character"),
-  make_option("--metadata_cols",type="character"),
-  make_option("--metadata_cols_filter",type="character"),
-  make_option("--adduct_split", action="store_true"),
-  make_option("--xcms_groupids",type="character"),
-  make_option("--filter",action="store_true"),
-  make_option("--intensity_ra",type="character"),
-  make_option("--include_adducts",type="character"),
-  make_option("--msp_schema",type="character"),
-  make_option("--include_adducts_custom",type="character", default=""),
-  make_option("--out_dir",type="character", default=".")
+  make_option("--rdata_input", type = "character"),
+  make_option("--method", type = "character"),
+  make_option("--metadata", type = "character"),
+  make_option("--metadata_cols", type = "character"),
+  make_option("--metadata_cols_filter", type = "character"),
+  make_option("--adduct_split", action = "store_true"),
+  make_option("--xcms_groupids", type = "character"),
+  make_option("--filter", action = "store_true"),
+  make_option("--intensity_ra", type = "character"),
+  make_option("--include_adducts", type = "character"),
+  make_option("--msp_schema", type = "character"),
+  make_option("--include_adducts_custom", type = "character", default = ""),
+  make_option("--out_dir", type = "character", default = ".")
 )
-opt <- parse_args(OptionParser(option_list=option_list))
+opt <- parse_args(OptionParser(option_list = option_list))
 
 print(opt)
 
 load(opt$rdata_input)
 
-if (is.null(opt$metadata)){
+if (is.null(opt$metadata)) {
   metadata <- NULL
 }else{
-  metadata <- read.table(opt$metadata,  header = TRUE, sep='\t', stringsAsFactors = FALSE, check.names = FALSE)
+  metadata <- read.table(opt$metadata,  header = TRUE, sep = "\t",
+                         stringsAsFactors = FALSE, check.names = FALSE)
 
-  if(!opt$metadata_cols_filter==''){
-     metadata_cols_filter <- strsplit(opt$metadata_cols_filter, ',')[[1]]
+  if (!opt$metadata_cols_filter == "") {
+     metadata_cols_filter <- strsplit(opt$metadata_cols_filter, ",")[[1]]
 
-     metadata <- metadata[,metadata_cols_filter, drop=FALSE]
+     metadata <- metadata[, metadata_cols_filter, drop = FALSE]
      print(metadata)
 
-     if (!"grpid" %in% colnames(metadata)){
-       metadata$grpid <- 1:nrow(metadata)
+     if (!"grpid" %in% colnames(metadata)) {
+       metadata$grpid <- seq_len(nrow(metadata))
      }
 
      print(metadata)
@@ -47,7 +48,7 @@
 
 
 
-if (is.null(opt$metadata_cols) || opt$metadata_cols==''){
+if (is.null(opt$metadata_cols) || opt$metadata_cols == "") {
     metadata_cols <- NULL
 }else{
     metadata_cols <- opt$metadata_cols
@@ -55,36 +56,33 @@
 }
 
 
-if(is.null(opt$adduct_split)){
+if (is.null(opt$adduct_split)) {
   adduct_split <- FALSE
 }else{
   adduct_split <- TRUE
 }
 
-if (is.null(opt$xcms_groupids)){
+if (is.null(opt$xcms_groupids)) {
   xcms_groupids <- NULL
 }else{
-  xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ',')[[1]])
+  xcms_groupids <- trimws(strsplit(opt$xcms_groupids, ",")[[1]])
 }
 
 
-
-
-
-if (is.null(opt$include_adducts_custom)){
-  include_adducts_custom <- ''
+if (is.null(opt$include_adducts_custom)) {
+  include_adducts_custom <- ""
 }else{
   include_adducts_custom <- opt$include_adducts_custom
 }
 
 
-if (opt$include_adducts=='None'){
-  include_adducts <- ''
+if (opt$include_adducts == "None") {
+  include_adducts <- ""
 }else{
   include_adducts <- opt$include_adducts
 }
 
-include_adducts_all <- paste(include_adducts_custom, ',', include_adducts, sep="")
+include_adducts_all <- paste(include_adducts_custom, ",", include_adducts, sep = "")
 
 include_adducts_all <- gsub("^,", "", include_adducts_all)
 include_adducts_all <- gsub(",$", "", include_adducts_all)
@@ -96,7 +94,7 @@
 
 
 
-if(is.null(opt$filter)){
+if (is.null(opt$filter)) {
   filter <- FALSE
 }else{
   filter <- TRUE
@@ -105,15 +103,15 @@
 
 
 msPurity::createMSP(pa,
-                    msp_file_pth = file.path(opt$out_dir, 'lcmsms_spectra.msp'),
+                    msp_file_pth = file.path(opt$out_dir, "lcmsms_spectra.msp"),
                     metadata = metadata,
                     metadata_cols = metadata_cols,
                     method = opt$method,
                     adduct_split = adduct_split,
                     xcms_groupids = xcms_groupids,
                     filter = filter,
-                    intensity_ra=opt$intensity_ra,
-                    include_adducts=include_adducts_all,
-                    msp_schema=opt$msp_schema)
+                    intensity_ra = opt$intensity_ra,
+                    include_adducts = include_adducts_all,
+                    msp_schema = opt$msp_schema)
 
-print('msp created')
+print("msp created")