1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
<HTML>
<HEAD>
<TITLE>Auxiliary datastructures</TITLE>
<LINK HREF="doxygen.css" REL="stylesheet" TYPE="text/css">
<LINK HREF="style_ini.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<A href="index.html">Home</A> ·
<A href="classes.html">Classes</A> ·
<A href="annotated.html">Annotated Classes</A> ·
<A href="modules.html">Modules</A> ·
<A href="functions_func.html">Members</A> ·
<A href="namespaces.html">Namespaces</A> ·
<A href="pages.html">Related Pages</A>
<HR style="height:1px; border:none; border-top:1px solid #c0c0c0;">
<!-- Generated by Doxygen 1.8.5 -->
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Auxiliary datastructures </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>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 <em>DATASTRUCTURES</em> folder.</p>
<h1><a class="anchor" id="datastructures_string"></a>
The OpenMS string implementation</h1>
<p>The OpenMS string implementation <em>String</em> is based on the STL <em>std::string</em>. 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:</p>
<ul>
<li>Checking for a substring (suffix, prefix, substring, char)</li>
<li>Extracting a substring (suffix, prefix, substring)</li>
<li>Trimming (left, right, both sides)</li>
<li>Concatenation of string and other primitive types with <em>operator+</em> </li>
<li>Construction from QString and conversion to QString</li>
</ul>
<h1><a class="anchor" id="datastructures_dposition"></a>
D-dimensional coordinates</h1>
<p>Many OpenMS classes, especially the kernel classes, need to store some kind of d-dimensional coordinates. The template class <em>DPosition</em> 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 <em>DIMENSION</em>. The following example (Tutorial_DPosition.C) shows how to print a DPosition to the standard output stream.</p>
<p>First we need to include the header file for <em>DPosition</em> and <em>iostream</em>. Then we import all the OpenMS symbols to the scope with the <em>using</em> directive. <div class="fragment"><div class="line"><span class="comment">// --------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">// OpenMS -- Open-Source Mass Spectrometry</span></div>
<div class="line"><span class="comment">// --------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,</span></div>
<div class="line"><span class="comment">// ETH Zurich, and Freie Universitaet Berlin 2002-2013.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"><span class="comment">// This software is released under a three-clause BSD license:</span></div>
<div class="line"><span class="comment">// * Redistributions of source code must retain the above copyright</span></div>
<div class="line"><span class="comment">// notice, this list of conditions and the following disclaimer.</span></div>
<div class="line"><span class="comment">// * Redistributions in binary form must reproduce the above copyright</span></div>
<div class="line"><span class="comment">// notice, this list of conditions and the following disclaimer in the</span></div>
<div class="line"><span class="comment">// documentation and/or other materials provided with the distribution.</span></div>
<div class="line"><span class="comment">// * Neither the name of any author or any participating institution</span></div>
<div class="line"><span class="comment">// may be used to endorse or promote products derived from this software</span></div>
<div class="line"><span class="comment">// without specific prior written permission.</span></div>
<div class="line"><span class="comment">// For a full list of authors, refer to the file AUTHORS.</span></div>
<div class="line"><span class="comment">// --------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment">// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"</span></div>
<div class="line"><span class="comment">// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span></div>
<div class="line"><span class="comment">// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span></div>
<div class="line"><span class="comment">// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING</span></div>
<div class="line"><span class="comment">// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,</span></div>
<div class="line"><span class="comment">// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,</span></div>
<div class="line"><span class="comment">// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;</span></div>
<div class="line"><span class="comment">// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,</span></div>
<div class="line"><span class="comment">// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR</span></div>
<div class="line"><span class="comment">// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF</span></div>
<div class="line"><span class="comment">// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span></div>
<div class="line"><span class="comment">//</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include <<a class="code" href="DPosition_8h.html">OpenMS/DATASTRUCTURES/DPosition.h</a>></span></div>
<div class="line"><span class="preprocessor">#include <iostream></span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>OpenMS;</div>
</div><!-- fragment --> The first commands in the main method initialize a 2-dimensional <em>DPosition</em> : <div class="fragment"><div class="line"></div>
<div class="line"><a class="code" href="classInt.html">Int</a> <a class="code" href="RNPxl_8C.html#a217dbf8b442f20279ea00b898af96f52">main</a>()</div>
<div class="line">{</div>
<div class="line"> DPosition<2> pos;</div>
<div class="line"> pos[0] = 8.15;</div>
<div class="line"> pos[1] = 47.11;</div>
</div><!-- fragment --> Finally we print the content of the DPosition to the standard output stream: <div class="fragment"><div class="line"></div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__Concept.html#gaf9ecec2d692138fab9167164a457cbd4">Size</a> i = 0; i < DPosition<2>::DIMENSION; ++i)</div>
<div class="line"> {</div>
<div class="line"> std::cout << <span class="stringliteral">"Dimension "</span> << i << <span class="stringliteral">": "</span> << pos[i] << std::endl;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">} <span class="comment">//end of main</span></div>
</div><!-- fragment --></p>
<p>The output of our first little OpenMS program is the following: </p>
<div class="fragment"><div class="line">Dimension 0: 8.15</div>
<div class="line">Dimension 1: 47.11</div>
</div><!-- fragment --><h1><a class="anchor" id="datastructures_drange"></a>
D-dimensional ranges</h1>
<p>Another important datastructure we need to look at in detail is <em>DRange</em>. It defines a d-dimensional, half-open interval through its two <em>DPosition</em> members. These members are accessed by the <em>minPosition()</em> and <em>maxPosition()</em> methods and can be set by the <em>setMin()</em> and <em>setMax()</em> methods.</p>
<p>DRange maintains the invariant that <em>minPosition()</em> is geometrically less or equal to <em>maxPosition()</em>, i.e. <img class="formulaInl" alt="$ minPosition()[x] \le maxPosition()[x]$" src="form_101.png"/> for each dimension <em>x</em>. The following example (Tutorial_DRange.C) demonstrates this behavior.</p>
<p>This time, we skip everything before the main method. In the main method, we create a range and assign values to <em>min</em> and <em>max</em>. Note that the the minimum value of the first dimension is larger than the maximum value. <div class="fragment"><div class="line"><a class="code" href="classInt.html">Int</a> <a class="code" href="RNPxl_8C.html#a217dbf8b442f20279ea00b898af96f52">main</a>()</div>
<div class="line">{</div>
<div class="line"> DRange<2> range;</div>
<div class="line"> range.setMin(DPosition<2>(2.0, 3.0));</div>
<div class="line"> range.setMax(DPosition<2>(1.0, 5.0));</div>
</div><!-- fragment --> Then we print the content of <em>range</em> : <div class="fragment"><div class="line"></div>
<div class="line"> <span class="keywordflow">for</span> (<a class="code" href="group__Concept.html#gaba0996d26f7be2572973245b51852757">UInt</a> i = 0; i < DRange<2>::DIMENSION; ++i)</div>
<div class="line"> {</div>
<div class="line"> std::cout << <span class="stringliteral">"min "</span> << i << <span class="stringliteral">": "</span> << range.minPosition()[i] << std::endl;</div>
<div class="line"> std::cout << <span class="stringliteral">"max "</span> << i << <span class="stringliteral">": "</span> << range.maxPosition()[i] << std::endl;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">} <span class="comment">//end of main</span></div>
</div><!-- fragment --></p>
<p>The output is: </p>
<div class="fragment"><div class="line">min 0: 1</div>
<div class="line">max 0: 1</div>
<div class="line">min 1: 3</div>
<div class="line">max 1: 5</div>
</div><!-- fragment --><p> As you can see, the minimum value of dimension one was adjusted in order to make the maximum of <em>1</em> conform with the invariant.</p>
<p><em>DIntervalBase</em> is the closed interval counterpart (and base class) of <em>DRange</em>. Another class derived from <em>DIntervalBase</em> is <em>DBoundingBox</em>. It also represents a closed interval, but differs in the methods. Please have a look at the class documentation for details.</p>
<h1><a class="anchor" id="datastructures_param"></a>
Param</h1>
<p>Most algorithms of OpenMS and some of the TOPP tools have many parameters. The parameters are stored in instances of <em>Param</em>. 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 <em>DataValue</em>. <br/>
Parameter names are given as a string including the sections and subsections in which ':' is used as a delimiter.</p>
<p>The following example (Tutorial_Param.C) shows how a file description is given. <div class="fragment"><div class="line"><a class="code" href="classInt.html">Int</a> <a class="code" href="RNPxl_8C.html#a217dbf8b442f20279ea00b898af96f52">main</a>()</div>
<div class="line">{</div>
<div class="line"> Param param;</div>
<div class="line"></div>
<div class="line"> param.setValue(<span class="stringliteral">"file:name"</span>, <span class="stringliteral">"test.xml"</span>);</div>
<div class="line"> param.setValue(<span class="stringliteral">"file:size(MB)"</span>, 572.3);</div>
<div class="line"> param.setValue(<span class="stringliteral">"file:data:min_int"</span>, 0);</div>
<div class="line"> param.setValue(<span class="stringliteral">"file:data:max_int"</span>, 16459);</div>
<div class="line"></div>
<div class="line"> cout << <span class="stringliteral">"Name : "</span> << (String)(param.getValue(<span class="stringliteral">"file:name"</span>)) << endl;</div>
<div class="line"> cout << <span class="stringliteral">"Size : "</span> << (<a class="code" href="group__Concept.html#gab685845059e8a2c92743427d9a698c70">Real</a>)(param.getValue(<span class="stringliteral">"file:size(MB)"</span>)) << endl;</div>
<div class="line"> cout << <span class="stringliteral">"Min int: "</span> << (<a class="code" href="group__Concept.html#gaba0996d26f7be2572973245b51852757">UInt</a>)(param.getValue(<span class="stringliteral">"file:data:min_int"</span>)) << endl;</div>
<div class="line"> cout << <span class="stringliteral">"Max int: "</span> << (<a class="code" href="group__Concept.html#gaba0996d26f7be2572973245b51852757">UInt</a>)(param.getValue(<span class="stringliteral">"file:data:max_int"</span>)) << endl;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">} <span class="comment">//end of main</span></div>
</div><!-- fragment --> </p>
</div></div><!-- contents -->
<HR style="height:1px; border:none; border-top:1px solid #c0c0c0;">
<TABLE width="100%" border="0">
<TR>
<TD><font color="#c0c0c0">OpenMS / TOPP release 1.11.1</font></TD>
<TD align="right"><font color="#c0c0c0">Documentation generated on Thu Nov 14 2013 11:19:24 using doxygen 1.8.5</font></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|