libpappsomspp
Library for mass spectrometry
xicwidget.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/widget/xicwidget/xicwidget.h
3  * \date 12/1/2018
4  * \author Olivier Langella
5  * \brief plot a XIC
6  */
7 
8 
9 /*******************************************************************************
10  * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
11  *
12  * This file is part of the PAPPSOms++ library.
13  *
14  * PAPPSOms++ is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * PAPPSOms++ is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
26  *
27  * Contributors:
28  * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
29  *implementation
30  ******************************************************************************/
31 
32 
33 #include "xicwidget.h"
34 #include <QDebug>
35 #include <QHBoxLayout>
36 #include "qcpxic.h"
37 #include "../../exception/exceptionnotfound.h"
38 
39 using namespace pappso;
40 
41 XicWidget::XicWidget(QWidget *parent) : GraphicDeviceWidget(parent)
42 {
43  qDebug() << "XicWidget::XicWidget begin";
44 
45 
46  this->setLayout(new QHBoxLayout(this));
47 
48  setMinimumSize(200, 160);
49  this->layout()->setContentsMargins(0, 0, 0, 0);
50 
51  _qcp_xic = new QCPXic(this);
52  this->layout()->addWidget(_qcp_xic);
53  qDebug() << "XicWidget::XicWidget end";
54 }
56 {
57 }
58 
59 void
61 {
62  XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
63  _qcp_xic->addMsMsEvent(xic_p, rt);
64  _map_xic_msms_event[xic_p] = rt;
65 }
66 QCPGraph *
68 {
69  _xic_sp_list.push_back(xic_sp);
70  return _qcp_xic->addXicP(xic_sp.get());
71 }
72 
73 const QString &
74 XicWidget::getName(const Xic *xic_p) const
75 {
76  XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
77  return _map_xic_name.at(xic_p);
78 }
79 
80 void
81 XicWidget::setName(const Xic *xic_p, const QString &name)
82 {
83  XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
84  _qcp_xic->legend->setVisible(true);
85  _qcp_xic->setName(xic_p, name);
86  _map_xic_name[xic_p] = name;
87 }
88 
89 void
91 {
92  _qcp_xic->replot();
93 }
94 void
96 {
97  _qcp_xic->xAxis->rescale(true);
98  _qcp_xic->yAxis->rescale(true);
99  _qcp_xic->rescale();
100 }
101 
102 QCPAxis *
104 {
105  return _qcp_xic->xAxis;
106 }
107 
108 QCPAxis *
110 {
111  return _qcp_xic->yAxis;
112 }
113 
114 void
115 XicWidget::rescaleOneRange(QString axis_name, QCPRange new_range)
116 {
117  if(axis_name == "xAxis")
118  {
119  _qcp_xic->xAxis->setRange(new_range);
120  }
121  else // axis_name == "yAxis"
122  {
123  _qcp_xic->yAxis->setRange(new_range);
124  }
125  _qcp_xic->replot();
126 }
127 
128 void
130 {
131  _map_xic_name.clear();
132  _xic_sp_list.clear();
133  _xic_peak_sp_list.clear();
134  _qcp_xic->clear();
135  _map_xic_msms_event.clear();
136 }
137 
139 XicWidget::getXicCstSPtr(const Xic *xic_p) const
140 {
141  std::vector<XicCstSPtr>::const_iterator it =
142  std::find_if(_xic_sp_list.begin(),
143  _xic_sp_list.end(),
144  [xic_p](XicCstSPtr xic_sp) { return xic_sp.get() == xic_p; });
145  if(it == _xic_sp_list.end())
146  {
147  throw pappso::ExceptionNotFound(tr("ERROR : xic pointer not found"));
148  }
149  return *it;
150 }
151 
152 void
154  const Xic *xic_p, const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
155 {
156  XicCstSPtr xic_sp = getXicCstSPtr(xic_p);
157  _qcp_xic->addXicPeakList(xic_p, xic_peak_list);
158  for(const pappso::TracePeakCstSPtr &xic_peak : xic_peak_list)
159  {
160  _xic_peak_sp_list.push_back(
161  std::pair<XicCstSPtr, TracePeakCstSPtr>(xic_sp, xic_peak));
162  }
163 }
164 void
166 {
167  emit rtChanged(rt);
168 
169  std::vector<std::pair<XicCstSPtr, TracePeakCstSPtr>> over_xic_peak_list;
170  for(std::pair<XicCstSPtr, TracePeakCstSPtr> pair_xic_peak : _xic_peak_sp_list)
171  {
172  if(pair_xic_peak.second.get()->containsRt(rt))
173  {
174  over_xic_peak_list.push_back(pair_xic_peak);
175  }
176  }
177 
178  // if (over_xic_peak_list.size() > 0) {
179  emit xicPeakListChanged(over_xic_peak_list);
180  //}
181 }
182 
183 void
184 XicWidget::toQPaintDevice(QPaintDevice *device, const QSize &size)
185 {
186 
187  if(_qcp_xic != nullptr)
188  {
189  QCPPainter painter;
190  painter.begin(device);
191  _qcp_xic->toPainter(&painter, size.width(), size.height());
192  painter.end();
193  }
194 }
195 
196 
197 void
199 {
200  _rt_in_seconds = true;
201  _qcp_xic->xAxis->setLabel("retention time (sec)");
202  replotAll();
203 }
204 void
206 {
207  _rt_in_seconds = false;
208  _qcp_xic->xAxis->setLabel("retention time (min)");
209  replotAll();
210 }
211 
212 void
214 {
215  _qcp_xic->clear();
216 
217  for(XicCstSPtr xic_sp : _xic_sp_list)
218  {
219  _qcp_xic->addXicP(xic_sp.get());
220 
221  std::vector<TracePeakCstSPtr> xic_peak_list;
222  for(auto xic_map_peak_list : _xic_peak_sp_list)
223  {
224  if(xic_map_peak_list.first.get() == xic_sp.get())
225  xic_peak_list.push_back(xic_map_peak_list.second);
226  }
227  _qcp_xic->addXicPeakList(xic_sp.get(), xic_peak_list);
228  }
229  for(auto xic_name : _map_xic_name)
230  {
231  setName(xic_name.first, xic_name.second);
232  }
233  for(auto xic_msms : _map_xic_msms_event)
234  {
235  _qcp_xic->addMsMsEvent(xic_msms.first, xic_msms.second);
236  }
237 
238  rescale();
239  _qcp_xic->replot();
240 }
241 
242 void
244  pappso::pappso_double intensity) const
245 {
246  emit clicked(rt, intensity);
247 }
248 
249 
250 void
252 {
253  XicCstSPtr xic_sp;
254  for(std::pair<XicCstSPtr, TracePeakCstSPtr> pair_xic_peak : _xic_peak_sp_list)
255  {
256  if(pair_xic_peak.second.get() == xic_peak.get())
257  {
258  xic_sp = pair_xic_peak.first;
259  break;
260  }
261  }
262 
263  if(xic_sp.get() != nullptr)
264  {
265 
266  unsigned int i = 0;
267  for(XicCstSPtr xic_in_list : _xic_sp_list)
268  {
269  if(xic_in_list.get() == xic_sp.get())
270  {
271  break;
272  }
273  i++;
274  }
275  _qcp_xic->drawXicPeakBorders(i, xic_sp.get(), xic_peak.get());
276  }
277 }
278 
279 
280 void
282 {
284 }
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition: qcpxic.cpp:275
void clearXicPeakBorders()
Definition: qcpxic.cpp:431
void clear()
Definition: qcpxic.cpp:301
void setName(const Xic *xic_p, const QString &name)
Definition: qcpxic.cpp:293
void drawXicPeakBorders(unsigned int i, const Xic *xic_p, const pappso::TracePeak *p_xic_peak)
Definition: qcpxic.cpp:369
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition: qcpxic.cpp:312
void rescale()
Definition: qcpxic.cpp:252
QCPGraph * addXicP(const Xic *xic_p)
Definition: qcpxic.cpp:219
friend class QCPXic
Definition: xicwidget.h:89
void toQPaintDevice(QPaintDevice *device, const QSize &size) override
Definition: xicwidget.cpp:184
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition: xicwidget.cpp:153
void rtChanged(double rt) const
announce the current retention time (under mouse) in seconds
QCPAxis * getIntensityAxisP()
Definition: xicwidget.cpp:109
std::vector< XicCstSPtr > _xic_sp_list
Definition: xicwidget.h:102
void clearXicPeakBorders()
Definition: xicwidget.cpp:281
XicCstSPtr getXicCstSPtr(const Xic *xic_p) const
Definition: xicwidget.cpp:139
XicXicPeakPairList _xic_peak_sp_list
Definition: xicwidget.h:103
std::map< const Xic *, QString > _map_xic_name
Definition: xicwidget.h:100
XicWidget(QWidget *parent=0)
Definition: xicwidget.cpp:41
void setRetentionTimeInMinutes()
Definition: xicwidget.cpp:205
const QString & getName(const Xic *xic_p) const
Definition: xicwidget.cpp:74
void rtChangeEvent(pappso::pappso_double rt) const
Definition: xicwidget.cpp:165
QCPGraph * addXicSp(XicCstSPtr xic_sp)
Definition: xicwidget.cpp:67
std::map< const Xic *, pappso::pappso_double > _map_xic_msms_event
Definition: xicwidget.h:101
QCPAxis * getRtAxisP()
get the plots axis and rescale one axis with the given range
Definition: xicwidget.cpp:103
void xicPeakListChanged(pappso::XicXicPeakPairList xic_peak_list) const
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition: xicwidget.cpp:60
void setName(const Xic *xic_p, const QString &name)
Definition: xicwidget.cpp:81
void clicked(double rt, double intensity) const
announce mouse position on click (rt in seconds, intensity)
void rescaleOneRange(QString axis_name, QCPRange new_range)
Definition: xicwidget.cpp:115
void drawXicPeakBorders(pappso::TracePeakCstSPtr xic_peak)
Definition: xicwidget.cpp:251
void xicClickEvent(pappso::pappso_double rt, pappso::pappso_double intensity) const
Definition: xicwidget.cpp:243
QCPXic * _qcp_xic
Definition: xicwidget.h:104
void setRetentionTimeInSeconds()
Definition: xicwidget.cpp:198
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const Xic > XicCstSPtr
Definition: xic.h:37
double pappso_double
A type definition for doubles.
Definition: types.h:49
@ rt
Retention time.
std::shared_ptr< const TracePeak > TracePeakCstSPtr
Definition: tracepeak.h:34
custom plot XIC
plot a XIC