comparison assess_purity_msms.R @ 0:fe7d7cc95ca5 draft

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