libpappsomspp
Library for mass spectrometry
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 
38 namespace 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  : m_mz(mz), m_delta(delta)
58 {
59 }
60 
61 
62 /// Constructs MzRange object using 2 different precisions: lower and upper.
64  PrecisionPtr precision_lower,
65  PrecisionPtr precision_upper)
66 {
67 
68  m_delta = (precision_lower->delta(mz) + precision_upper->delta(mz)) / 2;
69  m_mz = mz - precision_lower->delta(mz) + m_delta;
70 }
71 
72 
74  : m_mz(other.m_mz), m_delta(other.m_delta)
75 {
76  // std::cout << "MzRange::MzRange (const MzRange & other)" << std::endl;
77 }
78 
79 
81 {
82 }
83 
84 
85 MzRange &
87 {
88  m_mz = other.m_mz;
89  m_delta = other.m_delta;
90 
91  return *this;
92 }
93 
94 
95 MzRange &
97 {
98  m_mz += other.m_mz;
99  m_delta += other.m_delta;
100 
101  return *this;
102 }
103 
104 MzRange &
105 MzRange::operator*=(double number)
106 {
107  m_mz *= number;
108  m_delta *= number;
109 
110  return *this;
111 }
112 
115 {
116  return m_mz;
117 }
118 
119 bool
121 {
122  // qDebug() << " " << std::abs(mz - m_mz) << " m_delta:" << m_delta;
123  if(std::abs(mz - m_mz) <= m_delta)
124  {
125  return true;
126  }
127  return false;
128 }
129 
130 QString
132 {
133  // QString s = "mz=" + QString::number(m_mz) + " delta=" +
134  // QString::number(m_delta);
135  return QString("mz=%1 delta=%2 : %3 < %4 < %5")
136  .arg(m_mz)
137  .arg(m_delta)
138  .arg(lower())
139  .arg(m_mz)
140  .arg(upper());
141 }
142 
143 } // namespace pappso
pappso_double getMz() const
Definition: mzrange.cpp:114
MzRange & operator+=(const MzRange &other)
Definition: mzrange.cpp:96
QString toString() const
Definition: mzrange.cpp:131
MzRange & operator=(const MzRange &other)
Definition: mzrange.cpp:86
pappso_double lower() const
Definition: mzrange.h:71
virtual ~MzRange()
Definition: mzrange.cpp:80
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:105
pappso_double m_delta
Definition: mzrange.h:85
pappso_double m_mz
Definition: mzrange.h:80
bool contains(pappso_double) const
Definition: mzrange.cpp:120
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:49