Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:param method: Method of combining (weighted or centroid). Weighted is recommended for accuracy
:param verbose: chatty mode
:return: bar isotope pattern in ``[[m/z values],[intensity values]]`` format.
:rtype: list
"""
if method not in VALID_GROUP_METHODS:
raise ValueError(f'The grouping method {method} is invalid. Choose from {", ".join(VALID_GROUP_METHODS)}')
if verbose is True:
sys.stdout.write('Generating bar isotope pattern')
if isinstance(rawip, Spectrum): # if handed a Spectrum object, trim before continuing
rawip = rawip.trim()
groupedip = group_masses(rawip, delta / 2)
out = [[], []]
for group in groupedip:
if method == 'weighted':
x, y = weighted_average(*group) # determine weighted mass and summed intensity
elif method == 'centroid':
x, y = centroid(group)
out[0].append(x)
out[1].append(y)
maxint = max(out[1])
for ind, val in enumerate(out[1]):
out[0][ind] = out[0][ind] # / abs(charge)
out[1][ind] = val / maxint * 100. # normalize to 100
if verbose is True:
sys.stdout.write(' DONE\n')
return out