qcpxic.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/widget/xicwidget/qcpxic.cpp
* \date 12/1/2018
* \author Olivier Langella
* \brief custom plot XIC
*/
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
*implementation
******************************************************************************/
#include "qcpxic.h"
#include "../../processing/detection/tracepeak.h"
using namespace pappso;
QCPXic::QCPXic(XicWidget *parent) : QCustomPlot(parent)
{
qDebug() << "QCPXic::QCPXic begin";
_parent = parent;
setFocusPolicy(Qt::ClickFocus);
if(_parent->_rt_in_seconds)
{
xAxis->setLabel("retention time (sec)");
}
else
{
xAxis->setLabel("retention time (min)");
}
yAxis->setLabel("intensity");
setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
axisRect()->setRangeDrag(Qt::Horizontal);
axisRect()->setRangeZoom(Qt::Horizontal);
connect(this->xAxis,
SIGNAL(rangeChanged(QCPRange)),
this,
SLOT(setRtRangeChanged(QCPRange)));
//
// http://tools.medialab.sciences-po.fr/iwanthue/
_colours = {QColor(197, 89, 110),
QColor(94, 185, 86),
QColor(132, 95, 203),
QColor(176, 175, 69),
QColor(202, 72, 160),
QColor(91, 126, 59),
QColor(193, 126, 189),
QColor(81, 183, 159),
QColor(210, 77, 58),
QColor(99, 137, 203),
QColor(223, 147, 71),
QColor(156, 105, 52)};
qDebug() << "QCPXic::QCPXic end";
}
QCPXic::~QCPXic()
{
}
void
QCPXic::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Control)
{
_control_key = true;
}
qDebug() << "QCPXic::keyPressEvent end";
}
void
QCPXic::keyReleaseEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Control)
{
_control_key = false;
}
qDebug() << "QCPXic::keyReleaseEvent end";
}
void
QCPXic::mousePressEvent(QMouseEvent *event)
{
qDebug() << "QCPXic::mousePressEvent begin "
<< xAxis->pixelToCoord(event->x()) << " "
<< yAxis->pixelToCoord(event->y());
_mouse_move = false;
_click = true;
_old_x = event->x();
_old_y = yAxis->pixelToCoord(event->y());
if(_old_y < 0)
{
_old_y = 0;
}
else
{
}
qDebug() << "QCPXic::mousePressEvent end";
}
void
QCPXic::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << "QCPXic::mouseReleaseEvent begin "
<< xAxis->pixelToCoord(event->x()) << " "
<< yAxis->pixelToCoord(event->y());
_click = false;
if(_mouse_move)
{
_mouse_move = false;
}
else
{
_parent->xicClickEvent(xAxisToSeconds(_old_x), _old_y);
}
qDebug() << "QCPXic::mouseReleaseEvent end";
}
void
QCPXic::mouseMoveEvent(QMouseEvent *event)
{
_mouse_move = true;
pappso::pappso_double x = xAxis->pixelToCoord(event->x());
if(_click)
{
qDebug() << "QCPXic::mouseMoveEvent begin "
<< xAxis->pixelToCoord(event->x()) << " "
<< yAxis->pixelToCoord(event->y());
pappso::pappso_double y = yAxis->pixelToCoord(event->y());
if(y < 0)
{
y = 0;
}
if(_control_key)
{
if(y > 0)
{
this->yAxis->scaleRange(_old_y / y, 0);
}
}
else
{
this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) -
xAxis->pixelToCoord(event->x()));
}
_old_x = event->x();
_old_y = y;
replot();
qDebug() << "QCPXic::mouseMoveEvent end";
}
else
{
if(_map_xic_graph.size() > 0)
{
// pappso::pappso_double mouse_mz_range = xAxis->pixelToCoord(10) -
// xAxis->pixelToCoord(5); getNearestPeakBetween(x, mouse_mz_range);
_parent->rtChangeEvent(xAxisToSeconds(x));
}
}
}
void
QCPXic::addXicP(const Xic *xic_p)
{
_graph_color = _colours[(int)(_map_xic_graph.size() % _colours.size())];
QCPGraph *graph_xic = addGraph();
graph_xic->setPen(QPen(_graph_color));
_map_xic_graph.insert(std::pair<const Xic *, QCPGraph *>(xic_p, graph_xic));
graph_xic->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, 2.0));
if(xic_p->size() > 0)
{
for(const DataPoint &element : *xic_p)
{
graph_xic->addData(getRetentionTimeFromSecondsToLocal(element.x),
element.y);
}
if(_rt_range.lower > getRetentionTimeFromSecondsToLocal(xic_p->front().x))
_rt_range.lower =
getRetentionTimeFromSecondsToLocal(xic_p->front().x) - 1;
if(_rt_range.upper < getRetentionTimeFromSecondsToLocal(xic_p->back().x))
_rt_range.upper =
getRetentionTimeFromSecondsToLocal(xic_p->back().x) + 1;
_intensity_range.lower = 0;
if(_intensity_range.upper < xic_p->maxYDataPoint().y)
_intensity_range.upper = xic_p->maxYDataPoint().y;
}
}
void
QCPXic::rescale()
{
}
void
QCPXic::setRtRangeChanged(QCPRange range)
{
qDebug() << "QCPXic::setMzRangeChanged _rt_range.lower" << _rt_range.lower;
if(range.lower < _rt_range.lower)
{
range.lower = _rt_range.lower;
}
if(range.upper > _rt_range.upper)
{
range.upper = _rt_range.upper;
}
xAxis->setRange(range);
}
void
QCPXic::addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
{
_current_ms2_event = new QCPItemTracer(this);
// itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
// bracketDataSlot for animation
_current_ms2_event->setGraph(_map_xic_graph.at(xic_p));
_current_ms2_event->setGraphKey(getRetentionTimeFromSecondsToLocal(rt));
_current_ms2_event->setInterpolating(true);
_current_ms2_event->setStyle(QCPItemTracer::tsCircle);
_current_ms2_event->setPen(QPen(Qt::red));
_current_ms2_event->setBrush(Qt::red);
_current_ms2_event->setSize(7);
// addItem(_current_ms2_event);
}
void
QCPXic::setName(const Xic *xic_p, const QString &name)
{
_map_xic_graph.at(xic_p)->addToLegend();
_map_xic_graph.at(xic_p)->setName(name);
}
void
QCPXic::clear()
{
legend->clearItems();
_map_xic_graph.clear();
this->clearGraphs();
this->clearItems();
this->clearPlottables();
}
void
QCPXic::addXicPeakList(
const Xic *xic_p, const std::vector<pappso::TracePeakCstSPtr> &xic_peak_list)
{
for(const pappso::TracePeakCstSPtr &peak : xic_peak_list)
{
_graph_peak_surface_list.push_back(addGraph());
for(auto &xic_element : *(xic_p))
{
if(peak.get()->containsRt(xic_element.x))
{
_graph_peak_surface_list.back()->addData(
getRetentionTimeFromSecondsToLocal(xic_element.x),
xic_element.y);
}
}
// graph()->setData(rt_peak, intensity_peak);
_graph_peak_surface_list.back()->removeFromLegend();
_graph_peak_surface_list.back()->setChannelFillGraph(0);
_graph_peak_surface_list.back()->setLineStyle(
QCPGraph::LineStyle::lsLine);
QColor color = _colours[_graph_peak_surface_list.size() % 12];
color.setAlpha(0);
// QColor(0, 110, 110, 30)
_graph_peak_surface_list.back()->setPen(QPen(color));
color.setAlpha(40);
//_graph_peak_surface_list.back()->setScatterStyle(QCPScatterStyle::ssDot);
_graph_peak_surface_list.back()->setBrush(QBrush(color));
}
}
pappso::pappso_double
QCPXic::getRetentionTimeFromSecondsToLocal(pappso::pappso_double rt) const
{
if(_parent->_rt_in_seconds)
{
return rt;
}
else
{
return (rt / (pappso::pappso_double)60);
}
}
pappso::pappso_double
QCPXic::xAxisToSeconds(pappso::pappso_double rt) const
{
if(_parent->_rt_in_seconds)
{
return rt;
}
else
{
return (rt * (pappso::pappso_double)60);
}
}
void
QCPXic::drawXicPeakBorders(unsigned int i,
const Xic *xic_p,
const pappso::TracePeak *p_xic_peak)
{
QCPGraph *p_graph = _map_xic_graph.at(xic_p);
QColor color = _colours[i % 12];
// color.setAlpha(95);
QCPItemTracer *p_peak_border_left = new QCPItemTracer(this);
// itemDemoPhaseTracer = phaseTracer; // so we can access it later in the
// bracketDataSlot for animation
QPen border_pen(color);
border_pen.setWidth(3);
p_peak_border_left->setGraph(p_graph);
p_peak_border_left->setGraphKey(
getRetentionTimeFromSecondsToLocal(p_xic_peak->getLeftBoundary().x));
p_peak_border_left->setInterpolating(true);
p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
p_peak_border_left->setPen(border_pen);
p_peak_border_left->setBrush(color);
p_peak_border_left->setSize(30);
_graph_peak_border_list.push_back(p_peak_border_left);
// addItem(p_peak_border_left);
QPen apex_pen(color);
apex_pen.setWidth(2);
p_peak_border_left = new QCPItemTracer(this);
p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
p_peak_border_left->setGraphKey(
getRetentionTimeFromSecondsToLocal(p_xic_peak->getMaxXicElement().x));
p_peak_border_left->setInterpolating(true);
p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
p_peak_border_left->setPen(apex_pen);
p_peak_border_left->setBrush(color);
p_peak_border_left->setSize(8);
_graph_peak_border_list.push_back(p_peak_border_left);
// addItem(p_peak_border_left);
p_peak_border_left = new QCPItemTracer(this);
p_peak_border_left->setGraph(_map_xic_graph.at(xic_p));
p_peak_border_left->setGraphKey(
getRetentionTimeFromSecondsToLocal(p_xic_peak->getRightBoundary().x));
p_peak_border_left->setInterpolating(true);
p_peak_border_left->setStyle(QCPItemTracer::tsPlus);
p_peak_border_left->setPen(border_pen);
p_peak_border_left->setBrush(color);
p_peak_border_left->setSize(30);
_graph_peak_border_list.push_back(p_peak_border_left);
// addItem(p_peak_border_left);
replot();
}
void
QCPXic::clearXicPeakBorders()
{
for(QCPItemTracer *p_tracer : _graph_peak_border_list)
{
removeItem(p_tracer);
// delete p_tracer;
}
_graph_peak_border_list.clear();
replot();
}
pappso::QCPXic::_click
bool _click
Definition: qcpxic.h:80
pappso::QCPXic::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event) override
Definition: qcpxic.cpp:84
pappso::QCPXic::_mouse_move
bool _mouse_move
Definition: qcpxic.h:81
pappso::QCPXic::addMsMsEvent
void addMsMsEvent(const Xic *xic_p, pappso::pappso_double rt)
Definition: qcpxic.cpp:237
pappso::QCPXic::clearXicPeakBorders
void clearXicPeakBorders()
Definition: qcpxic.cpp:393
pappso::QCPXic::_colours
std::vector< QColor > _colours
Definition: qcpxic.h:88
pappso::QCPXic::clear
void clear()
Definition: qcpxic.cpp:263
pappso::QCPXic::_graph_peak_border_list
std::vector< QCPItemTracer * > _graph_peak_border_list
Definition: qcpxic.h:90
pappso::QCPXic::_control_key
bool _control_key
Definition: qcpxic.h:82
pappso::QCPXic::_old_y
pappso::pappso_double _old_y
Definition: qcpxic.h:84
pappso::QCPXic::_rt_range
QCPRange _rt_range
Definition: qcpxic.h:78
pappso::QCPXic::xAxisToSeconds
pappso::pappso_double xAxisToSeconds(pappso::pappso_double rt) const
Definition: qcpxic.cpp:318
pappso::QCPXic::setName
void setName(const Xic *xic_p, const QString &name)
Definition: qcpxic.cpp:255
pappso::QCPXic::_intensity_range
QCPRange _intensity_range
Definition: qcpxic.h:79
pappso::QCPXic::_old_x
pappso::pappso_double _old_x
Definition: qcpxic.h:83
pappso::QCPXic::_graph_peak_surface_list
std::vector< QCPGraph * > _graph_peak_surface_list
Definition: qcpxic.h:89
pappso::QCPXic::~QCPXic
~QCPXic()
Definition: qcpxic.cpp:80
pappso::QCPXic::_map_xic_graph
std::map< const Xic *, QCPGraph * > _map_xic_graph
Definition: qcpxic.h:86
pappso::QCPXic::setRtRangeChanged
Q_SLOT void setRtRangeChanged(QCPRange range)
Definition: qcpxic.cpp:220
pappso::QCPXic::getRetentionTimeFromSecondsToLocal
pappso::pappso_double getRetentionTimeFromSecondsToLocal(pappso::pappso_double rt) const
Definition: qcpxic.cpp:305
pappso::QCPXic::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:104
pappso::QCPXic::drawXicPeakBorders
void drawXicPeakBorders(unsigned int i, const Xic *xic_p, const pappso::TracePeak *p_xic_peak)
Definition: qcpxic.cpp:331
pappso::QCPXic::_current_ms2_event
QCPItemTracer * _current_ms2_event
Definition: qcpxic.h:85
pappso::QCPXic::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:140
pappso::QCPXic::keyReleaseEvent
virtual void keyReleaseEvent(QKeyEvent *event) override
Definition: qcpxic.cpp:94
pappso::QCPXic::addXicPeakList
void addXicPeakList(const Xic *xic_p, const std::vector< pappso::TracePeakCstSPtr > &xic_peak_list)
Definition: qcpxic.cpp:274
pappso::QCPXic::rescale
void rescale()
Definition: qcpxic.cpp:214
pappso::QCPXic::_graph_color
QColor _graph_color
Definition: qcpxic.h:87
pappso::QCPXic::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *event) override
Definition: qcpxic.cpp:123
pappso::QCPXic::addXicP
void addXicP(const Xic *xic_p)
Definition: qcpxic.cpp:183
pappso::QCPXic::QCPXic
QCPXic(XicWidget *parent)
Definition: qcpxic.cpp:38
pappso::QCPXic::_parent
XicWidget * _parent
Definition: qcpxic.h:77
pappso::TracePeak
Definition: tracepeak.h:40
pappso::TracePeak::getLeftBoundary
DataPoint & getLeftBoundary()
Definition: tracepeak.cpp:74
pappso::TracePeak::getMaxXicElement
DataPoint & getMaxXicElement()
Definition: tracepeak.cpp:64
pappso::TracePeak::getRightBoundary
DataPoint & getRightBoundary()
Definition: tracepeak.cpp:85
pappso::XicWidget
Definition: xicwidget.h:48
pappso::XicWidget::rtChangeEvent
void rtChangeEvent(pappso::pappso_double rt) const
Definition: xicwidget.cpp:165
pappso::XicWidget::_rt_in_seconds
bool _rt_in_seconds
Definition: xicwidget.h:97
pappso::XicWidget::xicClickEvent
void xicClickEvent(pappso::pappso_double rt, pappso::pappso_double intensity) const
Definition: xicwidget.cpp:243
pappso::Xic
Definition: xic.h:44
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::PeptideIonCter::y
@ y
pappso::PeptideIonCter::x
@ x
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::DataKind::rt
@ rt
Retention time.
pappso::TracePeakCstSPtr
std::shared_ptr< const TracePeak > TracePeakCstSPtr
Definition: tracepeak.h:34
qcpxic.h
custom plot XIC
pappso::DataPoint
Definition: datapoint.h:21
pappso::DataPoint::x
pappso_double x
Definition: datapoint.h:22