rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
34 stars 24 forks source link

Plotting fails with empty spectra #175

Closed ococrook closed 3 years ago

ococrook commented 3 years ago

Sometime it reasonable to try to plot an empty spectra - for large pipelines where we are searching for potential peptide and the expected peptide happens to be missing.

However, a number of the plotting functions fail when trying to plot empty spectra (unsuprinsgly), but its not that elegent.

mySpectra) <- filterIntensity(mySpectra, c(0,1))  #generate empty spectra
plotSpectra(mySpectra)
Error in plot.window(xlim = xlim, ylim = ylim) : 
  need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In max(abs(ints), na.rm = TRUE) :
  no non-missing arguments to max; returning -Inf

The problem is that max of an empty or NULL is -Inf which leads to nonsense xlim or ylim values. I would suggest including a 0 in the max when setting xlim and ylim to avoid the issue or checking if the spectra is empty and return an empty plot?

jorainer commented 3 years ago

Sorry for my late reply. Indeed a good point. I will fix ASAP.

jorainer commented 3 years ago

It's implemented. Now you plotSpectra and plotSpectraMirror no longer fails when called on an empty spectrum.

Feel free to re-open if this did not fix your problem.

ococrook commented 3 years ago

cheers, I'll double check it work for me