Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
x: list of x values
y: list of y values (paired with x)
returns: integral
"""
if start > max(x) or start < min(x): # check that start is within the m/z bounds
self._BE.warn(name, start, end, min(x), max(x))
if end is None: # if only a start value is supplied, return closest to that value
try: # try to find the value in the list
return y[locate_in_list(x, start)]
except TypeError: # if the value is not in the list, return 0
return 0
if end > max(x): # check that end is within the m/z bounds
self._BE.warn(name, start, end, min(x), max(x))
else:
l = locate_in_list(x, start, 'greater')
r = locate_in_list(x, end, 'lesser')
if l <= r:
return sum(y[l:r])
else: # catch for if there are no values in the bounds
return 0
y: list of y values (paired with x)
returns: integral
"""
if start > max(x) or start < min(x): # check that start is within the m/z bounds
self._BE.warn(name, start, end, min(x), max(x))
if end is None: # if only a start value is supplied, return closest to that value
try: # try to find the value in the list
return y[locate_in_list(x, start)]
except TypeError: # if the value is not in the list, return 0
return 0
if end > max(x): # check that end is within the m/z bounds
self._BE.warn(name, start, end, min(x), max(x))
else:
l = locate_in_list(x, start, 'greater')
r = locate_in_list(x, end, 'lesser')
if l <= r:
return sum(y[l:r])
else: # catch for if there are no values in the bounds
return 0
name: name of the peak being integrated (only used for warning purposes)
start: float
start x value
end: float or None
end x value
None will return the nearest value to the provided start value
x: list of x values
y: list of y values (paired with x)
returns: integral
"""
if start > max(x) or start < min(x): # check that start is within the m/z bounds
self._BE.warn(name, start, end, min(x), max(x))
if end is None: # if only a start value is supplied, return closest to that value
try: # try to find the value in the list
return y[locate_in_list(x, start)]
except TypeError: # if the value is not in the list, return 0
return 0
if end > max(x): # check that end is within the m/z bounds
self._BE.warn(name, start, end, min(x), max(x))
else:
l = locate_in_list(x, start, 'greater')
r = locate_in_list(x, end, 'lesser')
if l <= r:
return sum(y[l:r])
else: # catch for if there are no values in the bounds
return 0
:param str bias: Bias of index finding (options dictacted by locate_in_list() )
:return: scan index
:rtype: int
"""
if function not in self.functions:
raise KeyError('The function %d is not in this mzML file.' % function)
if scan is None: # if no scan number is specified
if bias == 'greater': # used for start point
return self.functions[function]['sr'][0]
if bias == 'lesser': # used for end point
return self.functions[function]['sr'][1]
if type(scan) is float: # timepoint
if self.ftt is False:
self.function_timetic()
# return located index plus start of the scan range
return locate_in_list(self.functions[function]['timepoints'], scan, bias=bias) + self.functions[function]['sr'][0]
elif type(scan) is int: # scan number
if scan < 1:
raise ValueError('The scan number must be greater or equal to 1 (specified: %d)' % scan)
if scan > self.functions[function]['nscans']:
raise ValueError(f'The scan number {scan} exceeds the number of scans in function {function} '
f'({self.functions[function]["nscans"]})')
# return scan minus 1 (to shift into index domain) plus the start location index
return scan - 1 + self.functions[function]['sr'][0]
else:
raise ValueError(f'An unexpected scan type was handed to the scan_index function ("{scan}", '
f'type: {type(scan)})')