OpenMS  2.7.0
Classes | Public Types | Public Member Functions | List of all members
IMSAlphabet Class Reference

Holds an indexed list of bio-chemical elements. More...

#include <OpenMS/CHEMISTRY/MASSDECOMPOSITION/IMS/IMSAlphabet.h>

Collaboration diagram for IMSAlphabet:
[legend]

Classes

class  MassSortingCriteria_
 Private class-functor to sort out elements in mass ascending order. More...
 

Public Types

typedef IMSElement element_type
 
typedef element_type::mass_type mass_type
 
typedef element_type::name_type name_type
 
typedef std::vector< element_typecontainer
 
typedef container::size_type size_type
 
typedef container::iterator iterator
 
typedef container::const_iterator const_iterator
 
typedef std::vector< name_typename_container
 
typedef name_container::iterator name_iterator
 
typedef name_container::const_iterator const_name_iterator
 
typedef std::vector< mass_typemass_container
 
typedef mass_container::iterator mass_iterator
 
typedef mass_container::const_iterator const_mass_iterator
 
typedef std::vector< mass_typemasses_type
 

Public Member Functions

 IMSAlphabet ()
 
 IMSAlphabet (const container &elements)
 
 IMSAlphabet (const IMSAlphabet &alphabet)
 
size_type size () const
 
const element_typegetElement (size_type index) const
 
void setElement (const name_type &name, mass_type mass, bool forced=false)
 
bool erase (const name_type &name)
 

. If there is

Gets the element with the symbol no such element, throws Exception::InvalidValue.

Parameters
nameName of the element.
Returns
Element with the given name, or if there are no such element
Exceptions
Exception::InvalidValue.
container elements_
 
const element_typegetElement (const name_type &name) const
 
const name_typegetName (size_type index) const
 
mass_type getMass (const name_type &name) const
 
mass_type getMass (size_type index) const
 
masses_type getMasses (size_type isotope_index=0) const
 
masses_type getAverageMasses () const
 
bool hasName (const name_type &name) const
 
void push_back (const name_type &name, mass_type value)
 
void push_back (const element_type &element)
 
void clear ()
 
virtual void sortByNames ()
 
virtual void sortByValues ()
 
virtual void load (const std::string &fname)
 
virtual void load (const std::string &fname, IMSAlphabetParser<> &parser)
 
virtual ~IMSAlphabet ()
 

Detailed Description

Holds an indexed list of bio-chemical elements.

Presents an indexed list of bio-chemical elements of type (or derived from type) Element. Due to indexed structure Alphabet can be used similar to std::vector, for example to add a new element to Alphabet function push_back(element_type) can be used. Elements or their properties (such as element's mass) can be accessed by index in a constant time. On the other hand accessing elements by their names takes linear time. Due to this and also the fact that Alphabet is 'heavy-weighted' (consisting of Element -s or their derivatives where the depth of derivation as well is undefined resulting in possibly 'heavy' access operations) it is recommended not use Alphabet directly in operations where fast access to Element 's properties is required. Instead consider to use 'light-weighted' equivalents, such as Weights.

Elements in Alphabet can be sorted by the Element 's properties: sequence and mass. When alphabet's data is loaded from file it is automatically sorted by mass. To load data from file default function load(str::string& fname) can be used. Then elements have to be stored in a flat file fname in a predefined format. To read more on this format, please,

See also
AlphabetParser. If one wants to load data stored differently or in its own file format (i.e. xml) one has to define a new parser derived from AlphabetParser and pass its pointer together with the file name to function load(const std::string& fname, AlphabetParser<>* parser). If there is any error happened while loading data, IOException will be thrown.

Member Typedef Documentation

◆ const_iterator

typedef container::const_iterator const_iterator

◆ const_mass_iterator

typedef mass_container::const_iterator const_mass_iterator

◆ const_name_iterator

typedef name_container::const_iterator const_name_iterator

◆ container

typedef std::vector<element_type> container

◆ element_type

◆ iterator

typedef container::iterator iterator

◆ mass_container

typedef std::vector<mass_type> mass_container

◆ mass_iterator

typedef mass_container::iterator mass_iterator

◆ mass_type

◆ masses_type

typedef std::vector<mass_type> masses_type

◆ name_container

typedef std::vector<name_type> name_container

◆ name_iterator

typedef name_container::iterator name_iterator

◆ name_type

◆ size_type

typedef container::size_type size_type

Constructor & Destructor Documentation

◆ IMSAlphabet() [1/3]

IMSAlphabet ( )
inline

Empty constructor.

◆ IMSAlphabet() [2/3]

IMSAlphabet ( const container elements)
inlineexplicit

Constructor with elements.

Parameters
elementsElements to be set

◆ IMSAlphabet() [3/3]

IMSAlphabet ( const IMSAlphabet alphabet)
inline

Copy constructor.

Parameters
alphabetAlphabet to be assigned

◆ ~IMSAlphabet()

virtual ~IMSAlphabet ( )
inlinevirtual

Default destructor.

Member Function Documentation

◆ clear()

void clear ( )
inline

Clears the alphabet data.

◆ erase()

bool erase ( const name_type name)

Removes the element with name name from the alphabet.

Parameters
nameThe name of the element to be removed from the alphabet.
Returns
A boolean indicating whether an element was removed (true) or not (false).

◆ getAverageMasses()

masses_type getAverageMasses ( ) const

Gets average masses of elements.

Returns
Average masses of elements.

◆ getElement() [1/2]

const element_type& getElement ( const name_type name) const

◆ getElement() [2/2]

const element_type& getElement ( size_type  index) const
inline

Gets the element with index index.

Note
Operation takes constant time.
Parameters
indexof the element
Returns
Element with the given index in alphabet

◆ getMass() [1/2]

mass_type getMass ( const name_type name) const

Gets mono isotopic mass of the element with the symbol name. If there is no such element, throws an Exception::InvalidValue.

Parameters
nameSymbol of the element.
Returns
Mass of the element, or if there are no element
Exceptions
Exception::InvalidValue.
See also
getMass(size_type index)

◆ getMass() [2/2]

mass_type getMass ( size_type  index) const

Gets mass of the element with an index index in alphabet.

Parameters
indexIndex of the element.
Returns
Mass of the element.
See also
getMass(const std::string& name)

◆ getMasses()

masses_type getMasses ( size_type  isotope_index = 0) const

Gets masses of elements isotopes given by isotope_index.

Parameters
isotope_indexIndex of isotope
Returns
Masses of elements isotopes with the given index.

◆ getName()

const name_type& getName ( size_type  index) const

Gets the symbol of the element with an index index in alphabet.

Parameters
indexof the element.
Returns
Name of the element.

◆ hasName()

bool hasName ( const name_type name) const

Returns true if there is an element with symbol name in the alphabet, false - otherwise.

Returns
True, if there is an element with symbol name, false - otherwise.

◆ load() [1/2]

virtual void load ( const std::string &  fname)
virtual

Loads the alphabet data from the file fname using the default parser. If there is no file fname, throws an IOException.

Parameters
fnameThe file name to be loaded.
Exceptions
Exception::IOException
See also
load(const std::string& fname, AlphabetParser<>* parser)

◆ load() [2/2]

virtual void load ( const std::string &  fname,
IMSAlphabetParser<> &  parser 
)
virtual

Loads the alphabet data from the file fname using parser. If there is no file fname found, throws an IOException.

Parameters
fnameFile name to be loaded.
parserParser to be used by loading.
Exceptions
Exception::IOException
See also
load(const std::string& fname)
AlphabetParser

◆ push_back() [1/2]

void push_back ( const element_type element)
inline

Adds a new element element to the alphabet.

Parameters
elementThe Element to be added.

◆ push_back() [2/2]

void push_back ( const name_type name,
mass_type  value 
)
inline

Adds a new element with name name and mass value to the alphabet.

Parameters
nameName of the element to be added.
valueMass of the element to be added.
See also
push_back(const element_type&)

◆ setElement()

void setElement ( const name_type name,
mass_type  mass,
bool  forced = false 
)

Overwrites an element in the alphabet with the name with a new element constructed from the given name name and mass mass. If the parameter forced is set to true, a new element will be appended to the alphabet in the case the alphabet contains no element with the name name.

Parameters
nameThe name of the element that should be replaced in (or appended to) the alphabet.
massThe new mass of the element in the alphabet.
forcedIndicates whether a new element should be created (if set to true) if there is no element with the name name or not (if set to false).

◆ size()

size_type size ( ) const
inline

Returns the alphabet size.

Returns
The size of alphabet.

◆ sortByNames()

virtual void sortByNames ( )
virtual

Sorts the alphabet by names.

See also
sortByValues()

◆ sortByValues()

virtual void sortByValues ( )
virtual

Sorts the alphabet by mass values.

See also
sortByNames()

Member Data Documentation

◆ elements_

container elements_
private

Elements of the alphabet.