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