Skip to content

Commit

Permalink
Make sure charge isn't 0 during peak annotation
Browse files Browse the repository at this point in the history
Fixes #11.
  • Loading branch information
bittremieux committed Jul 2, 2020
1 parent 0ab2989 commit 7ecb4d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spectrum_utils/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ def annotate_peptide_fragments(self, fragment_tol_mass: float,
if self.peptide is None:
raise ValueError('No peptide sequence available for the spectrum')
if max_ion_charge is None:
max_ion_charge = self.precursor_charge - 1
max_ion_charge = max(1, self.precursor_charge - 1)

theoretical_fragments = _get_theoretical_peptide_fragments(
self.peptide, self.modifications, ion_types, max_ion_charge)
Expand Down
5 changes: 2 additions & 3 deletions spectrum_utils/tests/spectrum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,18 +646,17 @@ def test_annotate_peptide_fragments():
fragment_tol_mode = 'Da'
peptides = ['SYELPDGQVITIGNER', 'MFLSFPTTK', 'DLYANTVLSGGTTMYPGIADR',
'YLYEIAR', 'VAPEEHPVLLTEAPLNPK']
for peptide in peptides:
for charge, peptide in enumerate(peptides, 1):
fragment_mz = np.asarray([fragment.calc_mz for fragment in
spectrum._get_theoretical_peptide_fragments(
peptide)])
peptide, max_charge=charge - 1)])
fragment_mz += np.random.uniform(
-0.9 * fragment_tol_mass, 0.9 * fragment_tol_mass,
len(fragment_mz))
num_peaks = 150
mz = np.random.uniform(100, 1400, num_peaks)
mz[: len(fragment_mz)] = fragment_mz
intensity = np.random.lognormal(0, 1, num_peaks)
charge = 2
spec = spectrum.MsmsSpectrum(
'test_spectrum', mass.calculate_mass(sequence=peptide,
charge=charge),
Expand Down

0 comments on commit 7ecb4d0

Please sign in to comment.