bittremieux / spectrum_utils

Python package for efficient mass spectrometry data processing and visualization
https://spectrum-utils.readthedocs.io/
Apache License 2.0
140 stars 20 forks source link

non-reproducible example + annotate random ion #71

Open HijaziHassan opened 5 days ago

HijaziHassan commented 5 days ago

Hello, The example you provided in the documentation is giving an error:

https://spectrum-utils.readthedocs.io/en/latest/annotating.html

import matplotlib.pyplot as plt
import spectrum_utils.plot as sup
import spectrum_utils.spectrum as sus

# Retrieve the spectrum by its USI.
usi = "mzspec:MSV000082283:f07074:scan:5475"
spectrum = sus.MsmsSpectrum.from_usi(usi)
 ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[30], line 3
      1 # Retrieve the spectrum by its USI.
      2 usi = "mzspec:MSV000082283:f07074:scan:5475"
----> 3 spectrum = sus.MsmsSpectrum.from_usi(usi)

File [c:\Python310\lib\site-packages\spectrum_utils\spectrum.py:345](file:///C:/Python310/lib/site-packages/spectrum_utils/spectrum.py:345), in MsmsSpectrum.from_usi(cls, usi, backend, **kwargs)
    343             break
    344     else:
--> 345         raise ValueError(
    346             "Unknown precursor m/z from USI. Specify the precursor m/z"
    347             " directly."
    348         )
    349 if "precursor_charge" not in kwargs:
    350     for attr in spectrum_dict["attributes"]:

ValueError: Unknown precursor m/z from USI. Specify the precursor m/z directly.

Could you please point me at where the error is coming from?

Additionally, I want to annotate an ion with specific m/z that is not among the supported ones, could you please direct me at the suitable function to use?

bittremieux commented 5 days ago

There have been some updates to the USI backends, this is likely related to that. The fixes are currently available in the latest alpha version. Use the following command to upgrade:

pip install spectrum_utils==0.5.0a0 --upgrade

We need to do a few more tests before creating an official v0.5 release.

Additionally, I want to annotate an ion with specific m/z that is not among the supported ones, could you please direct me at the suitable function to use?

Annotating a custom peak is currently not super straightforward. You'd have to modify the annotation property of an MsmsSpectrum directly to assign a custom annotation to the matching peak and then ensure that the plotting function is able to interpret that annotation.