OpenMS  2.7.0
IMSAlphabet.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Anton Pervukhin <Anton.Pervukhin@CeBiTec.Uni-Bielefeld.DE> $
33 // --------------------------------------------------------------------------
34 //
35 
36 #pragma once
37 
38 #include <vector>
39 #include <string>
40 #include <iosfwd>
41 
43 
46 
47 namespace OpenMS
48 {
49 
50  namespace ims
51  {
52 
81  class OPENMS_DLLAPI IMSAlphabet
82  {
83 
84 public:
88  typedef std::vector<element_type> container;
89  typedef container::size_type size_type;
90  typedef container::iterator iterator;
91  typedef container::const_iterator const_iterator;
92  typedef std::vector<name_type> name_container;
93  typedef name_container::iterator name_iterator;
94  typedef name_container::const_iterator const_name_iterator;
95  typedef std::vector<mass_type> mass_container;
96  typedef mass_container::iterator mass_iterator;
97  typedef mass_container::const_iterator const_mass_iterator;
98  typedef std::vector<mass_type> masses_type;
99 
104 
105 
111  explicit IMSAlphabet(const container & elements) :
112  elements_(elements)
113  {}
114 
115 
121  IMSAlphabet(const IMSAlphabet & alphabet) :
122  elements_(alphabet.elements_)
123  {}
124 
130  size_type size() const
131  {
132  return elements_.size();
133  }
134 
142  const element_type & getElement(size_type index) const
143  {
144  return elements_[index];
145  }
146 
157  void setElement(const name_type & name, mass_type mass, bool forced = false);
158 
165  bool erase(const name_type & name);
166 
175  const element_type & getElement(const name_type & name) const;
176 
183  const name_type & getName(size_type index) const;
184 
194  mass_type getMass(const name_type & name) const;
195 
204 
211  masses_type getMasses(size_type isotope_index = 0) const;
212 
219 
227  bool hasName(const name_type & name) const;
228 
238  void push_back(const name_type & name, mass_type value)
239  {
240  push_back(element_type(name, value));
241  }
242 
248  void push_back(const element_type & element)
249  {
250  elements_.push_back(element);
251  }
252 
256  void clear()
257  {
258  elements_.clear();
259  }
260 
266  virtual void sortByNames();
267 
268 
274  virtual void sortByValues();
275 
276 
286  virtual void load(const std::string & fname);
287 
288 
300  virtual void load(const std::string & fname, IMSAlphabetParser<> & parser);
301 
302 
306  virtual ~IMSAlphabet() {}
307 
308 private:
313 
317  class OPENMS_DLLAPI MassSortingCriteria_
318  {
319 public:
320  bool operator()(const element_type & el1,
321  const element_type & el2) const
322  {
323  return el1.getMass() < el2.getMass();
324  }
325 
326  };
327 
328  };
329 
336  OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const IMSAlphabet & alphabet);
337 
338  } // namespace ims
339 
340 } // namespace OpenMS
341 
An abstract templatized parser to load the data that is used to initialize Alphabet objects.
Definition: IMSAlphabetParser.h:64
Private class-functor to sort out elements in mass ascending order.
Definition: IMSAlphabet.h:318
bool operator()(const element_type &el1, const element_type &el2) const
Definition: IMSAlphabet.h:320
Holds an indexed list of bio-chemical elements.
Definition: IMSAlphabet.h:82
masses_type getMasses(size_type isotope_index=0) const
element_type::mass_type mass_type
Definition: IMSAlphabet.h:86
container::size_type size_type
Definition: IMSAlphabet.h:89
virtual void load(const std::string &fname, IMSAlphabetParser<> &parser)
virtual void sortByValues()
container elements_
Definition: IMSAlphabet.h:312
IMSAlphabet()
Definition: IMSAlphabet.h:103
mass_type getMass(size_type index) const
virtual void load(const std::string &fname)
void push_back(const element_type &element)
Definition: IMSAlphabet.h:248
bool hasName(const name_type &name) const
IMSAlphabet(const IMSAlphabet &alphabet)
Definition: IMSAlphabet.h:121
size_type size() const
Definition: IMSAlphabet.h:130
const name_type & getName(size_type index) const
std::vector< mass_type > mass_container
Definition: IMSAlphabet.h:95
std::vector< element_type > container
Definition: IMSAlphabet.h:88
container::iterator iterator
Definition: IMSAlphabet.h:90
virtual void sortByNames()
masses_type getAverageMasses() const
void setElement(const name_type &name, mass_type mass, bool forced=false)
const element_type & getElement(const name_type &name) const
std::vector< name_type > name_container
Definition: IMSAlphabet.h:92
name_container::iterator name_iterator
Definition: IMSAlphabet.h:93
void push_back(const name_type &name, mass_type value)
Definition: IMSAlphabet.h:238
IMSElement element_type
Definition: IMSAlphabet.h:85
const element_type & getElement(size_type index) const
Definition: IMSAlphabet.h:142
std::vector< mass_type > masses_type
Definition: IMSAlphabet.h:98
mass_type getMass(const name_type &name) const
mass_container::const_iterator const_mass_iterator
Definition: IMSAlphabet.h:97
void clear()
Definition: IMSAlphabet.h:256
element_type::name_type name_type
Definition: IMSAlphabet.h:87
virtual ~IMSAlphabet()
Definition: IMSAlphabet.h:306
container::const_iterator const_iterator
Definition: IMSAlphabet.h:91
mass_container::iterator mass_iterator
Definition: IMSAlphabet.h:96
name_container::const_iterator const_name_iterator
Definition: IMSAlphabet.h:94
IMSAlphabet(const container &elements)
Definition: IMSAlphabet.h:111
bool erase(const name_type &name)
Represents a chemical atom with name and isotope distribution.
Definition: IMSElement.h:59
isotopes_type::mass_type mass_type
Type of isotope mass.
Definition: IMSElement.h:68
std::string name_type
Type of element's name.
Definition: IMSElement.h:62
mass_type getMass(size_type index=0) const
Definition: IMSElement.h:172
std::ostream & operator<<(std::ostream &os, const IMSAlphabet &alphabet)
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47