MZTrafoModel#
- class pyopenms.MZTrafoModel#
Bases:
objectCreate and apply models of a mass recalibration function
The input is a list of calibration points (ideally spanning a wide m/z range to prevent extrapolation when applying to model)
Models (LINEAR, LINEAR_WEIGHTED, QUADRATIC, QUADRATIC_WEIGHTED) can be trained using CalData points (or a subset of them) Calibration points can have different retention time points, and a model should be build such that it captures the local (in time) decalibration of the instrument, i.e. choose appropriate time windows along RT to calibrate the spectra in this RT region From the available calibrant data, a model is build. Later, any uncalibrated m/z value can be fed to the model, to obtain a calibrated m/z
The input domain can either be absolute mass differences in [Th], or relative differences in [ppm] The models are build based on this input
Outlier detection before model building via the RANSAC algorithm is supported for LINEAR and QUADRATIC models
- __init__() None#
- __init__(arg: bool, /) None
- __init__(arg: pyopenms.MZTrafoModel, /) None
Methods
__init__()enumToName(mt)findNearest(tms, rt)Find the model nearest to the given RT
Get model coefficients
getRT()Get RT associated with the model (training region)
Returns true if the model have coefficients (i.e. was trained successfully).
isValidModel(trafo)nameToEnum(name)predict(mz)Apply the model to an uncalibrated m/z value
setCoefficientLimits(offset, scale, power)setCoefficients(rhs)Overloaded function.
setRANSACSeed(seed)toString()train(cd, md, use_RANSAC[, rt_left, rt_right])Overloaded function.
- class MODELTYPE(*values)#
Bases:
EnumModel type for m/z calibration transformation
- LINEAR = 0#
- LINEAR_WEIGHTED = 1#
- QUADRATIC = 2#
- QUADRATIC_WEIGHTED = 3#
- SIZE_OF_MODELTYPE = 4#
- getMapping()#
Returns a dict mapping int values to enum member name strings.
- static enumToName(mt: pyopenms.MZTrafoModel.MODELTYPE) str#
- static findNearest(tms: collections.abc.Sequence[pyopenms.MZTrafoModel], rt: float) int#
Find the model nearest to the given RT
- getCoefficients() tuple#
Get model coefficients
The model must be trained before; Exception is thrown otherwise!
- Returns:
Tuple of (intercept, slope, power); power is the coefficient for x*x (0 for linear models)
- getRT() float#
Get RT associated with the model (training region)
- isTrained() bool#
Returns true if the model have coefficients (i.e. was trained successfully)
- static isValidModel(trafo: pyopenms.MZTrafoModel) bool#
- static nameToEnum(name: str) pyopenms.MZTrafoModel.MODELTYPE#
- predict(mz: float) float#
Apply the model to an uncalibrated m/z value
Make sure the model was trained (train()) and is valid (isValidModel()) before calling this function!
Applies the function y = intercept + slope*mz + power*mz^2 and returns y
- Parameters:
mz – The uncalibrated m/z value
- Returns:
The calibrated m/z value
- static setCoefficientLimits(offset: float, scale: float, power: float) None#
- setCoefficients(rhs: pyopenms.MZTrafoModel) None#
- setCoefficients(intercept: float, slope: float, power: float) None
Overloaded function.
setCoefficients(rhs: pyopenms.MZTrafoModel) -> None
Copy model coefficients from another model
setCoefficients(intercept: float, slope: float, power: float) -> None
Manually set model coefficients
Can be used instead of train(), so manually set coefficients It must be exactly three values. If you want a linear model, set ‘power’ to zero If you want a constant model, set slope to zero in addition
- Parameters:
intercept – The offset
slope – The slope
power – The x*x coefficient (for quadratic models)
- static setRANSACParams(p: pyopenms.RANSACParam) None#
- static setRANSACSeed(seed: int) None#
- toString() str#
- train(cd: pyopenms.CalibrationData, md: pyopenms.MZTrafoModel.MODELTYPE, use_RANSAC: bool, rt_left: float = -1.7976931348623157e+308, rt_right: float = 1.7976931348623157e+308) bool#
- train(error_mz: collections.abc.Sequence[float], theo_mz: collections.abc.Sequence[float], weights: collections.abc.Sequence[float], md: pyopenms.MZTrafoModel.MODELTYPE, use_RANSAC: bool) bool
Overloaded function.
train(cd: pyopenms.CalibrationData, md: pyopenms.MZTrafoModel.MODELTYPE, use_RANSAC: bool, rt_left: float = -1.7976931348623157e+308, rt_right: float = 1.7976931348623157e+308) -> bool
Train a model using calibrant data
If the CalibrationData was created using peak groups (usually corresponding to mass traces), the median for each group is used as a group representative. This is more robust, and reduces the number of data points drastically, i.e. one value per group
Internally, these steps take place:
apply RT filter
[compute median per group] (only if groups were given in ‘cd’)
set Model’s rt position
call train() (see overloaded method)
- Parameters:
cd – List of calibrants
md – Type of model (linear, quadratic, …)
use_RANSAC – Remove outliers before computing the model?
rt_left – Filter ‘cd’ by RT; all calibrants with RT < ‘rt_left’ are removed
rt_right – Filter ‘cd’ by RT; all calibrants with RT > ‘rt_right’ are removed
- Returns:
True if model was build, false otherwise
train(error_mz: collections.abc.Sequence[float], theo_mz: collections.abc.Sequence[float], weights: collections.abc.Sequence[float], md: pyopenms.MZTrafoModel.MODELTYPE, use_RANSAC: bool) -> bool
Train a model using calibrant data
Given theoretical and observed mass values (and corresponding weights), a model (linear, quadratic, …) is build Outlier removal is applied before The ‘obs_mz’ can be either given as absolute masses in [Th] or relative deviations in [ppm] The MZTrafoModel must be constructed accordingly (see constructor). This has no influence on the model building itself, but rather on how ‘predict()’ works internally
Outlier detection before model building via the RANSAC algorithm is supported for LINEAR and QUADRATIC models
Internally, these steps take place:
[apply RANSAC] (depending on ‘use_RANSAC’)
build model and store its parameters internally
- Parameters:
error_mz – Observed Mass error (in ppm or Th)
theo_mz – Theoretical m/z values, corresponding to ‘error_mz’
weights – For weighted models only: weight of calibrants; ignored otherwise
md – Type of model (linear, quadratic, …)
use_RANSAC – Remove outliers before computing the model?
- Returns:
True if model was build, false otherwise