Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
mods = {}
ions = []
for i in range(1, len(peptide)):
for ion_type in types:
if ion_type in 'abc': # N-terminal fragment.
ion_index = i
sequence = peptide[:i]
mod_mass = sum([md for pos, md in mods.items() if pos < i])
else: # C-terminal fragment.
ion_index = len(peptide) - i
sequence = peptide[i:]
mod_mass = sum([md for pos, md in mods.items() if pos >= i])
for charge in range(1, max_charge + 1):
ions.append(PeptideFragmentAnnotation(
charge, mass.fast_mass(
sequence=sequence, ion_type=ion_type,
charge=charge, aa_mass=_aa_mass) + mod_mass / charge,
ion_type, ion_index))
return sorted(ions, key=operator.attrgetter('calc_mz'))