mass_automation.deisotoping package#

Submodules#

mass_automation.deisotoping.process module#

class mass_automation.deisotoping.process.Deisotoper(model=None)#

Bases: ABC

General class for deisotoping algorithms.

model#

The dictionary, which contains model parameters and ML model, if necessary.

Type:

dict

abstract calc_features(spectrum: Spectrum, ipeak: int, jpeak: int, labels: ndarray, count_features: int) ndarray#

Calculates features for an object, which is a pair of peaks.

Parameters:
  • spectrum (Spectrum) – The spectrum, where we select the peaks.

  • ipeak (int) – The indice of the first peak in the pair.

  • jpeak (int) – The index of the second peak in the pair

  • labels (np.ndarray) – The array of labels in the state before the features calculation.

  • count_features (int) – The number of features in the model.

Returns:

The array of calculated features.

If LinearDeisotoper:

array = [masses[ipeak], masses[jpeak]]

If MlDeisotoper:

array = [“Distance between ipeak and jpeak”,

”Number of peaks, registered before classification”, “Recent intensities belonging to the class ipeak (5 numbers)”, “Recent distances belonging to the class ipeak (3 numbers)”, “Maximal intensity of peaks labeled as ipeak to jpeak intensity relation”, “Mean intensity of peaks labeled as ipeak to jpeak intensity relation”, “Mean intensity of last 3 labeled as ipeak peaks compared to max intensity”]

Return type:

np.ndarray

find_peaks(spectrum: Spectrum) ndarray#

Peak finding implementation.

Parameters:

spectrum (Spectrum) – The spectrum, which should be processed by the peak finding algorithm.

Returns:

The array of peaks’ indices.

Return type:

np.ndarray

load(path=None, min_distance=0.01, delta=0.007)#

Loading the model.

Parameters:
  • path (str) – The path to the pkl file, which contains the model dictionary.

  • min_distance (float) – The minimal mass difference between neighbouring peaks.

  • delta (float) – The mass difference between neighbouring peaks.

abstract make_prediction(features) bool#

Performs classifier prediction.

Parameters:

features (np.ndarray) – The array of features for the pair of peaks

Returns:

If True, the peaks are in the same class, else not.

Return type:

bool

run(spectrum: Spectrum, threshold=0.5, logger=None, count_features=13, exp_coef=1) ndarray#

The deisotoping algorithm. Returns the array of labels, assigns labels to spectrum.isotopic_distributions and assigns True to spectrum.deisotoped.

Parameters:
  • spectrum (Spectrum) – The spectrum, which should be deisotoped.

  • threshold (float) – Minimal predict proba of ML algorithm. (default is 0.5)

  • logger (FeatureLogger object) – Logger for deisotoping process in spectrum

  • count_features (int) – Number of features in deisotoping model. (default is 13)

  • exp_coef – Coefficient of proportionality between delta parameter and radius of vicinity, where possible peaks can be located. (default is 1)

Returns:

The array of labels.

Return type:

np.ndarray

class mass_automation.deisotoping.process.FeatureLogger#

Bases: object

Class for checking deisotoping model predictions in spectra

features#

List containing counted features for each pair of possible peaks in spectrum.

Type:

List

targets#

List containing model answers for each pair of possible peaks in spectrum

Type:

List

dumpf(path)#

Dump feature logger dataset

Parameters:

path (str) – Path to the saved pkl-file

write(features, prediction)#

Write features and model answer for new pair of possible peaks in spectrum.

Parameters:
  • features (np.ndarray) – New pair of possible peaks features

  • prediction (np.ndarray) – New pair of possible peaks prediction

class mass_automation.deisotoping.process.LinearDeisotoper(model=None)#

Bases: Deisotoper

calc_features(spectrum: Spectrum, ipeak: int, jpeak: int, labels: Optional[ndarray] = None, count_features=13) ndarray#

Calculates features for an object, which is a pair of peaks.

Parameters:
  • spectrum (Spectrum) – The spectrum, where we select the peaks.

  • ipeak (int) – The indice of the first peak in the pair.

  • jpeak (int) – The index of the second peak in the pair

  • labels (np.ndarray) – The array of labels in the state before the features calculation.

  • count_features (int) – The number of features in the model.

Returns:

The array of calculated features.

If LinearDeisotoper:

array = [masses[ipeak], masses[jpeak]]

If MlDeisotoper:

array = [“Distance between ipeak and jpeak”,

”Number of peaks, registered before classification”, “Recent intensities belonging to the class ipeak (5 numbers)”, “Recent distances belonging to the class ipeak (3 numbers)”, “Maximal intensity of peaks labeled as ipeak to jpeak intensity relation”, “Mean intensity of peaks labeled as ipeak to jpeak intensity relation”, “Mean intensity of last 3 labeled as ipeak peaks compared to max intensity”]

Return type:

np.ndarray

make_prediction(features: ndarray) bool#

Performs classifier prediction.

Parameters:

features (np.ndarray) – The array of features for the pair of peaks

Returns:

If True, the peaks are in the same class, else not.

Return type:

bool

class mass_automation.deisotoping.process.MlDeisotoper(model=None)#

Bases: Deisotoper

calc_features(spectrum: Spectrum, ipeak: int, jpeak: int, labels: ndarray, count_features=13) ndarray#

Calculates features for an object, which is a pair of peaks.

Parameters:
  • spectrum (Spectrum) – The spectrum, where we select the peaks.

  • ipeak (int) – The indice of the first peak in the pair.

  • jpeak (int) – The index of the second peak in the pair

  • labels (np.ndarray) – The array of labels in the state before the features calculation.

  • count_features (int) – The number of features in the model.

Returns:

The array of calculated features.

If LinearDeisotoper:

array = [masses[ipeak], masses[jpeak]]

If MlDeisotoper:

array = [“Distance between ipeak and jpeak”,

”Number of peaks, registered before classification”, “Recent intensities belonging to the class ipeak (5 numbers)”, “Recent distances belonging to the class ipeak (3 numbers)”, “Maximal intensity of peaks labeled as ipeak to jpeak intensity relation”, “Mean intensity of peaks labeled as ipeak to jpeak intensity relation”, “Mean intensity of last 3 labeled as ipeak peaks compared to max intensity”]

Return type:

np.ndarray

make_prediction(features: ndarray) bool#

Performs classifier prediction.

Parameters:

features (np.ndarray) – The array of features for the pair of peaks

Returns:

If True, the peaks are in the same class, else not.

Return type:

bool

mass_automation.deisotoping.process.find_spec_peaks(spectrum: Spectrum, min_distance: float, algorithm='std', verbose=False, alpha=None, threshold=None)#

Peak finding algorithm

Parameters:
  • spectrum (Spectrum) – The spectrum, where peaks are searched.

  • min_distance (float) – Required minimal mass difference between neighbouring peaks.

  • algorithm ({‘std’, ‘hist’, ‘quantile’, 'manual'}, default=’std’) – If ‘std’, minimal intensity is set as spectra ints median + double standard deviation. If ‘hist’, minimal intensity peak threshold is set as the first bin edge in spectra of intensities. If ‘quantile’, minimal intensity is set as parameter alpha quantile. If None, minimal intensity is set manually.

  • verbose (bool) – If True, show TQDM bars.

  • alpha (float) – Argument in quantile function. Used in ‘quantile’ algorithm.

  • threshold (float) – Minimal peak intensity threshold value in ‘manual’ algorithm.

Returns:

List with three arrays (peak masses, peak intensities, peak labels)

Return type:

List[np.array, np.array, np.array]

Module contents#