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

"cannot compute fingerprint of empty list" with singly charged precursor #11

Closed levitsky closed 4 years ago

levitsky commented 4 years ago

Hi and thank you for the great package!

First time using it and it seems to have a problem annotating one of my spectra where the precursor charge is 1.

Code causing the problem: s.annotate_peptide_fragments(0.5, 'Da', ion_types='aby') (copied from docs) Error:

ValueError                                Traceback (most recent call last)
<ipython-input-143-823c7e798d31> in <module>
----> 1 s.annotate_peptide_fragments(0.5, 'Da', ion_types='aby',)

/usr/lib/python3.8/site-packages/spectrum_utils/spectrum.py in annotate_peptide_fragments(self, fragment_tol_mass, fragment_tol_mode, ion_types, max_ion_charge, peak_assignment)
   1049             warnings.simplefilter('ignore', nb.NumbaPendingDeprecationWarning)
   1050             for annotation_i, fragment_i in\
-> 1051                     _get_peptide_fragment_annotation_map(
   1052                         self.mz, self.intensity,
   1053                         [fragment.calc_mz for fragment

ValueError: cannot compute fingerprint of empty list

The error goes away if I specify max_ion_charge=1. Perhaps it makes sense to make the default value be 1 if the precursor charge is 1.

The spectrum is:

{'identifier': 'MVQALSLGGG',
 'precursor_mz': 932.48697878668,
 'precursor_charge': 1,
 '_mz': array([190.08223, 231.11618, 303.1663 , 359.17474, 390.19833, 430.21185,
        503.28238, 543.29596, 574.3195 , 630.32794, 702.37805, 743.41205,
        800.4335 , 857.45496], dtype=float32),
 '_intensity': array([0.20990807, 0.28059167, 0.16901207, 0.6857932 , 0.2795136 ,
        1.        , 0.34787884, 0.676259  , 0.25297335, 0.6218561 ,
        0.23610453, 0.33881018, 0.3910684 , 0.22612093], dtype=float32),
 '_annotation': array([None, None, None, None, None, None, None, None, None, None, None,
        None, None, None], dtype=object),
 'retention_time': 78.90333557128906,
 'peptide': 'MVQALSLGGG',
 'modifications': {},
 'is_decoy': False}

Best regards, Lev

bittremieux commented 4 years ago

Thanks Lev. I'm much indebted to Pyteomics, I always use it together with spectrum_utils.

The problem was that if max_ion_charge isn't set, by default all fragments with a charge up to the precursor minus one are annotated (as detailed in the docstring). However, when the charge is 1, the minus one would result in 0, leading to the error. I've updated it now so that the minimum charge considered is 1.

The bugfix is available in spectrum_utils version 0.3.4 from pip, and will be available from Bioconda shortly as well.