libpappsomspp
Library for mass spectrometry
qcpxic.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/widget/xicwidget/qcpxic.cpp
3  * \date 12/1/2018
4  * \author Olivier Langella
5  * \brief custom plot 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 "qcpxic.h"
34 #include "../../processing/detection/tracepeak.h"
35 
36 using namespace pappso;
37 
38 QCPXic::QCPXic(XicWidget *parent) : QCustomPlot(parent)
39 {
40  qDebug() << "QCPXic::QCPXic begin";
41  _parent = parent;
42  setFocusPolicy(Qt::ClickFocus);
43 
45  {
46  xAxis->setLabel("retention time (sec)");
47  }
48  else
49  {
50  xAxis->setLabel("retention time (min)");
51  }
52 
53  yAxis->setLabel("intensity");
54  setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
55  axisRect()->setRangeDrag(Qt::Horizontal);
56  axisRect()->setRangeZoom(Qt::Horizontal);
57 
58  connect(this->xAxis,
59  SIGNAL(rangeChanged(QCPRange)),
60  this,
61  SLOT(setRtRangeChanged(QCPRange)));
62 
63  //
64  // http://tools.medialab.sciences-po.fr/iwanthue/
65  _colours = {QColor(197, 89, 110),
66  QColor(94, 185, 86),
67  QColor(132, 95, 203),
68  QColor(176, 175, 69),
69  QColor(202, 72, 160),
70  QColor(91, 126, 59),
71  QColor(193, 126, 189),
72  QColor(81, 183, 159),
73  QColor(210, 77, 58),
74  QColor(99, 137, 203),
75  QColor(223, 147, 71),
76  QColor(156, 105, 52)};
77 
78  qDebug() << "QCPXic::QCPXic end";
79 }
81 {
82 }
83 void
84 QCPXic::keyPressEvent(QKeyEvent *event)
85 {
86  if(event->key() == Qt::Key_Control)
87  {
88  _control_key = true;
89  }
90  qDebug() << "QCPXic::keyPressEvent end";
91 }
92 
93 void
94 QCPXic::keyReleaseEvent(QKeyEvent *event)
95 {
96  if(event->key() == Qt::Key_Control)
97  {
98  _control_key = false;
99  }
100  qDebug() << "QCPXic::keyReleaseEvent end";
101 }
102 
103 void
104 QCPXic::mousePressEvent(QMouseEvent *event)
105 {
106  qDebug() << " begin ";
107  _mouse_move = false;
108  _click = true;
109 
110 #if QT_VERSION < 0x060000
111  _old_x = event->x();
112  _old_y = yAxis->pixelToCoord(event->y());
113 #else
114  _old_x = event->position().x();
115  _old_y = yAxis->pixelToCoord(event->position().y());
116 #endif
117  if(_old_y < 0)
118  {
119  _old_y = 0;
120  }
121  else
122  {
123  }
124  qDebug() << "QCPXic::mousePressEvent end";
125 }
126 void
127 QCPXic::mouseReleaseEvent(QMouseEvent *event)
128 {
129 
130 #if QT_VERSION < 0x060000
131  qDebug() << "QCPXic::mouseReleaseEvent begin "
132  << xAxis->pixelToCoord(event->x()) << " "
133  << yAxis->pixelToCoord(event->y());
134 #else
135  qDebug() << "QCPXic::mouseReleaseEvent begin "
136  << xAxis->pixelToCoord(event->position().x()) << " "
137  << yAxis->pixelToCoord(event->position().y());
138 #endif
139 
140  _click = false;
141  if(_mouse_move)
142  {
143  _mouse_move = false;
144  }
145  else
146  {
148  }
149  qDebug() << "QCPXic::mouseReleaseEvent end";
150 }
151 void
152 QCPXic::mouseMoveEvent(QMouseEvent *event)
153 {
154  _mouse_move = true;
155 
156 #if QT_VERSION < 0x060000
157  pappso::pappso_double x = xAxis->pixelToCoord(event->x());
158 #else
159  pappso::pappso_double x = xAxis->pixelToCoord(event->position().x());
160 #endif
161  if(_click)
162  {
163 
164 #if QT_VERSION < 0x060000
165  qDebug() << "QCPXic::mouseMoveEvent begin "
166  << xAxis->pixelToCoord(event->x()) << " "
167  << yAxis->pixelToCoord(event->y());
168  pappso::pappso_double y = yAxis->pixelToCoord(event->y());
169 #else
170  qDebug() << "QCPXic::mouseMoveEvent begin "
171  << xAxis->pixelToCoord(event->position().x()) << " "
172  << yAxis->pixelToCoord(event->position().y());
173  pappso::pappso_double y = yAxis->pixelToCoord(event->position().y());
174 #endif
175  if(y < 0)
176  {
177  y = 0;
178  }
179  if(_control_key)
180  {
181  if(y > 0)
182  {
183  this->yAxis->scaleRange(_old_y / y, 0);
184  }
185  }
186  else
187  {
188 
189 #if QT_VERSION < 0x060000
190  this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) -
191  xAxis->pixelToCoord(event->x()));
192 #else
193  this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) -
194  xAxis->pixelToCoord(event->position().x()));
195 #endif
196  }
197 
198 #if QT_VERSION < 0x060000
199  _old_x = event->x();
200 #else
201  _old_x = event->position().x();
202 #endif
203  _old_y = y;
204  replot();
205  qDebug() << "QCPXic::mouseMoveEvent end";
206  }
207  else
208  {
209  if(_map_xic_graph.size() > 0)
210  {
211  // pappso::pappso_double mouse_mz_range = xAxis->pixelToCoord(10) -
212  // xAxis->pixelToCoord(5); getNearestPeakBetween(x, mouse_mz_range);
214  }
215  }
216 }
217 
218 QCPGraph *
219 QCPXic::addXicP(const Xic *xic_p)
220 {
221 
222  _graph_color = _colours[(int)(_map_xic_graph.size() % _colours.size())];
223 
224  QCPGraph *graph_xic = addGraph();
225  graph_xic->setPen(QPen(_graph_color));
226  _map_xic_graph.insert(std::pair<const Xic *, QCPGraph *>(xic_p, graph_xic));
227  graph_xic->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 2.0));
228 
229  if(xic_p->size() > 0)
230  {
231  for(const DataPoint &element : *xic_p)
232  {
233  graph_xic->addData(getRetentionTimeFromSecondsToLocal(element.x),
234  element.y);
235  }
236  if(_rt_range.lower > getRetentionTimeFromSecondsToLocal(xic_p->front().x))
237  _rt_range.lower =
238  getRetentionTimeFromSecondsToLocal(xic_p->front().x) - 1;
239  if(_rt_range.upper < getRetentionTimeFromSecondsToLocal(xic_p->back().x))
240  _rt_range.upper =
241  getRetentionTimeFromSecondsToLocal(xic_p->back().x) + 1;
242  _intensity_range.lower = 0;
243  if(_intensity_range.upper < xic_p->maxYDataPoint().y)
244  _intensity_range.upper = xic_p->maxYDataPoint().y;
245  }
246 
247  return graph_xic;
248 }
249 
250 
251 void
253 {
254 }
255 
256 
257 void
259 {
260  qDebug() << "QCPXic::setMzRangeChanged _rt_range.lower" << _rt_range.lower;
261  if(range.lower < _rt_range.lower)
262  {
263  range.lower = _rt_range.lower;
264  }
265  if(range.upper > _rt_range.upper)
266  {
267  range.upper = _rt_range.upper;
268  }
269 
270  xAxis->setRange(range);
271 }
272 
273 
274 void
276 {
277  _current_ms2_event = new QCPItemTracer(this);
278  // itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
279  // bracketDataSlot for animation
280 
281  _current_ms2_event->setGraph(_map_xic_graph.at(xic_p));
283  _current_ms2_event->setInterpolating(true);
284  _current_ms2_event->setStyle(QCPItemTracer::tsCircle);
285  _current_ms2_event->setPen(QPen(Qt::red));
286  _current_ms2_event->setBrush(Qt::red);
287  _current_ms2_event->setSize(7);
288 
289  // addItem(_current_ms2_event);
290 }
291 
292 void
293 QCPXic::setName(const Xic *xic_p, const QString &name)
294 {
295  _map_xic_graph.at(xic_p)->addToLegend();
296  _map_xic_graph.at(xic_p)->setName(name);
297 }
298 
299 
300 void
302 {
303  legend->clearItems();
304  _map_xic_graph.clear();
305  this->clearGraphs();
306  this->clearItems();
307  this->clearPlottables();
308 }
309 
310 
311 void
313  const Xic *xic_p, const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
314 {
315  for(const pappso::TracePeakCstSPtr &peak : xic_peak_list)
316  {
317  _graph_peak_surface_list.push_back(addGraph());
318  for(auto &xic_element : *(xic_p))
319  {
320  if(peak.get()->containsRt(xic_element.x))
321  {
322  _graph_peak_surface_list.back()->addData(
323  getRetentionTimeFromSecondsToLocal(xic_element.x),
324  xic_element.y);
325  }
326  }
327  // graph()->setData(rt_peak, intensity_peak);
328  _graph_peak_surface_list.back()->removeFromLegend();
329  _graph_peak_surface_list.back()->setChannelFillGraph(0);
330  _graph_peak_surface_list.back()->setLineStyle(
331  QCPGraph::LineStyle::lsLine);
332  QColor color = _colours[_graph_peak_surface_list.size() % 12];
333  color.setAlpha(0);
334  // QColor(0, 110, 110, 30)
335  _graph_peak_surface_list.back()->setPen(QPen(color));
336  color.setAlpha(40);
337  //_graph_peak_surface_list.back()->setScatterStyle(QCPScatterStyle::ssDot);
338  _graph_peak_surface_list.back()->setBrush(QBrush(color));
339  }
340 }
341 
344 {
346  {
347  return rt;
348  }
349  else
350  {
351  return (rt / (pappso::pappso_double)60);
352  }
353 }
354 
357 {
359  {
360  return rt;
361  }
362  else
363  {
364  return (rt * (pappso::pappso_double)60);
365  }
366 }
367 
368 void
370  const Xic *xic_p,
371  const pappso::TracePeak *p_xic_peak)
372 {
373  QCPGraph *p_graph = _map_xic_graph.at(xic_p);
374  QColor color = _colours[i % 12];
375  // color.setAlpha(95);
376 
377  QCPItemTracer *p_peak_border_left = new QCPItemTracer(this);
378  // itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
379  // bracketDataSlot for animation
380  QPen border_pen(color);
381  border_pen.setWidth(3);
382 
383  p_peak_border_left->setGraph(p_graph);
384  p_peak_border_left->setGraphKey(
386  p_peak_border_left->setInterpolating(true);
387  p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
388  p_peak_border_left->setPen(border_pen);
389  p_peak_border_left->setBrush(color);
390  p_peak_border_left->setSize(30);
391 
392  _graph_peak_border_list.push_back(p_peak_border_left);
393 
394  // addItem(p_peak_border_left);
395 
396  QPen apex_pen(color);
397  apex_pen.setWidth(2);
398  p_peak_border_left = new QCPItemTracer(this);
399  p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
400  p_peak_border_left->setGraphKey(
402  p_peak_border_left->setInterpolating(true);
403  p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
404  p_peak_border_left->setPen(apex_pen);
405  p_peak_border_left->setBrush(color);
406  p_peak_border_left->setSize(8);
407 
408  _graph_peak_border_list.push_back(p_peak_border_left);
409 
410  // addItem(p_peak_border_left);
411 
412 
413  p_peak_border_left = new QCPItemTracer(this);
414  p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
415  p_peak_border_left->setGraphKey(
417  p_peak_border_left->setInterpolating(true);
418  p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
419  p_peak_border_left->setPen(border_pen);
420  p_peak_border_left->setBrush(color);
421  p_peak_border_left->setSize(30);
422 
423  _graph_peak_border_list.push_back(p_peak_border_left);
424 
425  // addItem(p_peak_border_left);
426 
427  replot();
428 }
429 
430 void
432 {
433  for(QCPItemTracer *p_tracer : _graph_peak_border_list)
434  {
435  removeItem(p_tracer);
436  // delete p_tracer;
437  }
438  _graph_peak_border_list.clear();
439  replot();
440 }
bool _click
Definition: qcpxic.h:80
virtual void keyPressEvent(QKeyEvent *event) override
Definition: qcpxic.cpp:84
bool _mouse_move
Definition: qcpxic.h:81
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition: qcpxic.cpp:275
void clearXicPeakBorders()
Definition: qcpxic.cpp:431
std::vector< QColor > _colours
Definition: qcpxic.h:88
void clear()
Definition: qcpxic.cpp:301
std::vector< QCPItemTracer * > _graph_peak_border_list
Definition: qcpxic.h:90
bool _control_key
Definition: qcpxic.h:82
pappso::pappso_double _old_y
Definition: qcpxic.h:84
QCPRange _rt_range
Definition: qcpxic.h:78
pappso::pappso_double xAxisToSeconds(pappso::pappso_double rt) const
Definition: qcpxic.cpp:356
void setName(const Xic *xic_p, const QString &name)
Definition: qcpxic.cpp:293
QCPRange _intensity_range
Definition: qcpxic.h:79
pappso::pappso_double _old_x
Definition: qcpxic.h:83
std::vector< QCPGraph * > _graph_peak_surface_list
Definition: qcpxic.h:89
std::map< const Xic *, QCPGraph * > _map_xic_graph
Definition: qcpxic.h:86
Q_SLOT void setRtRangeChanged(QCPRange range)
Definition: qcpxic.cpp:258
pappso::pappso_double getRetentionTimeFromSecondsToLocal(pappso::pappso_double rt) const
Definition: qcpxic.cpp:343
virtual void mousePressEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:104
void drawXicPeakBorders(unsigned int i, const Xic *xic_p, const pappso::TracePeak *p_xic_peak)
Definition: qcpxic.cpp:369
QCPItemTracer * _current_ms2_event
Definition: qcpxic.h:85
virtual void mouseMoveEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:152
virtual void keyReleaseEvent(QKeyEvent *event) override
Definition: qcpxic.cpp:94
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition: qcpxic.cpp:312
void rescale()
Definition: qcpxic.cpp:252
QColor _graph_color
Definition: qcpxic.h:87
virtual void mouseReleaseEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:127
QCPXic(XicWidget *parent)
Definition: qcpxic.cpp:38
XicWidget * _parent
Definition: qcpxic.h:77
QCPGraph * addXicP(const Xic *xic_p)
Definition: qcpxic.cpp:219
DataPoint & getLeftBoundary()
Definition: tracepeak.cpp:93
DataPoint & getMaxXicElement()
Definition: tracepeak.cpp:83
DataPoint & getRightBoundary()
Definition: tracepeak.cpp:104
void rtChangeEvent(pappso::pappso_double rt) const
Definition: xicwidget.cpp:165
void xicClickEvent(pappso::pappso_double rt, pappso::pappso_double intensity) const
Definition: xicwidget.cpp:243
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
@ rt
Retention time.
std::shared_ptr< const TracePeak > TracePeakCstSPtr
Definition: tracepeak.h:34
custom plot XIC
pappso_double x
Definition: datapoint.h:23