comparison purityA.R @ 0:f52287a06c02 draft

"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit cb903cd93f9378cfb5eeb68512a54178dcea7bbc-dirty"
author computational-metabolomics
date Wed, 27 Nov 2019 13:44:58 -0500
parents
children 600a866a510c
comparison
equal deleted inserted replaced
-1:000000000000 0:f52287a06c02
1 library(msPurity)
2 library(optparse)
3 print(sessionInfo())
4
5 option_list <- list(
6 make_option(c("-o", "--out_dir"), type="character"),
7 make_option("--mzML_files", type="character"),
8 make_option("--galaxy_names", type="character"),
9 make_option("--minOffset", default=0.5),
10 make_option("--maxOffset", default=0.5),
11 make_option("--ilim", default=0.05),
12 make_option("--iwNorm", default="none", type="character"),
13 make_option("--exclude_isotopes", action="store_true"),
14 make_option("--isotope_matrix", type="character"),
15 make_option("--mostIntense", action="store_true"),
16 make_option("--plotP", action="store_true"),
17 make_option("--nearest", action="store_true"),
18 make_option("--cores", default=4),
19 make_option("--ppmInterp", default=7)
20 )
21
22 opt <- parse_args(OptionParser(option_list=option_list))
23 print(opt)
24
25 minOffset = as.numeric(opt$minOffset)
26 maxOffset = as.numeric(opt$maxOffset)
27
28 if (opt$iwNorm=='none'){
29 iwNorm = FALSE
30 iwNormFun = NULL
31 }else if (opt$iwNorm=='gauss'){
32 iwNorm = TRUE
33 iwNormFun = msPurity::iwNormGauss(minOff=-minOffset, maxOff=maxOffset)
34 }else if (opt$iwNorm=='rcosine'){
35 iwNorm = TRUE
36 iwNormFun = msPurity::iwNormRcosine(minOff=-minOffset, maxOff=maxOffset)
37 }else if (opt$iwNorm=='QE5'){
38 iwNorm = TRUE
39 iwNormFun = msPurity::iwNormQE.5()
40 }
41
42 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]])
43 filepaths <- filepaths[filepaths != ""]
44
45
46
47 if(is.null(opt$minOffset) || is.null(opt$maxOffset)){
48 offsets = NA
49 }else{
50 offsets = as.numeric(c(opt$minOffset, opt$maxOffset))
51 }
52
53
54 if(is.null(opt$mostIntense)){
55 mostIntense = FALSE
56 }else{
57 mostIntense = TRUE
58 }
59
60 if(is.null(opt$nearest)){
61 nearest = FALSE
62 }else{
63 nearest = TRUE
64 }
65
66 if(is.null(opt$plotP)){
67 plotP = FALSE
68 plotdir = NULL
69 }else{
70 plotP = TRUE
71 plotdir = opt$out_dir
72 }
73
74
75 if (is.null(opt$isotope_matrix)){
76 im <- NULL
77 }else{
78 im <- read.table(opt$isotope_matrix,
79 header = TRUE, sep='\t', stringsAsFactors = FALSE)
80 }
81
82 if (is.null(opt$exclude_isotopes)){
83 isotopes <- FALSE
84 }else{
85 isotopes <- TRUE
86 }
87
88 pa <- msPurity::purityA(filepaths,
89 cores = opt$cores,
90 mostIntense = mostIntense,
91 nearest = nearest,
92 offsets = offsets,
93 plotP = plotP,
94 plotdir = plotdir,
95 interpol = "linear",
96 iwNorm = iwNorm,
97 iwNormFun = iwNormFun,
98 ilim = opt$ilim,
99 mzRback = "pwiz",
100 isotopes = isotopes,
101 im = im,
102 ppmInterp = opt$ppmInterp)
103
104
105 if (!is.null(opt$galaxy_names)){
106 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]])
107 galaxy_names <- galaxy_names[galaxy_names != ""]
108 names(pa@fileList) <- galaxy_names
109 }
110
111 print(pa)
112 save(pa, file=file.path(opt$out_dir, 'purityA_output.RData'))
113
114 pa@puritydf$filename <- sapply(pa@puritydf$fileid, function(x) names(pa@fileList)[as.integer(x)])
115
116 print(head(pa@puritydf))
117 write.table(pa@puritydf, file.path(opt$out_dir, 'purityA_output.tsv'), row.names=FALSE, sep='\t')
118
119 # removed_peaks <- data.frame(removed_peaks)
120 # write.table(data.frame('ID'=rownames(removed_peaks),removed_peaks),
121 # file.path(opt$out_dir, 'removed_peaks.txt'), row.names=FALSE, sep='\t')