| <large>libXpertMassCore and libXpertMassGui Developer Documentation</large>

- libXpertMassCore
- IsotopicClusterGenerator

# MsXpS::libXpertMassCore::IsotopicClusterGenerator Class

class MsXpS::libXpertMassCore::IsotopicClusterGenerator

The IsotopicClusterGenerator class provides the features needed to model isotopic clusters starting from (elemental-composition, charge) pairs. Neutral analytes can have their isotopic cluster modelle by setting the charge to 0. More...

Header: | `#include <MsXpS/libXpertMassCore/IsotopicClusterGenerator.hpp>`
Inherits: | QObject

- List of all members, including inherited members
- IsotopicClusterGenerator is part of libXpertMassCore Mass calculations.

## Public Functions

| IsotopicClusterGenerator(QObject *parent = nullptr)
| IsotopicClusterGenerator(MsXpS::libXpertMassCore::IsotopicDataSPtr isotopic_data_sp, QObject *parent = nullptr)
virtual | ~IsotopicClusterGenerator()
void | appendFormulaChargePair(MsXpS::libXpertMassCore::FormulaChargePair &formula_charge_pair)
QString | clusterToString(const pappso::TraceCstSPtr &isotopic_cluster_sp) const
QString | clustersToString() const
bool | configureIsotopicData(std::map<QString, int> &symbol_count_map, int *&per_element_isotopes_count_array_p, int *&per_element_symbol_count_array_p, double **&per_element_isotope_masses_arrays_p_p, double **&per_element_isotope_probs_arrays_p_p)
MsXpS::libXpertMassCore::IsotopicClusterChargePair | generateIsotopicClusterCentroids(MsXpS::libXpertMassCore::FormulaChargePair formula_charge_pair)
const std::vector<MsXpS::libXpertMassCore::IsotopicClusterChargePair> & | getIsotopicClusterChargePairs() const
MsXpS::libXpertMassCore::IsotopicDataSPtr | getIsotopicData() const
std::size_t | run()
pappso::TraceSPtr | runIsotopicDataCalculations(std::size_t element_count, int charge, int *per_element_isotopes_count_array_p, int *per_element_symbol_count_array_p, double **per_element_isotope_masses_arrays_p_p, double **per_element_isotope_probs_arrays_p_p)
void | setFormulaChargePair(MsXpS::libXpertMassCore::FormulaChargePair &formula_charge_pair)
void | setFormulaChargePairs(const std::vector<MsXpS::libXpertMassCore::FormulaChargePair> &formula_charge_pairs)
void | setIsotopicData(MsXpS::libXpertMassCore::IsotopicDataSPtr isotopic_data_sp)
void | setIsotopicDataType(MsXpS::libXpertMassCore::IsotopicDataType isotopic_data_type)
void | setMaxSummedProbability(double max_probability)
void | setNormalizationIntensity(int normalize_intensity)
void | setSortOrder(pappso::Enums::SortOrder sort_order)
void | setSortType(pappso::Enums::SortType sort_type)
bool | validateAllFormulas()
bool | validateFormula(MsXpS::libXpertMassCore::Formula &formula)

## Protected Functions

void | normalizeIntensities(pappso::TraceSPtr &isotopic_cluster_sp)
void | sortPeakCentroids(pappso::TraceSPtr &isotopic_cluster_sp)

## Protected Variables

std::vector<MsXpS::libXpertMassCore::FormulaChargePair> | m_formulaChargePairs
std::vector<MsXpS::libXpertMassCore::IsotopicClusterChargePair> | m_isotopicClusterChargePairs
MsXpS::libXpertMassCore::IsotopicDataType | m_isotopicDataType
double | m_maxSummedProbability
int | m_normalizeIntensity
pappso::Enums::SortOrder | m_sortOrder
pappso::Enums::SortType | m_sortType
MsXpS::libXpertMassCore::IsotopicDataSPtr | msp_isotopicData

## Detailed Description

The modelling uses the member isotopic data. The generated isotopic clusters only contain cluster centroid peaks. If peaks should have a profile, then they need to be shaped.

See also IsotopicClusterShaper and MassPeakShaper.

## Member Function Documentation

### IsotopicClusterGenerator::IsotopicClusterGenerator(QObject *parent = nullptr)

Constructs a IsotopicClusterGenerator instance.

### `[explicit]` IsotopicClusterGenerator::IsotopicClusterGenerator(MsXpS::libXpertMassCore::IsotopicDataSPtr isotopic_data_sp, QObject *parent = nullptr)

Constructs a IsotopicClusterGenerator instance.

- isotopic_data_sp: The isotopic data used for the calculations.

### `[virtual noexcept]` IsotopicClusterGenerator::~IsotopicClusterGenerator()

Destructs this IsotopicClusterGenerator instance.

### void IsotopicClusterGenerator::appendFormulaChargePair(MsXpS::libXpertMassCore::FormulaChargePair &formula_charge_pair)

Adds the (elemental composition, charge) pair formula_charge_pair to the member list of FormulaChargePair instances.

### QString IsotopicClusterGenerator::clusterToString(const pappso::TraceCstSPtr &isotopic_cluster_sp) const

Returns a string containing a space-separated set of m/z, intensity pairs, representing the isotopic cluster in isotopic_cluster_sp.

### QString IsotopicClusterGenerator::clustersToString() const

Returns a string containing a space-separated set of m/z, intensity pairs, representing the isotopic clusters in the member isotopic clusters m_isotopicClusterChargePairs.

### bool IsotopicClusterGenerator::configureIsotopicData(std::map<QString, int> &symbol_count_map, int *&per_element_isotopes_count_array_p, int *&per_element_symbol_count_array_p, double **&per_element_isotope_masses_arrays_p_p, double **&per_element_isotope_probs_arrays_p_p)

Configures the isotopic data in a set of arrays for the (symbol,count) pairs in symbol_count_map.

- per_element_isotopes_count_array_p: pointer to int array. This array lists the number of isotopes that each element has. Typically, C has 2, O has 3, P has 1...
- per_element_symbol_count_array_p: pointer to int array. This array lists the count of atoms of each element. Typically H20 will have 2 for H and 1 for O.
- per_element_isotope_masses_arrays_p_p: pointer to pointer to double array (array of arrays of double). Each array contains a new sub-array for each symbol. The sub-array contains the isotopic masses for one of the element symbols.
- per_element_isotope_probs_arrays_p_p: pointer to pointer to double array (array of arrays of double). Each array contains a new sub-array for each symbol. The sub-array contains the isotopic probs for one of the element symbols.

Returns a pappso::Trace with the calculated isotopic cluster.

### MsXpS::libXpertMassCore::IsotopicClusterChargePair IsotopicClusterGenerator::generateIsotopicClusterCentroids(MsXpS::libXpertMassCore::FormulaChargePair formula_charge_pair)

Calculates the isotopic cluster's peak centroids for formula_charge_pair.

1. The elemental composition formula string is converted to a Formula and validated.
2. The proper isotopic data handler is allocated (IsotopicDataType).
3. The number of symbols in the elemental composition is determined.
4. The int arrays and arrays of double arrays are allocated.
5. The arrays are filled-in with configureIsotopicData().
6. The calculations are performed on these arrays with runIsotopicDataCalculations().

Returns the results of the computation in the form of a IsotopicClusterChargePair instance.

### const std::vector<MsXpS::libXpertMassCore::IsotopicClusterChargePair> &IsotopicClusterGenerator::getIsotopicClusterChargePairs() const

Returns the member list ofIsotopicClusterChargePair instances.

### MsXpS::libXpertMassCore::IsotopicDataSPtr IsotopicClusterGenerator::getIsotopicData() const

Returns the isotopic data.

### `[protected]` void IsotopicClusterGenerator::normalizeIntensities(pappso::TraceSPtr &isotopic_cluster_sp)

Normalizes the intensities of the isotopic cluster's peak centroids in isotopic_cluster_sp.

If normalization is asked for, the most intense peak centroid in isotopic_cluster_sp is determined. That intensity becomes the m_normalizeIntensity value and all the other peak centroids' intensities are normalized.

Note: The normalization occurs in place.

### std::size_t IsotopicClusterGenerator::run()

Starts the computations.

The member m_isotopicClusterChargePairs are first cleared.

Returns the count of IsotopicClusterChargePair instances generated upon the calculations.

### pappso::TraceSPtr IsotopicClusterGenerator::runIsotopicDataCalculations(std::size_t element_count, int charge, int *per_element_isotopes_count_array_p, int *per_element_symbol_count_array_p, double **per_element_isotope_masses_arrays_p_p, double **per_element_isotope_probs_arrays_p_p)

Runs the IsoSpec-based isotopic calculations.

- element_count: the number of elements in the chemical composition.
- charge: the charge of the analyte. Might be 0 for neutral analytes.
- per_element_isotopes_count_array_p: pointer to int array. This array lists the number of isotopes that each element has. Typically, C has 2, O has 3, P has 1...
- per_element_symbol_count_array_p: pointer to int array. This array lists the count of atoms of each element. Typically H20 will have 2 for H and 1 for O.
- per_element_isotope_masses_arrays_p_p: pointer to pointer to double array (array of arrays of double). Each array contains a new sub-array for each symbol. The sub-array contains the isotopic masses for one of the element symbols.
- per_element_isotope_probs_arrays_p_p: pointer to pointer to double array (array of arrays of double). Each array contains a new sub-array for each symbol. The sub-array contains the isotopic probs for one of the element symbols.

Returns a pappso::Trace with the calculated isotopic cluster.

### void IsotopicClusterGenerator::setFormulaChargePair(MsXpS::libXpertMassCore::FormulaChargePair &formula_charge_pair)

Adds the (elemental composition, charge) pair formula_charge_pair to the member list of FormulaChargePair instances.

The member list of FormulaChargePair instances is first cleared.

### void IsotopicClusterGenerator::setFormulaChargePairs(const std::vector<MsXpS::libXpertMassCore::FormulaChargePair> &formula_charge_pairs)

Adds the (elemental composition, charge) pairs formula_charge_pairs to the member list of FormulaChargePair instances.

The member list of FormulaChargePair instances is first cleared.

### void IsotopicClusterGenerator::setIsotopicData(MsXpS::libXpertMassCore::IsotopicDataSPtr isotopic_data_sp)

Sets the isotopic data to isotopic_data_sp.

### void IsotopicClusterGenerator::setIsotopicDataType(MsXpS::libXpertMassCore::IsotopicDataType isotopic_data_type)

Sets the isotopic data type to isotopic_data_type.

### void IsotopicClusterGenerator::setMaxSummedProbability(double max_probability)

Sets the summed probability maximum value to max_probability.

### void IsotopicClusterGenerator::setNormalizationIntensity(int normalize_intensity)

Sets the normalization intensity to normalize_intensity.

### void IsotopicClusterGenerator::setSortOrder(pappso::Enums::SortOrder sort_order)

Sets the sort_order.

### void IsotopicClusterGenerator::setSortType(pappso::Enums::SortType sort_type)

Sets the sort_type.

### `[protected]` void IsotopicClusterGenerator::sortPeakCentroids(pappso::TraceSPtr &isotopic_cluster_sp)

Sorts the peak centroids of the isotopic cluster isotopic_cluster_sp.

The sort is performed according to m_sortType.

### bool IsotopicClusterGenerator::validateAllFormulas()

Validates all the elemental compositions in this IsotopicClusterGenerator instance.

Each FormulaChargePair in m_formulaChargePairs is validated for its elemental composition by first creating a Formula out of it.

Returns true if validation was successful, false otherwise.

See also validateFormula and Formula::validate().

### bool IsotopicClusterGenerator::validateFormula(MsXpS::libXpertMassCore::Formula &formula)

Validates the elemental composition formula.

The formula needs to be fully indexed, that is, even an atom present only once needs to be indexed with '1', like this `H2O1`.

Returns true if validation was successful, false otherwise.

See also Formula::validate().

## Member Variable Documentation

### std::vector<MsXpS::libXpertMassCore::FormulaChargePair> IsotopicClusterGenerator::m_formulaChargePairs

This variable holds the set of (elemental composition, charge) pairs.

### std::vector<MsXpS::libXpertMassCore::IsotopicClusterChargePair> IsotopicClusterGenerator::m_isotopicClusterChargePairs

This variable holds the set of (isotopic cluster, charge) pairs.

Neutral analytes will have the charge set to 0.

### MsXpS::libXpertMassCore::IsotopicDataType IsotopicClusterGenerator::m_isotopicDataType

This variable holds the IsotopicDataType type of data.

### double IsotopicClusterGenerator::m_maxSummedProbability

This variable holds the summed probability of all the isotopic cluster peaks. The computation stops when this probability is reached.

### int IsotopicClusterGenerator::m_normalizeIntensity

This variable holds the most intense cluster peak's intensity that is used to normalize all the other cluster peaks.

### pappso::Enums::SortOrder IsotopicClusterGenerator::m_sortOrder

This variable holds the order of the sorting for the generated cluster peak centroids.

### pappso::Enums::SortType IsotopicClusterGenerator::m_sortType

This variable holds the type of sorting required for the generated cluster peak centroids.

### MsXpS::libXpertMassCore::IsotopicDataSPtr IsotopicClusterGenerator::msp_isotopicData

This variable holds the isotopic data needed for the computations.