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"
33#include <QStringList>
34#include <cmath>
35#include <QDebug>
36
37
38namespace pappso
39{
40
41/// Constructs MzRange object using 1 precision (the same for lower or upper
42/// range).
44 : m_mz(mz), m_delta(precision->delta(m_mz))
45{
46}
47
48
49//! Construct a MzRange object with \p mz and \p delta
50/*!
51 *
52 * \p delta should be construed as the whole tolerance such that \c lower()
53 * returns \c m_mz - \c m_delta and \c upper() returns \c m_mz + \c m_delta.
54 *
55 */
57{
58}
59
60
61/// Constructs MzRange object using 2 different precisions: lower and upper.
62MzRange::MzRange(pappso_double mz, PrecisionPtr precision_lower, PrecisionPtr precision_upper)
63{
64
65 m_delta = (precision_lower->delta(mz) + precision_upper->delta(mz)) / 2;
66 m_mz = mz - precision_lower->delta(mz) + m_delta;
67}
68
69
70MzRange::MzRange(const MzRange &other) : m_mz(other.m_mz), m_delta(other.m_delta)
71{
72 // std::cout << "MzRange::MzRange (const MzRange & other)" << std::endl;
73}
74
75
79
80
81MzRange &
83{
84 m_mz = other.m_mz;
85 m_delta = other.m_delta;
86
87 return *this;
88}
89
90
91MzRange &
93{
94 m_mz += other.m_mz;
95 m_delta += other.m_delta;
96
97 return *this;
98}
99
100MzRange &
102{
103 m_mz *= number;
104 m_delta *= number;
105
106 return *this;
107}
108
111{
112 return m_mz;
113}
114
115bool
117{
118 // qDebug() << " " << std::abs(mz - m_mz) << " m_delta:" << m_delta;
119 if(std::abs(mz - m_mz) <= m_delta)
120 {
121 return true;
122 }
123 return false;
124}
125
126QString
128{
129 // QString s = "mz=" + QString::number(m_mz) + " delta=" +
130 // QString::number(m_delta);
131 return QString("mz=%1 delta=%2 : %3 < %4 < %5")
132 .arg(m_mz)
133 .arg(m_delta)
134 .arg(lower())
135 .arg(m_mz)
136 .arg(upper());
137}
138
139} // namespace pappso
pappso_double getMz() const
Definition mzrange.cpp:110
MzRange & operator+=(const MzRange &other)
Definition mzrange.cpp:92
QString toString() const
Definition mzrange.cpp:127
MzRange & operator=(const MzRange &other)
Definition mzrange.cpp:82
pappso_double lower() const
Definition mzrange.h:71
virtual ~MzRange()
Definition mzrange.cpp:76
MzRange(pappso_double mz, PrecisionPtr precision)
Definition mzrange.cpp:43
pappso_double upper() const
Definition mzrange.h:77
MzRange & operator*=(double number)
Definition mzrange.cpp:101
pappso_double m_delta
Definition mzrange.h:85
pappso_double m_mz
Definition mzrange.h:84
bool contains(pappso_double) const
Definition mzrange.cpp:116
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