BCCDC-DSI / RADD

Consult at the BCCDC for Mass Spectrometry
https://bccdc-dsi.github.io/RADD/
MIT License
1 stars 0 forks source link

Find out why `mass_spectra` is NULL in `go.R` #2

Closed Afraz496 closed 4 months ago

Afraz496 commented 5 months ago

The variable mass_spectra is empty. Find out why

Afraz496 commented 4 months ago

The main issue behind mass_spectra being NULL is due to the use of names(specrta). After running typeof(spectra) we see it's an S4 class in R where the variable columns need to be accessed with the @ operator.

Created some code to extract the columns but now we need to conclude which ones are of interest related to the legacy code:

 # extract MS/MS spectra
  spectra = chromPeakSpectra(dat, msLevel = 2L)

  # save all MS/MS spectra detected in this file
  spectra_df = data.frame(spectrum_name = names(spectra)) %>%
    separate(spectrum_name, into = c('chrom_peak', 'file', 'spectrum'),
             sep = "\\.", remove = FALSE) %>%
    dplyr::select(-file)

Which clearly wants:

  1. Chromatogram peak
  2. File Name
  3. Spectrum

The code currently written assumes that this is present under the rownamesof spectraData

spectra_df <- data.frame(
    spectrum_name = spectra@backend@spectraData@rownames,
    stringsAsFactors = FALSE
  )

  # Parsing the spectrum_name into potentially meaningful parts
  spectra_df <- spectra_df %>%
    separate(spectrum_name, into = c("file", "spectrum"), sep = "\\.", remove = FALSE) %>%
    mutate(
      chrom_peak = file  # Assuming 'file' part might relate to 'chrom_peak', which needs verification
    ) %>%
    select(-file)  # Optionally drop 'file' if it's redundant or not meaningful

The idea is a spectrum name like F1.S0190 gets parsed into spectrum: S0190 and chrom_peak: F1.

This in turn has created another bug in the program (which was either present before or is the direct result of the modification of the spectra data:

Error in `map()`:
ℹ In index: 1.
Caused by error in `-err_ppm / 1e+06 * theor_mass`:
! non-numeric argument to binary operator

Where the theoretical mass is no longer numeric - there seems to be a type issue.

Afraz496 commented 4 months ago

Closing this issue now as it has been concluded that the version of xcms is to blame. We need 3.3.3 and the current version of R forces >4.0