OpenMS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MassExplainer Class Reference

Computes empirical formulas for given mass differences using a set of allowed elements. More...

#include <OpenMS/DATASTRUCTURES/MassExplainer.h>

Collaboration diagram for MassExplainer:
[legend]

Public Types

typedef Adduct::AdductsType AdductsType
 Type definition for a vector of Adduct objects. More...
 
typedef std::vector< Compomer >::const_iterator CompomerIterator
 Type definition for an iterator over Compomer objects. More...
 

Constructors and destructor

std::vector< Compomerexplanations_
 Vector storing all possible explanations for mass differences. More...
 
AdductsType adduct_base_
 Set of allowed adducts that can be combined to explain mass differences. More...
 
Int q_min_
 Minimum charge state to consider in explanations. More...
 
Int q_max_
 Maximum charge state to consider in explanations. More...
 
Int max_span_
 Maximum allowed charge span between related features (e.g., a cluster with q={3,6} has span=4) More...
 
double thresh_p_
 Minimum required probability threshold for accepting explanations. More...
 
Size max_neutrals_
 Maximum number of neutral (q=0) adducts allowed in an explanation. More...
 
 MassExplainer ()
 Default constructor. More...
 
 MassExplainer (AdductsType adduct_base)
 Constructor with custom adduct base. More...
 
 MassExplainer (Int q_min, Int q_max, Int max_span, double thresh_logp)
 Constructor with custom charge parameters. More...
 
 MassExplainer (AdductsType adduct_base, Int q_min, Int q_max, Int max_span, double thresh_logp, Size max_neutrals)
 Constructor with all custom parameters. More...
 
MassExplaineroperator= (const MassExplainer &rhs)
 Assignment operator. More...
 
virtual ~MassExplainer ()
 Destructor. More...
 
void compute ()
 Compute all possible mass differences and their explanations. More...
 
void setAdductBase (AdductsType adduct_base)
 Set the base set of allowed adducts. More...
 
AdductsType getAdductBase () const
 Get the current set of allowed adducts. More...
 
const CompomergetCompomerById (Size id) const
 Get a specific compomer by its ID. More...
 
SignedSize query (const Int net_charge, const float mass_to_explain, const float mass_delta, const float thresh_log_p, std::vector< Compomer >::const_iterator &firstExplanation, std::vector< Compomer >::const_iterator &lastExplanation) const
 Search for explanations of a given mass difference. More...
 
void init_ (bool init_thresh_p)
 Check consistency of input parameters and initialize internal data structures. More...
 
bool compomerValid_ (const Compomer &cmp) const
 Check if a generated compomer is valid based on its probability, charges, etc. More...
 
Adduct createAdduct_ (const String &formula, const Int charge, const double p) const
 Create a proper adduct from formula, charge, and probability. More...
 

Detailed Description

Computes empirical formulas for given mass differences using a set of allowed elements.

MassExplainer is used to explain observed mass differences between features by determining the most likely combination of adducts that could cause such differences.

The class works by:

  1. Taking a set of allowed adducts (elements, molecules, or ions)
  2. Computing all possible combinations of these adducts that could explain observed mass differences
  3. Providing a query interface to search for explanations for specific mass differences

This is particularly useful in mass spectrometry data analysis for identifying related features that represent the same analyte but with different adducts or charge states.

Member Typedef Documentation

◆ AdductsType

Type definition for a vector of Adduct objects.

◆ CompomerIterator

typedef std::vector<Compomer>::const_iterator CompomerIterator

Type definition for an iterator over Compomer objects.

Constructor & Destructor Documentation

◆ MassExplainer() [1/4]

Default constructor.

Initializes with default parameters:

  • No adducts
  • Charge range from -2 to +4
  • Maximum charge span of 4
  • Log probability threshold of -5.0
  • Maximum number of neutral adducts of 2

◆ MassExplainer() [2/4]

MassExplainer ( AdductsType  adduct_base)

Constructor with custom adduct base.

Parameters
adduct_baseSet of allowed adducts to use for mass difference explanations

◆ MassExplainer() [3/4]

MassExplainer ( Int  q_min,
Int  q_max,
Int  max_span,
double  thresh_logp 
)

Constructor with custom charge parameters.

Parameters
q_minMinimum charge state to consider
q_maxMaximum charge state to consider
max_spanMaximum allowed charge span between related features
thresh_logpMinimum log probability threshold for accepting explanations

◆ MassExplainer() [4/4]

MassExplainer ( AdductsType  adduct_base,
Int  q_min,
Int  q_max,
Int  max_span,
double  thresh_logp,
Size  max_neutrals 
)

Constructor with all custom parameters.

Parameters
adduct_baseSet of allowed adducts to use for mass difference explanations
q_minMinimum charge state to consider
q_maxMaximum charge state to consider
max_spanMaximum allowed charge span between related features
thresh_logpMinimum log probability threshold for accepting explanations
max_neutralsMaximum number of neutral adducts allowed in an explanation

◆ ~MassExplainer()

virtual ~MassExplainer ( )
virtual

Destructor.

Member Function Documentation

◆ compomerValid_()

bool compomerValid_ ( const Compomer cmp) const
protected

Check if a generated compomer is valid based on its probability, charges, etc.

Parameters
cmpThe compomer to validate
Returns
True if the compomer is valid, false otherwise

◆ compute()

void compute ( )

Compute all possible mass differences and their explanations.

This method generates all possible combinations of adducts from the adduct base and stores them internally for later querying. This must be called after changing any parameters and before performing queries.

◆ createAdduct_()

Adduct createAdduct_ ( const String formula,
const Int  charge,
const double  p 
) const
protected

Create a proper adduct from formula, charge, and probability.

Parameters
formulaChemical formula of the adduct
chargeCharge of the adduct
pProbability of the adduct
Returns
Adduct object with the specified properties

◆ getAdductBase()

AdductsType getAdductBase ( ) const

Get the current set of allowed adducts.

Returns
Vector of adducts currently used for explanations

◆ getCompomerById()

const Compomer& getCompomerById ( Size  id) const

Get a specific compomer by its ID.

This is typically used after a query() to retrieve detailed information about a specific explanation.

Parameters
idID of the compomer to retrieve
Returns
Reference to the requested compomer

◆ init_()

void init_ ( bool  init_thresh_p)
private

Check consistency of input parameters and initialize internal data structures.

This method validates the input parameters and sets default values where needed.

Parameters
init_thresh_pWhether to initialize the probability threshold with default value (set to "false" to keep current value)

◆ operator=()

MassExplainer& operator= ( const MassExplainer rhs)

Assignment operator.

Parameters
rhsSource object to assign from
Returns
Reference to this object

◆ query()

SignedSize query ( const Int  net_charge,
const float  mass_to_explain,
const float  mass_delta,
const float  thresh_log_p,
std::vector< Compomer >::const_iterator &  firstExplanation,
std::vector< Compomer >::const_iterator &  lastExplanation 
) const

Search for explanations of a given mass difference.

This method searches the precomputed explanations for those that match the given mass difference within the specified tolerance and have the required net charge.

Parameters
net_chargeNet charge of the compomer being sought
mass_to_explainMass difference in Da that needs explanation
mass_deltaAllowed deviation from exact mass (tolerance)
thresh_log_pMinimum log probability required for explanations
firstExplanationOutput iterator to the beginning of matching explanations
lastExplanationOutput iterator to the end of matching explanations
Returns
Number of explanations found, or negative value if no explanations found

◆ setAdductBase()

void setAdductBase ( AdductsType  adduct_base)

Set the base set of allowed adducts.

Parameters
adduct_baseVector of adducts to use for explanations

Member Data Documentation

◆ adduct_base_

AdductsType adduct_base_
protected

Set of allowed adducts that can be combined to explain mass differences.

◆ explanations_

std::vector<Compomer> explanations_
protected

Vector storing all possible explanations for mass differences.

◆ max_neutrals_

Size max_neutrals_
protected

Maximum number of neutral (q=0) adducts allowed in an explanation.

◆ max_span_

Int max_span_
protected

Maximum allowed charge span between related features (e.g., a cluster with q={3,6} has span=4)

◆ q_max_

Int q_max_
protected

Maximum charge state to consider in explanations.

◆ q_min_

Int q_min_
protected

Minimum charge state to consider in explanations.

◆ thresh_p_

double thresh_p_
protected

Minimum required probability threshold for accepting explanations.