comparison purityA.R @ 8:94a2b6571758 draft

planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 7e1748612a9f9dce11a9e54ff36752b600e7aea3
author computational-metabolomics
date Wed, 12 Jun 2024 16:06:42 +0000
parents 18c0038dde9c
children 6400af18199a
comparison
equal deleted inserted replaced
7:d7104112fac6 8:94a2b6571758
1 library(msPurity) 1 library(msPurity)
2 library(optparse) 2 library(optparse)
3 print(sessionInfo()) 3 print(sessionInfo())
4 4
5 option_list <- list( 5 option_list <- list(
6 make_option(c("-o", "--out_dir"), type = "character"), 6 make_option(c("-o", "--out_dir"), type = "character"),
7 make_option("--mzML_files", type = "character"), 7 make_option("--mzML_files", type = "character"),
8 make_option("--galaxy_names", type = "character"), 8 make_option("--galaxy_names", type = "character"),
9 make_option("--minOffset", type = "numeric"), 9 make_option("--minOffset", type = "numeric"),
10 make_option("--maxOffset", type = "numeric"), 10 make_option("--maxOffset", type = "numeric"),
11 make_option("--ilim", type = "numeric"), 11 make_option("--ilim", type = "numeric"),
12 make_option("--iwNorm", default = "none", type = "character"), 12 make_option("--iwNorm", default = "none", type = "character"),
13 make_option("--exclude_isotopes", action = "store_true"), 13 make_option("--exclude_isotopes", action = "store_true"),
14 make_option("--isotope_matrix", type = "character"), 14 make_option("--isotope_matrix", type = "character"),
15 make_option("--mostIntense", action = "store_true"), 15 make_option("--mostIntense", action = "store_true"),
16 make_option("--plotP", action = "store_true"), 16 make_option("--plotP", action = "store_true"),
17 make_option("--nearest", action = "store_true"), 17 make_option("--nearest", action = "store_true"),
18 make_option("--cores", default = 4), 18 make_option("--cores", default = 4),
19 make_option("--ppmInterp", default = 7) 19 make_option("--ppmInterp", default = 7)
20 ) 20 )
21 21
22 opt <- parse_args(OptionParser(option_list = option_list)) 22 opt <- parse_args(OptionParser(option_list = option_list))
23 print(opt) 23 print(opt)
24 24
25 if (opt$iwNorm == "none") { 25 if (opt$iwNorm == "none") {
26 iwNorm <- FALSE 26 iwNorm <- FALSE
27 iwNormFun <- NULL 27 iwNormFun <- NULL
28 }else if (opt$iwNorm == "gauss") { 28 } else if (opt$iwNorm == "gauss") {
29 iwNorm <- TRUE 29 iwNorm <- TRUE
30 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { 30 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) {
31 print("User has to define offsets if using Gaussian normalisation") 31 print("User has to define offsets if using Gaussian normalisation")
32 }else{ 32 } else {
33 iwNormFun <- msPurity::iwNormGauss(minOff = -as.numeric(opt$minOffset), 33 iwNormFun <- msPurity::iwNormGauss(
34 maxOff = as.numeric(opt$maxOffset)) 34 minOff = -as.numeric(opt$minOffset),
35 maxOff = as.numeric(opt$maxOffset)
36 )
35 } 37 }
36 }else if (opt$iwNorm == "rcosine") { 38 } else if (opt$iwNorm == "rcosine") {
37 iwNorm <- TRUE 39 iwNorm <- TRUE
38 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { 40 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) {
39 print("User has to define offsets if using R-cosine normalisation") 41 print("User has to define offsets if using R-cosine normalisation")
40 }else{ 42 } else {
41 iwNormFun <- msPurity::iwNormRcosine(minOff = -as.numeric(opt$minOffset), 43 iwNormFun <- msPurity::iwNormRcosine(
42 maxOff = as.numeric(opt$maxOffset)) 44 minOff = -as.numeric(opt$minOffset),
45 maxOff = as.numeric(opt$maxOffset)
46 )
43 } 47 }
44 }else if (opt$iwNorm == "QE5") { 48 } else if (opt$iwNorm == "QE5") {
45 iwNorm <- TRUE 49 iwNorm <- TRUE
46 iwNormFun <- msPurity::iwNormQE.5() 50 iwNormFun <- msPurity::iwNormQE.5()
47 } 51 }
48 52
49 filepaths <- trimws(strsplit(opt$mzML_files, ",")[[1]]) 53 filepaths <- trimws(strsplit(opt$mzML_files, ",")[[1]])
51 55
52 56
53 57
54 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { 58 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) {
55 offsets <- NA 59 offsets <- NA
56 }else{ 60 } else {
57 offsets <- as.numeric(c(opt$minOffset, opt$maxOffset)) 61 offsets <- as.numeric(c(opt$minOffset, opt$maxOffset))
58 } 62 }
59 63
60 64
61 if (is.null(opt$mostIntense)) { 65 if (is.null(opt$mostIntense)) {
62 mostIntense <- FALSE 66 mostIntense <- FALSE
63 }else{ 67 } else {
64 mostIntense <- TRUE 68 mostIntense <- TRUE
65 } 69 }
66 70
67 if (is.null(opt$nearest)) { 71 if (is.null(opt$nearest)) {
68 nearest <- FALSE 72 nearest <- FALSE
69 }else{ 73 } else {
70 nearest <- TRUE 74 nearest <- TRUE
71 } 75 }
72 76
73 if (is.null(opt$plotP)) { 77 if (is.null(opt$plotP)) {
74 plotP <- FALSE 78 plotP <- FALSE
75 plotdir <- NULL 79 plotdir <- NULL
76 }else{ 80 } else {
77 plotP <- TRUE 81 plotP <- TRUE
78 plotdir <- opt$out_dir 82 plotdir <- opt$out_dir
79 } 83 }
80 84
81 85
82 if (is.null(opt$isotope_matrix)) { 86 if (is.null(opt$isotope_matrix)) {
83 im <- NULL 87 im <- NULL
84 }else{ 88 } else {
85 im <- read.table(opt$isotope_matrix, 89 im <- read.table(opt$isotope_matrix,
86 header = TRUE, sep = "\t", stringsAsFactors = FALSE) 90 header = TRUE, sep = "\t", stringsAsFactors = FALSE
91 )
87 } 92 }
88 93
89 if (is.null(opt$exclude_isotopes)) { 94 if (is.null(opt$exclude_isotopes)) {
90 isotopes <- FALSE 95 isotopes <- FALSE
91 }else{ 96 } else {
92 isotopes <- TRUE 97 isotopes <- TRUE
93 } 98 }
94 99
95 pa <- msPurity::purityA(filepaths, 100 pa <- msPurity::purityA(filepaths,
96 cores = opt$cores, 101 cores = opt$cores,
97 mostIntense = mostIntense, 102 mostIntense = mostIntense,
98 nearest = nearest, 103 nearest = nearest,
99 offsets = offsets, 104 offsets = offsets,
100 plotP = plotP, 105 plotP = plotP,
101 plotdir = plotdir, 106 plotdir = plotdir,
102 interpol = "linear", 107 interpol = "linear",
103 iwNorm = iwNorm, 108 iwNorm = iwNorm,
104 iwNormFun = iwNormFun, 109 iwNormFun = iwNormFun,
105 ilim = opt$ilim, 110 ilim = opt$ilim,
106 mzRback = "pwiz", 111 mzRback = "pwiz",
107 isotopes = isotopes, 112 isotopes = isotopes,
108 im = im, 113 im = im,
109 ppmInterp = opt$ppmInterp) 114 ppmInterp = opt$ppmInterp
115 )
110 116
111 117
112 if (!is.null(opt$galaxy_names)) { 118 if (!is.null(opt$galaxy_names)) {
113 galaxy_names <- trimws(strsplit(opt$galaxy_names, ",")[[1]]) 119 galaxy_names <- trimws(strsplit(opt$galaxy_names, ",")[[1]])
114 galaxy_names <- galaxy_names[galaxy_names != ""] 120 galaxy_names <- galaxy_names[galaxy_names != ""]