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