Mercurial > repos > computational-metabolomics > mspurity_averagefragspectra
comparison purityA.R @ 6:52d48bcd3608 draft
"planemo upload for repository https://github.com/computational-metabolomics/mspurity-galaxy commit 2579c8746819670348c378f86116f83703c493eb"
author | computational-metabolomics |
---|---|
date | Thu, 04 Mar 2021 12:29:17 +0000 |
parents | 4207233ead9c |
children | e98ae5c1f4e7 |
comparison
equal
deleted
inserted
replaced
5:e79c1a0654af | 6:52d48bcd3608 |
---|---|
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 | 25 if (opt$iwNorm == "none") { |
26 if (opt$iwNorm=='none'){ | 26 iwNorm <- FALSE |
27 iwNorm = FALSE | 27 iwNormFun <- NULL |
28 iwNormFun = NULL | 28 }else if (opt$iwNorm == "gauss") { |
29 }else if (opt$iwNorm=='gauss'){ | 29 iwNorm <- TRUE |
30 iwNorm = TRUE | 30 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { |
31 if (is.null(opt$minOffset) || is.null(opt$maxOffset)){ | 31 print("User has to define offsets if using Gaussian normalisation") |
32 print('User has to define offsets if using Gaussian normalisation') | |
33 }else{ | 32 }else{ |
34 iwNormFun = msPurity::iwNormGauss(minOff=-as.numeric(opt$minOffset), | 33 iwNormFun <- msPurity::iwNormGauss(minOff = -as.numeric(opt$minOffset), |
35 maxOff=as.numeric(opt$maxOffset)) | 34 maxOff = as.numeric(opt$maxOffset)) |
36 } | 35 } |
37 }else if (opt$iwNorm=='rcosine'){ | 36 }else if (opt$iwNorm == "rcosine") { |
38 iwNorm = TRUE | 37 iwNorm <- TRUE |
39 if (is.null(opt$minOffset) || is.null(opt$maxOffset)){ | 38 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { |
40 print('User has to define offsets if using R-cosine normalisation') | 39 print("User has to define offsets if using R-cosine normalisation") |
41 }else{ | 40 }else{ |
42 iwNormFun = msPurity::iwNormRcosine(minOff=-as.numeric(opt$minOffset), | 41 iwNormFun <- msPurity::iwNormRcosine(minOff = -as.numeric(opt$minOffset), |
43 maxOff=as.numeric(opt$maxOffset)) | 42 maxOff = as.numeric(opt$maxOffset)) |
44 } | 43 } |
45 }else if (opt$iwNorm=='QE5'){ | 44 }else if (opt$iwNorm == "QE5") { |
46 iwNorm = TRUE | 45 iwNorm <- TRUE |
47 iwNormFun = msPurity::iwNormQE.5() | 46 iwNormFun <- msPurity::iwNormQE.5() |
48 } | 47 } |
49 | 48 |
50 filepaths <- trimws(strsplit(opt$mzML_files, ',')[[1]]) | 49 filepaths <- trimws(strsplit(opt$mzML_files, ",")[[1]]) |
51 filepaths <- filepaths[filepaths != ""] | 50 filepaths <- filepaths[filepaths != ""] |
52 | 51 |
53 | 52 |
54 | 53 |
55 if(is.null(opt$minOffset) || is.null(opt$maxOffset)){ | 54 if (is.null(opt$minOffset) || is.null(opt$maxOffset)) { |
56 offsets = NA | 55 offsets <- NA |
57 }else{ | 56 }else{ |
58 offsets = as.numeric(c(opt$minOffset, opt$maxOffset)) | 57 offsets <- as.numeric(c(opt$minOffset, opt$maxOffset)) |
59 } | 58 } |
60 | 59 |
61 | 60 |
62 if(is.null(opt$mostIntense)){ | 61 if (is.null(opt$mostIntense)) { |
63 mostIntense = FALSE | 62 mostIntense <- FALSE |
64 }else{ | 63 }else{ |
65 mostIntense = TRUE | 64 mostIntense <- TRUE |
66 } | 65 } |
67 | 66 |
68 if(is.null(opt$nearest)){ | 67 if (is.null(opt$nearest)) { |
69 nearest = FALSE | 68 nearest <- FALSE |
70 }else{ | 69 }else{ |
71 nearest = TRUE | 70 nearest <- TRUE |
72 } | 71 } |
73 | 72 |
74 if(is.null(opt$plotP)){ | 73 if (is.null(opt$plotP)) { |
75 plotP = FALSE | 74 plotP <- FALSE |
76 plotdir = NULL | 75 plotdir <- NULL |
77 }else{ | 76 }else{ |
78 plotP = TRUE | 77 plotP <- TRUE |
79 plotdir = opt$out_dir | 78 plotdir <- opt$out_dir |
80 } | 79 } |
81 | 80 |
82 | 81 |
83 if (is.null(opt$isotope_matrix)){ | 82 if (is.null(opt$isotope_matrix)) { |
84 im <- NULL | 83 im <- NULL |
85 }else{ | 84 }else{ |
86 im <- read.table(opt$isotope_matrix, | 85 im <- read.table(opt$isotope_matrix, |
87 header = TRUE, sep='\t', stringsAsFactors = FALSE) | 86 header = TRUE, sep = "\t", stringsAsFactors = FALSE) |
88 } | 87 } |
89 | 88 |
90 if (is.null(opt$exclude_isotopes)){ | 89 if (is.null(opt$exclude_isotopes)) { |
91 isotopes <- FALSE | 90 isotopes <- FALSE |
92 }else{ | 91 }else{ |
93 isotopes <- TRUE | 92 isotopes <- TRUE |
94 } | 93 } |
95 | 94 |
108 isotopes = isotopes, | 107 isotopes = isotopes, |
109 im = im, | 108 im = im, |
110 ppmInterp = opt$ppmInterp) | 109 ppmInterp = opt$ppmInterp) |
111 | 110 |
112 | 111 |
113 if (!is.null(opt$galaxy_names)){ | 112 if (!is.null(opt$galaxy_names)) { |
114 galaxy_names <- trimws(strsplit(opt$galaxy_names, ',')[[1]]) | 113 galaxy_names <- trimws(strsplit(opt$galaxy_names, ",")[[1]]) |
115 galaxy_names <- galaxy_names[galaxy_names != ""] | 114 galaxy_names <- galaxy_names[galaxy_names != ""] |
116 names(pa@fileList) <- galaxy_names | 115 names(pa@fileList) <- galaxy_names |
117 } | 116 } |
118 | 117 |
119 print(pa) | 118 print(pa) |
120 save(pa, file=file.path(opt$out_dir, 'purityA_output.RData')) | 119 save(pa, file = file.path(opt$out_dir, "purityA_output.RData")) |
121 | 120 |
122 pa@puritydf$filename <- sapply(pa@puritydf$fileid, function(x) names(pa@fileList)[as.integer(x)]) | 121 pa@puritydf$filename <- sapply(pa@puritydf$fileid, function(x) names(pa@fileList)[as.integer(x)]) |
123 | 122 |
124 print(head(pa@puritydf)) | 123 print(head(pa@puritydf)) |
125 write.table(pa@puritydf, file.path(opt$out_dir, 'purityA_output.tsv'), row.names=FALSE, sep='\t') | 124 write.table(pa@puritydf, file.path(opt$out_dir, "purityA_output.tsv"), row.names = FALSE, sep = "\t") |
126 | |
127 # removed_peaks <- data.frame(removed_peaks) | |
128 # write.table(data.frame('ID'=rownames(removed_peaks),removed_peaks), | |
129 # file.path(opt$out_dir, 'removed_peaks.txt'), row.names=FALSE, sep='\t') |