@@ -5,19 +5,56 @@ suppressPackageStartupMessages(library("xcms"))
55cmd_args <- commandArgs(trailingOnly = TRUE )
66
77filepath <- cmd_args [1 ]
8- trim <- as.numeric(cmd_args [2 ])
9- resol <- as.numeric(cmd_args [3 ])
8+ outdir <- cmd_args [2 ]
9+ trim <- as.numeric(cmd_args [3 ])
10+ resol <- as.numeric(cmd_args [4 ])
11+
12+ # initialize
13+ trim_left_pos <- NULL
14+ trim_right_pos <- NULL
15+ trim_left_neg <- NULL
16+ trim_right_neg <- NULL
17+ breaks_fwhm <- NULL
18+ breaks_fwhm_avg <- NULL
19+ bins <- NULL
1020
1121# read in mzML file
1222raw_data <- suppressMessages(xcms :: xcmsRaw(filepath ))
1323
14- # get trim parameters and save them to file
15- get_trim_parameters(raw_data @ scantime , raw_data @ polarity , trim )
24+ # Get time values for positive and negative scans
25+ pos_times <- raw_data @ scantime [raw_data @ polarity == " positive" ]
26+ neg_times <- raw_data @ scantime [raw_data @ polarity == " negative" ]
27+
28+ # trim (remove) scans at the start and end for positive
29+ trim_left_pos <- round(pos_times [length(pos_times ) * (trim * 1.5 )]) # 15% aan het begin
30+ trim_right_pos <- round(pos_times [length(pos_times ) * (1 - (trim * 0.5 ))]) # 5% aan het eind
1631
17- # create breaks of bins for intensities. Bin size is a function of fwhm which is a function of m/z
18- get_breaks_for_bins(raw_data $ mzrange , resol )
32+ # trim (remove) scans at the start and end for negative
33+ trim_left_neg <- round(neg_times [length(neg_times ) * trim ])
34+ trim_right_neg <- round(neg_times [length(neg_times ) * (1 - trim )])
1935
20- # Determine maximum m/z and save to file
36+ # Mass range m/z
37+ low_mz <- raw_data @ mzrange [1 ]
2138high_mz <- raw_data @ mzrange [2 ]
22- save(high_mz , file = " highest_mz.RData" )
2339
40+ # determine number of segments (bins)
41+ nr_segments <- 2 * (high_mz - low_mz )
42+ segment <- seq(from = low_mz , to = high_mz , length.out = nr_segments + 1 )
43+
44+ # determine start and end of each bin.
45+ for (i in 1 : nr_segments ) {
46+ start_segment <- segment [i ]
47+ end_segment <- segment [i + 1 ]
48+ resol_mz <- resol * (1 / sqrt(2 ) ^ (log2(start_segment / 200 )))
49+ fwhm_segment <- start_segment / resol_mz
50+ breaks_fwhm <- c(breaks_fwhm , seq(from = (start_segment + fwhm_segment ), to = end_segment , by = 0.2 * fwhm_segment ))
51+ # average the m/z instead of start value
52+ range <- seq(from = (start_segment + fwhm_segment ), to = end_segment , by = 0.2 * fwhm_segment )
53+ delta_mz <- range [2 ] - range [1 ]
54+ breaks_fwhm_avg <- c(breaks_fwhm_avg , range + 0.5 * delta_mz )
55+ }
56+
57+ # generate output file
58+ save(breaks_fwhm , breaks_fwhm_avg , file = " breaks.fwhm.RData" )
59+ save(trim_left_pos , trim_right_pos , trim_left_neg , trim_right_neg , file = " trim_params.RData" )
60+ save(high_mz , file = " highest_mz.RData" )
0 commit comments