pyMSpec.pyisocalc package

Submodules

pyMSpec.pyisocalc.periodic_table module

pyMSpec.pyisocalc.pyisocalc module

class pyMSpec.pyisocalc.pyisocalc.Element(id)[source]

Bases: object

An element from the periodic table.

average_mass()[source]

Return the average mass of this element, that is the dot product of its masses and ratios. :rtype: float

charge()[source]

Return the atomic charge of this element. :rtype: int

mass_ratios()[source]

Return the probability of each isotope, ordered by the isotope’s atomic mass. :rtype: sequence

masses()[source]

Return the masses of all possible isotopes in ascending order.

Return type:sequence
name()[source]

Return the element symbol as a string.

number()[source]

Return the atomic number of this element in the periodic table. :rtype: int

class pyMSpec.pyisocalc.pyisocalc.FormulaSegment(element, amount)[source]

Bases: object

A segment from an expanded molecular sum formula.

A segment is a single element together with its number of occurrences within a molecule. For example, the molecule ‘H20’ would consist of the segments (‘H’, 2) and (‘O’, 1).

amount()[source]

Return the amount of the element.

average_mass()[source]

The element’s average mass multiplied by its amount.

charge()[source]

The element’s charge multiplied by its amount.

element()[source]

Return the chemical element.

class pyMSpec.pyisocalc.pyisocalc.SumFormula(segments)[source]

Bases: object

A molecular sum formula, built up from FormulaSegments. Use parseSumFormula to parse your string representation into a SumFormula object.

To get the expanded string representation of this object, use str().

average_mass()[source]

The sum of the average masses of its segments. :rtype: float

charge()[source]

The sum of the charges of its segments. :rtype: int

get_segments()[source]

Return the sequence of segments of which this sum formula consists. :rtype: tuple

pyMSpec.pyisocalc.pyisocalc.apply_gaussian(ms_input, sigma, pts_per_mz=10, exact=True)[source]

Smooth every peak into a gaussian shape using instrument-specific configuration.

Parameters:
  • ms_input (MassSpectrum) – the mass spectrum
  • sigma – sigma parameter for Gaussian. See fwhm_to_sigma
  • pts_per_mz (int) – Number of points per one mz unit for the regular grid
  • exact – if False, this function may use an approximate implementation
Returns:

a new mass spectrum containing the smoothed data in both profile and centroid mode

pyMSpec.pyisocalc.pyisocalc.cartesian(rx, mx, threshold=0.0001)[source]
pyMSpec.pyisocalc.pyisocalc.cartesian(rx, mx, threshold)[source]

Combine multiple isotope patterns into a single one.

Parameters:
  • rx (Sequence[ndarray]) – Sequence of ratio arrays
  • mx (Sequence[ndarray]) – Sequence of mass arrays
  • threshold – threshold below which the resulting ratios are filtered out
Returns:

The resulting ratio array and the mass array

Return type:

Tuple[ndarray]

pyMSpec.pyisocalc.pyisocalc.complete_isodist(sf, sigma=0.001, cutoff_perc=0.1, charge=None, pts_per_mz=10000, centroid_func=<function gradient>, centroid_kwargs=None)[source]

Wrapper function for applying perfect_pattern, then gen_gaussian and eventually centroid detection.

Parameters:
  • sf – the sum formula
  • sigma (float) – Full width at half maximum
  • cutoff_perc (float) – min percentage of the maximum intensity to return, max value = 100
  • charge (int) – charge of the molecule
  • pts_per_mz – Number of points per mz for the regular grid
  • centroid_func – the centroid function to apply to the isotope pattern or None if no centroid detection

should be performed. Must have the same signature as centroid_detection.gradient. :param centroid_kwargs: dict to pass to centroid_func as optional parameters :return:

pyMSpec.pyisocalc.pyisocalc.fwhm_to_sigma(min_x, max_x, fwhm)[source]

When fitting an isotope pattern to a gaussian distribution, this function calculates the standard deviation sigma for the gaussian distribution.

Parameters:
  • min_x – the lowest m/z value
  • max_x – the highest m/z value
  • fwhm – the full width at half maximum
Returns:

Sigma

Return type:

float

Throws ValueError:
 

if min_x > max_x or if not all inputs are greater than 0

pyMSpec.pyisocalc.pyisocalc.gen_approx_gaussian(ms, sigma, pts, n=20)[source]

Approximate and faster version of gen_gaussian

Parameters:ms – the isotope pattern as a MassSpectrum object
Returns:the smoothed pattern
Return type:Tuple[ndarray]
Throws ValueError:
 if sigma or pts are not greater than 0
Throws TypeError:
 if pts is not an integer
pyMSpec.pyisocalc.pyisocalc.gen_gaussian(ms, sigma, pts)[source]

Transform each peak in an isotope pattern into a gaussian curve.

Each of the curves is scaled up to the intensity value for the corresponding m/z. The output will be on a regular grid with pts points, starting from min_mz - 1, up to max_mz + 1, where min_mz is the lowest m/z value and max_mz is the highest m/z value. Since each curve is rendered on the same grid, overlapping curves will add up.

Parameters:ms – the isotope pattern as a MassSpectrum object
Returns:the smoothed pattern
Return type:Tuple[ndarray]
Throws ValueError:
 if sigma or pts are not greater than 0
Throws TypeError:
 if pts is not an integer
pyMSpec.pyisocalc.pyisocalc.normalize(m, n, charges, cutoff)[source]
pyMSpec.pyisocalc.pyisocalc.parseSumFormula(string)[source]

Parses string representation of a sum formula into a list of FormulaSegments

pyMSpec.pyisocalc.pyisocalc.perfect_pattern(sf, cutoff_perc=0.1, single_pattern_func=<function single_pattern_fft>, charge=None)[source]

Compute the isotope pattern of a molecule given by its sum formula.

First applies single_pattern_func to each segment within the sum formula, then combines these individual patterns into a single one.

Parameters:
  • sf (SumFormula) – the sum formula
  • cutoff_perc (float) – min percentage of the maximum intensity to return, max value = 100
  • single_pattern_func – the function to compute a single isotope pattern. Must have the same signature as

single_pattern_fft :param charge: charge of the molecule :type charge: int :return: the combined isotope pattern as a mass spectrum :rtype: MassSpectrum

pyMSpec.pyisocalc.pyisocalc.single_pattern_fft(segment, threshold=1e-09)[source]
pyMSpec.pyisocalc.pyisocalc.single_pattern_fft(segment[, threshold=1e-9])[source]

Calculates the isotope pattern of a single FormulaSegment using multidimensional fast fourier transform.

See ‘Efficient Calculation of Exact Fine Structure Isotope Patterns via the Multidimensional Fourier Transform’ (A. Ipsen, 2014).

Parameters:threshold (float) – Only intensities above this threshold will be part of the result. Must be a non-negative number
Returns:the isotopic pattern as a MassSpectrum
Return type:MassSpectrum
pyMSpec.pyisocalc.pyisocalc.total_points(min_x, max_x, points_per_mz)[source]

Calculate the number of points for the regular grid based on the full width at half maximum.

Parameters:
  • min_x – the lowest m/z value
  • max_x – the highest m/z value
  • points_per_mz – number of points per fwhm
Returns:

total number of points

Return type:

int

pyMSpec.pyisocalc.pyisocalc.trim(y, x)[source]
pyMSpec.pyisocalc.pyisocalc.trim(y, x)[source]

Remove duplicate elements in the second array and sum the duplicate values in the first one. This function returns an array containing the unique values from y and an array containing the values from x where its elements at the indexes of the duplicate elements in y have been summed.

Example:

>>> trim([5, 1, 2, 5], [1, 2, 2, 3])
(array([ 5.,  3.,  5.]), array([1, 2, 3]))
Parameters:
  • y (Union[ndarray, Iterable]) – the array from which the values are summed
  • x (Union[ndarray, Iterable]) – the array from which the duplicates are removed
Returns:

the trimmed y array and the trimmed x array

Return type:

Tuple[ndarray]

pyMSpec.pyisocalc.tools module

pyMSpec.pyisocalc.tools.make_sf_adduct_database(sum_formulae, adducts, output_filename, sigma=0.001, resolution=10000, charge=1)[source]
pyMSpec.pyisocalc.tools.make_sf_adduct_optimusfilter(sum_formulae, adducts, output_filename, sigma=0.001, resolution=10000, charge=1)[source]
pyMSpec.pyisocalc.tools.normalise_sf(sf_string)[source]

Module contents