Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Auxiliary datastructures

This section contains a short introduction to three datastructures you will definitely need when programming with OpenMS. The datastructures module of the class documentation contains many more classes, which are not mentioned here in detail. The classes described in this section can be found in the DATASTRUCTURES folder.

The OpenMS string implementation

The OpenMS string implementation String is based on the STL std::string. In order to make the OpenMS string class more convenient, a lot of methods have been implemented in addition to the methods provided by the base class. A selection of the added functionaliy is given here:

D-dimensional coordinates

Many OpenMS classes, especially the kernel classes, need to store some kind of d-dimensional coordinates. The template class DPosition is used for that purpose. The interface of DPosition is pretty straightforward. The operator[] is used to access the coordinate of the different dimensions. The dimensionality is stored in the enum value DIMENSION. The following example (Tutorial_DPosition.C) shows how to print a DPosition to the standard output stream.

First we need to include the header file for DPosition and iostream. Then we import all the OpenMS symbols to the scope with the using directive.

// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include <OpenMS/DATASTRUCTURES/DPosition.h>
#include <iostream>
using namespace OpenMS;
The first commands in the main method initialize a 2-dimensional DPosition :
Int main()
{
DPosition<2> pos;
pos[0] = 8.15;
pos[1] = 47.11;
Finally we print the content of the DPosition to the standard output stream:
for (Size i = 0; i < DPosition<2>::DIMENSION; ++i)
{
std::cout << "Dimension " << i << ": " << pos[i] << std::endl;
}
return 0;
} //end of main

The output of our first little OpenMS program is the following:

Dimension 0: 8.15
Dimension 1: 47.11

D-dimensional ranges

Another important datastructure we need to look at in detail is DRange. It defines a d-dimensional, half-open interval through its two DPosition members. These members are accessed by the minPosition() and maxPosition() methods and can be set by the setMin() and setMax() methods.

DRange maintains the invariant that minPosition() is geometrically less or equal to maxPosition(), i.e. $ minPosition()[x] \le maxPosition()[x]$ for each dimension x. The following example (Tutorial_DRange.C) demonstrates this behavior.

This time, we skip everything before the main method. In the main method, we create a range and assign values to min and max. Note that the the minimum value of the first dimension is larger than the maximum value.

Int main()
{
DRange<2> range;
range.setMin(DPosition<2>(2.0, 3.0));
range.setMax(DPosition<2>(1.0, 5.0));
Then we print the content of range :
for (UInt i = 0; i < DRange<2>::DIMENSION; ++i)
{
std::cout << "min " << i << ": " << range.minPosition()[i] << std::endl;
std::cout << "max " << i << ": " << range.maxPosition()[i] << std::endl;
}
return 0;
} //end of main

The output is:

min 0: 1
max 0: 1
min 1: 3
max 1: 5

As you can see, the minimum value of dimension one was adjusted in order to make the maximum of 1 conform with the invariant.

DIntervalBase is the closed interval counterpart (and base class) of DRange. Another class derived from DIntervalBase is DBoundingBox. It also represents a closed interval, but differs in the methods. Please have a look at the class documentation for details.

Param

Most algorithms of OpenMS and some of the TOPP tools have many parameters. The parameters are stored in instances of Param. This class is similar to a Windows INI file. The actual parameters (type, name and value) are stored in sections. Sections can contain parameters and sub-sections, which leads to a tree-like structure. The values are stored in DataValue.
Parameter names are given as a string including the sections and subsections in which ':' is used as a delimiter.

The following example (Tutorial_Param.C) shows how a file description is given.

Int main()
{
Param param;
param.setValue("file:name", "test.xml");
param.setValue("file:size(MB)", 572.3);
param.setValue("file:data:min_int", 0);
param.setValue("file:data:max_int", 16459);
cout << "Name : " << (String)(param.getValue("file:name")) << endl;
cout << "Size : " << (Real)(param.getValue("file:size(MB)")) << endl;
cout << "Min int: " << (UInt)(param.getValue("file:data:min_int")) << endl;
cout << "Max int: " << (UInt)(param.getValue("file:data:max_int")) << endl;
return 0;
} //end of main


OpenMS / TOPP release 1.11.1 Documentation generated on Sun Sep 7 2014 06:42:38 using doxygen 1.8.8