Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concatenateSpectra Error #10

Open
gmhhope opened this issue Jun 3, 2021 · 1 comment
Open

concatenateSpectra Error #10

gmhhope opened this issue Jun 3, 2021 · 1 comment

Comments

@gmhhope
Copy link

gmhhope commented Jun 3, 2021

I am trying to merge spectra objects based on the function concatenateSpectra you used in this session: https://bioconductor.org/packages/devel/bioc/vignettes/Spectra/inst/doc/Spectra.html#33_Filtering,_subsetting_and_merging

Background

  • I have performed filterMz and subset the original MS2 spectra (derived from several files of MS2 run) based on the precursor Mz.
  • Then I did several processings including the removal of small peaks.
> sps_final_l_noNull[[1]]
MSn data (Spectra) with 1 spectra in a MsBackendMzR backend:
    msLevel     rtime scanIndex
  <integer> <numeric> <integer>
1         2   195.912      2100
 ... 39 more variables/columns.

file(s):
ID_01.mzML
Lazy evaluation queue: 2 processing step(s)
Processing:
 Filter: select spectra with a precursor m/z within [348.06886830525, 348.070260583508] [Thu Jun  3 15:23:47 2021]
 Filter: select retention time [-202.776397705078..400.525695800781] on MS level(s) 2 [Thu Jun  3 15:23:47 2021]
 Remove peaks based on their intensities and a user-provided function in spectra of MS level(s) 2. [Thu Jun  3 15:24:39 2021] 
  • And then I match the spectra with hmdb/massbank, filtering by score > 0.7.
  • It results in a list of annotated spectra objects.
  • Now I want to merge the list of spectra back together as a single spectra object and export them as a data frame.

Error by running concatenateSpectra

# `sps_final_l_noNull` is a list of spectra objects that were matched with massbank or hmdb spectra.

sps_final <- NULL
for (i in (1:length(sps_final_l_noNull))) { 
  print(i)
  if (i == 1) {
    sps_final <- sps_final_l_noNull[[i]]
    
  }
  else {
    sps_final <- concatenateSpectra(sps_final,sps_final_l_noNull[[i]])
  }
  
}
  • Here it is the error message:
Error in .concatenate_spectra(unlist(unname(list(unname(x), ...)))) : Can not concatenate 'Spectra' objects with non-empty processing queue. Consider calling 'applyProcessing' before.
  • Then I try to test the suggestion by applyProcessing to the object:
length(sps_final_l_noNull[[1]]@processingQueue)
sps_final_l_noNull[[1]] <- applyProcessing(sps_final_l_noNull[[1]])
length(sps_rep@processingQueue)
  • I got the following error:
[1] 2
Error in applyProcessing(sps_final_l_noNull[[1]]) : MsBackendMzR is read-only. 'applyProcessing' works only with backends that support writing data.

Could you help me figure out what is going wrong?

Thanks very much!

Best regards,
Minghao Gong

@jorainer
Copy link
Owner

jorainer commented Jun 7, 2021

Spectra that use a MsBackendMzR for data storage are considered read-only because they read the m/z and intensity data on demand from the mzML files (same as the on-disk mode we had in MSnbase, maybe also have a look here to understand the difference). All data subsetting and manipulation operation work on them but these operations are not directly applied to the data because we don't want to change the original data in the mzML files. All operations are thus cached in the lazy processing queue and applied to the data on demand (i.e. whenever you access mz or intensity values with intensity(), mz() or $intensity and $mz. Thus, if you use this backend you can also not use the applyProcessing function (because we can not (and don't want to) modify the data in the mzML file).

The solution to this would be to switch to an in-memory backend which causes the data from the mzML file to be loaded into memory. In that case you can apply any processing steps. This can be done with sps <- setBackend(sps, MsBackendDataFrame()). In your case the following should work:

sps_final_l_noNull <- lapply(sps_final_l_noNull, function(z) {
    z <- setBackend(z, MsBackendDataFrame())
    applyProcessing(z)
})
sps_final <- concatenateSpectra(unname(sps_final_l_noNull))

Note that you could switch backends also earlier - having the data in memory (as with the MsBackendDataFrame) can speed-up some operations. The advantage of the MsBackendMzR is mostly to keep the memory footprint low and hence allowing also to analyze very big data sets on "conventional" computer infrastructure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants