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  _old_x = event->position().x();
110  _old_y = yAxis->pixelToCoord(event->position().y());
111  if(_old_y < 0)
112  {
113  _old_y = 0;
114  }
115  else
116  {
117  }
118  qDebug() << "QCPXic::mousePressEvent end";
119 }
120 void
121 QCPXic::mouseReleaseEvent(QMouseEvent *event)
122 {
123  qDebug() << "QCPXic::mouseReleaseEvent begin "
124  << xAxis->pixelToCoord(event->position().x()) << " "
125  << yAxis->pixelToCoord(event->position().y());
126  _click = false;
127  if(_mouse_move)
128  {
129  _mouse_move = false;
130  }
131  else
132  {
134  }
135  qDebug() << "QCPXic::mouseReleaseEvent end";
136 }
137 void
138 QCPXic::mouseMoveEvent(QMouseEvent *event)
139 {
140  _mouse_move = true;
141  pappso::pappso_double x = xAxis->pixelToCoord(event->position().x());
142  if(_click)
143  {
144  qDebug() << "QCPXic::mouseMoveEvent begin "
145  << xAxis->pixelToCoord(event->position().x()) << " "
146  << yAxis->pixelToCoord(event->position().y());
147  pappso::pappso_double y = yAxis->pixelToCoord(event->position().y());
148  if(y < 0)
149  {
150  y = 0;
151  }
152  if(_control_key)
153  {
154  if(y > 0)
155  {
156  this->yAxis->scaleRange(_old_y / y, 0);
157  }
158  }
159  else
160  {
161  this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) -
162  xAxis->pixelToCoord(event->position().x()));
163  }
164  _old_x = event->position().x();
165  _old_y = y;
166  replot();
167  qDebug() << "QCPXic::mouseMoveEvent end";
168  }
169  else
170  {
171  if(_map_xic_graph.size() > 0)
172  {
173  // pappso::pappso_double mouse_mz_range = xAxis->pixelToCoord(10) -
174  // xAxis->pixelToCoord(5); getNearestPeakBetween(x, mouse_mz_range);
176  }
177  }
178 }
179 
180 QCPGraph *
181 QCPXic::addXicP(const Xic *xic_p)
182 {
183 
184  _graph_color = _colours[(int)(_map_xic_graph.size() % _colours.size())];
185 
186  QCPGraph *graph_xic = addGraph();
187  graph_xic->setPen(QPen(_graph_color));
188  _map_xic_graph.insert(std::pair<const Xic *, QCPGraph *>(xic_p, graph_xic));
189  graph_xic->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 2.0));
190 
191  if(xic_p->size() > 0)
192  {
193  for(const DataPoint &element : *xic_p)
194  {
195  graph_xic->addData(getRetentionTimeFromSecondsToLocal(element.x),
196  element.y);
197  }
198  if(_rt_range.lower > getRetentionTimeFromSecondsToLocal(xic_p->front().x))
199  _rt_range.lower =
200  getRetentionTimeFromSecondsToLocal(xic_p->front().x) - 1;
201  if(_rt_range.upper < getRetentionTimeFromSecondsToLocal(xic_p->back().x))
202  _rt_range.upper =
203  getRetentionTimeFromSecondsToLocal(xic_p->back().x) + 1;
204  _intensity_range.lower = 0;
205  if(_intensity_range.upper < xic_p->maxYDataPoint().y)
206  _intensity_range.upper = xic_p->maxYDataPoint().y;
207  }
208 
209  return graph_xic;
210 }
211 
212 
213 void
215 {
216 }
217 
218 
219 void
221 {
222  qDebug() << "QCPXic::setMzRangeChanged _rt_range.lower" << _rt_range.lower;
223  if(range.lower < _rt_range.lower)
224  {
225  range.lower = _rt_range.lower;
226  }
227  if(range.upper > _rt_range.upper)
228  {
229  range.upper = _rt_range.upper;
230  }
231 
232  xAxis->setRange(range);
233 }
234 
235 
236 void
238 {
239  _current_ms2_event = new QCPItemTracer(this);
240  // itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
241  // bracketDataSlot for animation
242 
243  _current_ms2_event->setGraph(_map_xic_graph.at(xic_p));
245  _current_ms2_event->setInterpolating(true);
246  _current_ms2_event->setStyle(QCPItemTracer::tsCircle);
247  _current_ms2_event->setPen(QPen(Qt::red));
248  _current_ms2_event->setBrush(Qt::red);
249  _current_ms2_event->setSize(7);
250 
251  // addItem(_current_ms2_event);
252 }
253 
254 void
255 QCPXic::setName(const Xic *xic_p, const QString &name)
256 {
257  _map_xic_graph.at(xic_p)->addToLegend();
258  _map_xic_graph.at(xic_p)->setName(name);
259 }
260 
261 
262 void
264 {
265  legend->clearItems();
266  _map_xic_graph.clear();
267  this->clearGraphs();
268  this->clearItems();
269  this->clearPlottables();
270 }
271 
272 
273 void
275  const Xic *xic_p, const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
276 {
277  for(const pappso::TracePeakCstSPtr &peak : xic_peak_list)
278  {
279  _graph_peak_surface_list.push_back(addGraph());
280  for(auto &xic_element : *(xic_p))
281  {
282  if(peak.get()->containsRt(xic_element.x))
283  {
284  _graph_peak_surface_list.back()->addData(
285  getRetentionTimeFromSecondsToLocal(xic_element.x),
286  xic_element.y);
287  }
288  }
289  // graph()->setData(rt_peak, intensity_peak);
290  _graph_peak_surface_list.back()->removeFromLegend();
291  _graph_peak_surface_list.back()->setChannelFillGraph(0);
292  _graph_peak_surface_list.back()->setLineStyle(
293  QCPGraph::LineStyle::lsLine);
294  QColor color = _colours[_graph_peak_surface_list.size() % 12];
295  color.setAlpha(0);
296  // QColor(0, 110, 110, 30)
297  _graph_peak_surface_list.back()->setPen(QPen(color));
298  color.setAlpha(40);
299  //_graph_peak_surface_list.back()->setScatterStyle(QCPScatterStyle::ssDot);
300  _graph_peak_surface_list.back()->setBrush(QBrush(color));
301  }
302 }
303 
306 {
308  {
309  return rt;
310  }
311  else
312  {
313  return (rt / (pappso::pappso_double)60);
314  }
315 }
316 
319 {
321  {
322  return rt;
323  }
324  else
325  {
326  return (rt * (pappso::pappso_double)60);
327  }
328 }
329 
330 void
332  const Xic *xic_p,
333  const pappso::TracePeak *p_xic_peak)
334 {
335  QCPGraph *p_graph = _map_xic_graph.at(xic_p);
336  QColor color = _colours[i % 12];
337  // color.setAlpha(95);
338 
339  QCPItemTracer *p_peak_border_left = new QCPItemTracer(this);
340  // itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
341  // bracketDataSlot for animation
342  QPen border_pen(color);
343  border_pen.setWidth(3);
344 
345  p_peak_border_left->setGraph(p_graph);
346  p_peak_border_left->setGraphKey(
348  p_peak_border_left->setInterpolating(true);
349  p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
350  p_peak_border_left->setPen(border_pen);
351  p_peak_border_left->setBrush(color);
352  p_peak_border_left->setSize(30);
353 
354  _graph_peak_border_list.push_back(p_peak_border_left);
355 
356  // addItem(p_peak_border_left);
357 
358  QPen apex_pen(color);
359  apex_pen.setWidth(2);
360  p_peak_border_left = new QCPItemTracer(this);
361  p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
362  p_peak_border_left->setGraphKey(
364  p_peak_border_left->setInterpolating(true);
365  p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
366  p_peak_border_left->setPen(apex_pen);
367  p_peak_border_left->setBrush(color);
368  p_peak_border_left->setSize(8);
369 
370  _graph_peak_border_list.push_back(p_peak_border_left);
371 
372  // addItem(p_peak_border_left);
373 
374 
375  p_peak_border_left = new QCPItemTracer(this);
376  p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
377  p_peak_border_left->setGraphKey(
379  p_peak_border_left->setInterpolating(true);
380  p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
381  p_peak_border_left->setPen(border_pen);
382  p_peak_border_left->setBrush(color);
383  p_peak_border_left->setSize(30);
384 
385  _graph_peak_border_list.push_back(p_peak_border_left);
386 
387  // addItem(p_peak_border_left);
388 
389  replot();
390 }
391 
392 void
394 {
395  for(QCPItemTracer *p_tracer : _graph_peak_border_list)
396  {
397  removeItem(p_tracer);
398  // delete p_tracer;
399  }
400  _graph_peak_border_list.clear();
401  replot();
402 }
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:237
void clearXicPeakBorders()
Definition: qcpxic.cpp:393
std::vector< QColor > _colours
Definition: qcpxic.h:88
void clear()
Definition: qcpxic.cpp:263
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:318
void setName(const Xic *xic_p, const QString &name)
Definition: qcpxic.cpp:255
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:220
pappso::pappso_double getRetentionTimeFromSecondsToLocal(pappso::pappso_double rt) const
Definition: qcpxic.cpp:305
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:331
QCPItemTracer * _current_ms2_event
Definition: qcpxic.h:85
virtual void mouseMoveEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:138
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:274
void rescale()
Definition: qcpxic.cpp:214
QColor _graph_color
Definition: qcpxic.h:87
virtual void mouseReleaseEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:121
QCPXic(XicWidget *parent)
Definition: qcpxic.cpp:38
XicWidget * _parent
Definition: qcpxic.h:77
QCPGraph * addXicP(const Xic *xic_p)
Definition: qcpxic.cpp:181
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