comparison MS2snoop.R @ 6:77abacd33c31 draft

planemo upload commit 1f791337b9b8f08326c01bf4799f50493ef54f80
author workflow4metabolomics
date Fri, 30 Sep 2022 16:18:56 +0000
parents 78d5a12406c2
children 2a1f120a6874
comparison
equal deleted inserted replaced
5:78d5a12406c2 6:77abacd33c31
1 #'
2 #' read and process mspurity W4M files 1 #' read and process mspurity W4M files
3 #' create a summary of fragment for each precursor and a graphics of peseudo 2 #' create a summary of fragment for each precursor and a graphics of peseudo
4 #' spectra + correlation on which checking of fragment is based on 3 #' spectra + correlation on which checking of fragment is based on
5 #' V3 try to identify and process multiple files for 1 precursor which may 4 #' V3 try to identify and process multiple files for 1 precursor which may
6 #' occur if different collision energy are used 5 #' occur if different collision energy are used
52 ######################################################################## 51 ########################################################################
53 52
54 get_formulas <- function( 53 get_formulas <- function(
55 mzref, 54 mzref,
56 spectra, 55 spectra,
57 nominal_mz_list,
58 processing_parameters, 56 processing_parameters,
59 background = !TRUE 57 background = !TRUE
60 ) { 58 ) {
61 if (is.vector(mzref) && length(mzref) > 1) { 59 if (is.vector(mzref) && length(mzref) > 1) {
62 return(lapply( 60 return(lapply(
63 mzref, 61 mzref,
64 function(mz) { 62 function(mz) {
65 return(get_formulas( 63 return(get_formulas(
66 mzref = mz, 64 mzref = mz,
67 spectra = spectra, 65 spectra = spectra,
68 nominal_mz_list = nominal_mz_list,
69 processing_parameters = processing_parameters, 66 processing_parameters = processing_parameters,
70 background = background 67 background = background
71 )) 68 ))
72 } 69 }
73 )) 70 ))
152 ) 149 )
153 file_content <- sprintf( 150 file_content <- sprintf(
154 "%s\n\n>collision\n%s", 151 "%s\n\n>collision\n%s",
155 file_content, 152 file_content,
156 paste( 153 paste(
157 sprintf("%s %s", spectra$mz, spectra$intensities), 154 paste(spectra$mz, spectra$intensities),
158 collapse = "\n" 155 collapse = "\n"
159 ) 156 )
160 ) 157 )
161 cat(file_content, file = path, append = FALSE) 158 cat(file_content, file = path, append = FALSE)
162 } 159 }
234 if (delta_unit == "ppm") { 231 if (delta_unit == "ppm") {
235 filter <- abs(sirius_results$ppm) <= delta 232 filter <- abs(sirius_results$ppm) <= delta
236 fine <- which(filter) 233 fine <- which(filter)
237 not_fine <- which(!filter) 234 not_fine <- which(!filter)
238 catf( 235 catf(
239 paste("[KO] fragment %s (m/z=%s) eleminated because ppm=%s is greater", 236 paste(
237 "[KO] fragment %s (m/z=%s) eleminated because ppm=%s is greater",
240 "than delta=%s\n" 238 "than delta=%s\n"
241 ), 239 ),
242 sirius_results[not_fine, ]$formula, 240 sirius_results[not_fine, ]$formula,
243 sirius_results[not_fine, ]$mz, 241 sirius_results[not_fine, ]$mz,
244 sirius_results[not_fine, ]$ppm, 242 sirius_results[not_fine, ]$ppm,
414 if (do_sirius) { 412 if (do_sirius) {
415 verbose_catf("Everything is ok, preparing for sirius.\n") 413 verbose_catf("Everything is ok, preparing for sirius.\n")
416 formulas <- get_formulas( 414 formulas <- get_formulas(
417 mzref = processing_parameters$mzref, 415 mzref = processing_parameters$mzref,
418 spectra = data.frame(mz = meaned_mz, intensities = sum_int[-1]), 416 spectra = data.frame(mz = meaned_mz, intensities = sum_int[-1]),
419 nominal_mz_list = vmz,
420 processing_parameters = processing_parameters 417 processing_parameters = processing_parameters
421 ) 418 )
422 if (nrow(formulas) == 0) { 419 if (nrow(formulas) == 0) {
423 catf("No formula found.\n") 420 catf("No formula found.\n")
424 } else { 421 } else {
436 cp_res <- data.frame( 433 cp_res <- data.frame(
437 rep(processing_parameters$c_name, cp_res_length), 434 rep(processing_parameters$c_name, cp_res_length),
438 rep(processing_parameters$inchikey, cp_res_length), 435 rep(processing_parameters$inchikey, cp_res_length),
439 rep(processing_parameters$elemcomposition, cp_res_length), 436 rep(processing_parameters$elemcomposition, cp_res_length),
440 formulas, 437 formulas,
441 vmz, 438 meaned_mz,
442 ppm, 439 ppm,
443 rep(fid, cp_res_length), 440 rep(fid, cp_res_length),
444 cor_abs_int, 441 cor_abs_int,
445 sum_int[-1], 442 sum_int[-1],
446 rel_int, 443 rel_int,