MZTrafoModel#
- class pyopenms.MZTrafoModel#
Bases:
object
Cython implementation of _MZTrafoModel
Original C++ documentation is available here
Create 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__()#
Overload:
- __init__(self) None
Overload:
- __init__(self, in_0: MZTrafoModel) None
Overload:
- __init__(self, in_0: bool) None
Methods
Overload:
__static_MZTrafoModel_enumToName(mt: int ) -> bytes
__static_MZTrafoModel_findNearest(tms: List[MZTrafoModel] , rt: float ) -> int
getCoefficients
(self, intercept, slope, power)Get model coefficients
getRT
(self)Get RT associated with the model (training region)
isTrained
(self)Returns true if the model have coefficients (i.e.
__static_MZTrafoModel_isValidModel(trafo: MZTrafoModel ) -> bool
__static_MZTrafoModel_nameToEnum(name: bytes ) -> int
predict
(self, mz)Apply the model to an uncalibrated m/z value
__static_MZTrafoModel_setCoefficientLimits(offset: float , scale: float , power: float ) -> None
Overload:
__static_MZTrafoModel_setRANSACParams(p: RANSACParam ) -> None
toString
(self)Overload:
- enumToName()#
__static_MZTrafoModel_enumToName(mt: int ) -> bytes
- findNearest()#
__static_MZTrafoModel_findNearest(tms: List[MZTrafoModel] , rt: float ) -> int
- getCoefficients(self, intercept: float, slope: float, power: float) None #
Get model coefficients
Parameters will be filled with internal model parameters The model must be trained before; Exception is thrown otherwise!
- Parameters:
intercept – The intercept
slope – The slope
power – The coefficient for x*x (will be 0 for linear models)
- getRT(self) float #
Get RT associated with the model (training region)
- isTrained(self) bool #
Returns true if the model have coefficients (i.e. was trained successfully)
- isValidModel()#
__static_MZTrafoModel_isValidModel(trafo: MZTrafoModel ) -> bool
- nameToEnum()#
__static_MZTrafoModel_nameToEnum(name: bytes ) -> int
- predict(self, 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
- setCoefficientLimits()#
__static_MZTrafoModel_setCoefficientLimits(offset: float , scale: float , power: float ) -> None
- setCoefficients()#
Overload:
- setCoefficients(self, in_0: MZTrafoModel) None
Copy model coefficients from another model
Overload:
- setCoefficients(self, in_0: float, in_1: float, in_2: 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)
- setRANSACParams()#
__static_MZTrafoModel_setRANSACParams(p: RANSACParam ) -> None
- train()#
Overload:
- train(self, cd: CalibrationData, md: int, use_RANSAC: bool, rt_left: float, rt_right: float) 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
Overload:
- train(self, error_mz: List[float], theo_mz: List[float], weights: List[float], md: int, 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