| OpenMS 2.5.0

BernNorm.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-2020.
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: Mathias Walzer $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 //
35 #pragma once
36
37 #include <OpenMS/KERNEL/StandardTypes.h>
38
39 #include <OpenMS/DATASTRUCTURES/DefaultParamHandler.h>
40
41 #include <map>
42
43 namespace OpenMS
44 {
56 class OPENMS_DLLAPI BernNorm :
57 public DefaultParamHandler
58 {
59 public:
60
61 // @name Constructors and Destructors
63 BernNorm();
65
67 BernNorm(const BernNorm & source);
68
70 ~BernNorm() override;
72
73 // @name Operators
74 // @{
76 BernNorm & operator=(const BernNorm & source);
78
79 // @name Accessors
80 // @{
81
83 template <typename SpectrumType>
84 void filterSpectrum(SpectrumType & spectrum)
85 {
86 typedef typename SpectrumType::Iterator Iterator;
87 typedef typename SpectrumType::ConstIterator ConstIterator;
88
89 c1_ = (double)param_.getValue("C1");
90 c2_ = (double)param_.getValue("C2");
91 th_ = (double)param_.getValue("threshold");
92
93 spectrum.sortByPosition();
94
95 // find highest peak and ranking
96 double maxint = 0;
97 std::map<double, Size> peakranks;
98 for (ConstIterator it = spectrum.begin(); it != spectrum.end(); ++it)
99 {
100 peakranks[it->getIntensity()] = 0;
101 if (it->getIntensity() > maxint)
102 {
103 maxint = it->getIntensity();
104 }
105 }
106 UInt rank = 0;
107 for (std::map<double, Size>::reverse_iterator mit = peakranks.rbegin(); mit != peakranks.rend(); ++mit)
108 {
109 mit->second = ++rank;
110 }
111
112 // find maxmz i.e. significant (> threshold * maxpeak) peak with highest m/z
113 double maxmz = 0;
114 for (SignedSize i = spectrum.size() - 1; i >= 0; --i)
115 {
116 if (spectrum[i].getIntensity() > maxint * th_)
117 {
118 maxmz = spectrum[i].getMZ();
119 break;
120 }
121 }
122
123 // rank
124 for (Iterator it = spectrum.begin(); it != spectrum.end(); )
125 {
126 double newint = c1_ - (c2_ / maxmz) * peakranks[it->getIntensity()];
127 if (newint < 0)
128 {
129 it = spectrum.erase(it);
130 }
131 else
132 {
133 it->setIntensity(newint);
134 ++it;
135 }
136 }
137 return;
138 }
139
140 void filterPeakSpectrum(PeakSpectrum & spectrum);
141
142 void filterPeakMap(PeakMap & exp);
143 //TODO reimplement DefaultParamHandler::updateMembers_()
144
145 private:
146 double c1_;
147 double c2_;
148 double th_;
149
150 // @}
151
152 };
153
154 } // namespace OpenMS
155
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::BernNorm::filterSpectrum
void filterSpectrum(SpectrumType &spectrum)
Definition: BernNorm.h:84
OpenMS::DefaultParamHandler
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:91
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::MSSpectrum::Iterator
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:102
StandardTypes.h
OpenMS::BernNorm::c2_
double c2_
Definition: BernNorm.h:147
Iterator
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::BernNorm
BernNorm scales the peaks by ranking them and then scaling them according to rank.
Definition: BernNorm.h:56
OpenMS::BernNorm::th_
double th_
Definition: BernNorm.h:148
DefaultParamHandler.h
OpenMS::MSSpectrum::ConstIterator
ContainerType::const_iterator ConstIterator
Non-mutable iterator.
Definition: MSSpectrum.h:104
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
double
OpenMS::MSSpectrum::sortByPosition
void sortByPosition()
Lexicographically sorts the peaks by their position.
OpenMS::BernNorm::c1_
double c1_
Definition: BernNorm.h:146