Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Calculate precursor mass and mz for given peptide and modification list,
using Pyteomics.
peptide: stripped peptide sequence
modifications: MS2PIP-style formatted modifications list (e.g.
`0|Acetyl|2|Oxidation`)
mass_shifts: dictionary with `modification_name -> mass_shift` pairs
Returns: tuple(prec_mass, prec_mz)
Note: This method does not use the build-in Pyteomics modification handling, as
that would require a known atomic composition of the modification.
"""
charge = int(charge)
unmodified_mass = mass.fast_mass(peptide)
mods_massses = sum([mass_shifts[mod] for mod in modifications.split('|')[1::2]])
prec_mass = unmodified_mass + mods_massses
prec_mz = (prec_mass + charge * PROTON_MASS) / charge
return prec_mass, prec_mz