libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
mzrange.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/mass_range.cpp
3 * \date 4/3/2015
4 * \author Olivier Langella
5 * \brief object to handle a mass range (an mz value + or - some delta)
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
10 *
11 * This file is part of the PAPPSOms++ library.
12 *
13 * PAPPSOms++ is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms++ is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Contributors:
27 * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
28 *implementation
29 ******************************************************************************/
30
31#include "mzrange.h"
32#include <QStringList>
33#include <cmath>
34#include <QDebug>
35
36
37namespace pappso
38{
39
40/// Constructs MzRange object using 1 precision (the same for lower or upper
41/// range).
43 : m_mz(mz), m_delta(precision->delta(m_mz))
44{
45}
46
47
48//! Construct a MzRange object with \p mz and \p delta
49/*!
50 *
51 * \p delta should be construed as the whole tolerance such that \c lower()
52 * returns \c m_mz - \c m_delta and \c upper() returns \c m_mz + \c m_delta.
53 *
54 */
56{
57}
58
59
60/// Constructs MzRange object using 2 different precisions: lower and upper.
61MzRange::MzRange(pappso_double mz, PrecisionPtr precision_lower, PrecisionPtr precision_upper)
62{
63
64 m_delta = (precision_lower->delta(mz) + precision_upper->delta(mz)) / 2;
65 m_mz = mz - precision_lower->delta(mz) + m_delta;
66}
67
68
69MzRange::MzRange(const MzRange &other) : m_mz(other.m_mz), m_delta(other.m_delta)
70{
71 // std::cout << "MzRange::MzRange (const MzRange & other)" << std::endl;
72}
73
74
78
79
80MzRange &
82{
83 m_mz = other.m_mz;
84 m_delta = other.m_delta;
85
86 return *this;
87}
88
89
90MzRange &
92{
93 m_mz += other.m_mz;
94 m_delta += other.m_delta;
95
96 return *this;
97}
98
99MzRange &
101{
102 m_mz *= number;
103 m_delta *= number;
104
105 return *this;
106}
107
110{
111 return m_mz;
112}
113
114bool
116{
117 // qDebug() << " " << std::abs(mz - m_mz) << " m_delta:" << m_delta;
118 if(std::abs(mz - m_mz) <= m_delta)
119 {
120 return true;
121 }
122 return false;
123}
124
125QString
127{
128 // QString s = "mz=" + QString::number(m_mz) + " delta=" +
129 // QString::number(m_delta);
130 return QString("mz=%1 delta=%2 : %3 < %4 < %5")
131 .arg(m_mz)
132 .arg(m_delta)
133 .arg(lower())
134 .arg(m_mz)
135 .arg(upper());
136}
137
138} // namespace pappso
pappso_double getMz() const
Definition mzrange.cpp:109
MzRange & operator+=(const MzRange &other)
Definition mzrange.cpp:91
QString toString() const
Definition mzrange.cpp:126
MzRange & operator=(const MzRange &other)
Definition mzrange.cpp:81
pappso_double lower() const
Definition mzrange.h:71
virtual ~MzRange()
Definition mzrange.cpp:75
MzRange(pappso_double mz, PrecisionPtr precision)
Definition mzrange.cpp:42
pappso_double upper() const
Definition mzrange.h:77
MzRange & operator*=(double number)
Definition mzrange.cpp:100
pappso_double m_delta
Definition mzrange.h:85
pappso_double m_mz
Definition mzrange.h:84
bool contains(pappso_double) const
Definition mzrange.cpp:115
virtual pappso_double delta(pappso_double value) const =0
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
double pappso_double
A type definition for doubles.
Definition types.h:60
const PrecisionBase * PrecisionPtr
Definition precision.h:122