comparison MS2snoop.R @ 7:2a1f120a6874 draft default tip

planemo upload commit d9b3849751af6f74e3371db0c3525dcd08728723
author workflow4metabolomics
date Tue, 10 Jan 2023 11:07:48 +0000
parents 77abacd33c31
children
comparison
equal deleted inserted replaced
6:77abacd33c31 7:2a1f120a6874
52 52
53 get_formulas <- function( 53 get_formulas <- function(
54 mzref, 54 mzref,
55 spectra, 55 spectra,
56 processing_parameters, 56 processing_parameters,
57 background = !TRUE 57 background = !TRUE,
58 show_sirius_outputs = !TRUE
58 ) { 59 ) {
59 if (is.vector(mzref) && length(mzref) > 1) { 60 if (is.vector(mzref) && length(mzref) > 1) {
60 return(lapply( 61 return(lapply(
61 mzref, 62 mzref,
62 function(mz) { 63 function(mz) {
87 "--noSummaries", 88 "--noSummaries",
88 "--loglevel=WARNING", 89 "--loglevel=WARNING",
89 "-i='%s'", 90 "-i='%s'",
90 "-o='%s'", 91 "-o='%s'",
91 "tree", 92 "tree",
92 ## loglevel is not working taken into account during 93 "2>&1"
93 ## sirius startup, so we filter outputs...
94 "2>&1 | grep '^(WARNING|SEVERE)'"
95 ), 94 ),
96 input, 95 input,
97 output 96 output
98 ) 97 )
98 if (!show_sirius_outputs) {
99 ## loglevel is not taken into account during
100 ## sirius startup, so we filter outputs...
101 command <- paste(command, "| grep '^(WARNING|SEVERE)'")
102 }
99 verbose_catf( 103 verbose_catf(
100 ">> Sirius is running %swith the command: %s\n", 104 ">> Sirius is running %swith the command: %s\n",
101 if (background) "in the background " else "", 105 if (background) "in the background " else "",
102 command 106 command
103 ) 107 )
187 sirius_results <- get_csv_or_tsv(spectra_filename) 191 sirius_results <- get_csv_or_tsv(spectra_filename)
188 } else { 192 } else {
189 return(rep(NA, length(mz_list))) 193 return(rep(NA, length(mz_list)))
190 } 194 }
191 if (!is.null(trees_filename)) { 195 if (!is.null(trees_filename)) {
192 sirius_results <- cbind(sirius_results, extract_sirius_ppm(trees_filename)) 196 extracted_ppm <- extract_sirius_ppm(trees_filename)
197 sirius_results <- cbind(sirius_results, extracted_ppm)
193 } else { 198 } else {
194 return(rep(NA, length(mz_list))) 199 return(rep(NA, length(mz_list)))
195 } 200 }
196 201
197 fragment_matchings <- data.frame( 202 fragment_matchings <- data.frame(
208 delta_unit = delta_unit 213 delta_unit = delta_unit
209 ) 214 )
210 215
211 for (index in seq_len(nrow(sirius_results))) { 216 for (index in seq_len(nrow(sirius_results))) {
212 result <- sirius_results[index, ] 217 result <- sirius_results[index, ]
213 filter <- which(order(abs(fragment_matchings$mz - result$mz)) == 1) 218 filter <- order(abs(fragment_matchings$mz - result$mz))[1]
214 fragment_matchings[filter, "formula"] <- result$formula 219 fragment_matchings[filter, "formula"] <- result$formula
215 fragment_matchings[filter, "ppm"] <- result$ppm 220 fragment_matchings[filter, "ppm"] <- result$ppm
216 catf( 221 catf(
217 "[OK] Fragment with m/z=%s matches %s with a difference of %s ppm\n", 222 "[OK] Fragment with m/z=%s matches %s with a difference of %s ppm\n",
218 fragment_matchings[filter, "mz"], result$formula, result$ppm 223 fragment_matchings[filter, "mz"], result$formula, result$ppm
1122 return(args) 1127 return(args)
1123 } 1128 }
1124 1129
1125 zip_pdfs <- function(processing_parameters) { 1130 zip_pdfs <- function(processing_parameters) {
1126 if (processing_parameters$do_pdf) { 1131 if (processing_parameters$do_pdf) {
1127 if (zip <- Sys.getenv("R_ZIPCMD", "zip") == "") { 1132 if ((zip <- Sys.getenv("R_ZIPCMD", "zip")) == "") {
1128 catf("R could not fin the zip executable. Trying luck: zip = \"zip\"") 1133 catf("R could not fin the zip executable. Trying luck: zip = \"zip\"")
1129 zip <- "zip" 1134 zip <- "zip"
1130 } else { 1135 } else {
1131 catf("Found zip executable at %s .", zip) 1136 catf("Found zip executable at %s .", zip)
1132 } 1137 }