CDK-R / cdkr

Integrating R and the CDK
https://cdk-r.github.io/cdkr/
42 stars 27 forks source link

generate.formula for charged species: window not correctly calculated? #132

Open WBS-TW opened 1 year ago

WBS-TW commented 1 year ago

Hi, I am using generate.formula to annotate masses with charge +1 from high resolution masss spectrometers within a small uncertainty specified by the windows parameter. I am uncertain about how this window parameter is included in the calculations as it seems that the charge is added after the calculation of the molecular formula. For instance, I have a mass of 69.03353 and a charge of +1

library(rcdk)
mass <- 69.03353
window <- 0.000345 # correspond to a 5 ppm mass error

# manual calculation of lower bound window range: mass - window = 69.03353 - 0.000345 = 69.033185
# manual calculation of upper bound window range: mass + window = 69.03353 + 0.000345 = 69.033875

element_range <- list(c('C', 0,4), c('H', 0,11), c('O', 0,2), c('P', 0,1))
match <- rcdk::generate.formula(
     mass,
      window = window,
      elements = element_range,
      validation = FALSE,
      charge = 1
    )

This does not give match for any formula with the specified element range. However, the theoretical m/z of C4H5O+ is: 69.0335 which is within the window range. The neutral monoisotopic mass of C4H5O is 69.0340 and above the window range and I was wondering if the charge is added after the calculcations and therefore charged species cannot be correctly found?