plot_aligned.cpp 4.47 KB
Newer Older
Benoit Valot's avatar
Benoit Valot committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
 * \file plot.cpp
 * \date November 23, 2011
 * \author Edlira Nano
 */

#include "plot_aligned.h"
#include <qwt_legend.h>
#include <qwt_symbol.h>

PlotAligned::PlotAligned(QWidget *parent) :
		QwtPlot(parent) {

	setAutoReplot(false);

	setTitle("");

	// legend
	QwtLegend * legend = new QwtLegend;
	insertLegend(legend, QwtPlot::BottomLegend);

	setAxisTitle(QwtPlot::xBottom, "Retention time (s)");
	setAxisTitle(QwtPlot::yLeft, "Delta RT (s)");
	// enable zooming
	_zoomer = 0;
26
27
28
	
	_p_curve_deltart = new QwtPlotCurve("Aligned RT");
	_p_curve_ms2 = new QwtPlotCurve("Common identification");
Benoit Valot's avatar
Benoit Valot committed
29
30
31
32
33
34
35
36
37
38
}

PlotAligned::~PlotAligned() {
	this->clear();
	if (_zoomer != 0) {
		delete _zoomer;
		_zoomer = 0;
	}
}

39
void PlotAligned::viewAlignedMsRun(const Msrun * msrun) {
Olivier Langella's avatar
Olivier Langella committed
40
	qDebug() << "PlotAligned::viewAlignedMsRun begin";
Benoit Valot's avatar
Benoit Valot committed
41
42
43
44
45
46
	const std::vector<mcq_double> originalRt =
			msrun->getOriginalRetentionTimes();
	const std::vector<mcq_double> alignedRt = msrun->getAlignedRetentionTimes();
	if (originalRt.size() == alignedRt.size()) {
		std::vector<mcq_double>::const_iterator itOriginal = originalRt.begin();
		std::vector<mcq_double>::const_iterator itAligned = alignedRt.begin();
47
48
49
50
51
		//QwtPlotCurve * curve = new QwtPlotCurve("Aligned RT");
		_p_curve_deltart->setStyle(QwtPlotCurve::Lines);
		_p_curve_deltart->setRenderHint(QwtPlotItem::RenderAntialiased);
		_p_curve_deltart->setPen(QColor(Qt::blue));
		//_alignedPlots.push_back(curve);
Benoit Valot's avatar
Benoit Valot committed
52
53
54
55
56

		unsigned int plotsize(alignedRt.size());
		mcq_double x1[plotsize], y1[plotsize];
		int i = 0;
		for (; itOriginal != originalRt.end(); ++itOriginal, ++itAligned) {
57
			y1[i] = (*itOriginal) - (*itAligned);
Benoit Valot's avatar
Benoit Valot committed
58
			x1[i] = (*itOriginal);
Benoit Valot's avatar
Benoit Valot committed
59
60
			i++;
		}
Olivier Langella's avatar
Olivier Langella committed
61
		_p_curve_deltart->setSamples(x1, y1, plotsize);
Benoit Valot's avatar
Benoit Valot committed
62

63
		_p_curve_deltart->attach(this);
Benoit Valot's avatar
Benoit Valot committed
64
65

		this->setTitle(
66
67
				tr("Alignment of '%1'").arg(
						msrun->getXmlFileInfo().fileName()));
Benoit Valot's avatar
Benoit Valot committed
68
69
70
		this->replot();
		initZoomer();
	}
Olivier Langella's avatar
Olivier Langella committed
71
72
	
	qDebug() << "PlotAligned::viewAlignedMsRun end";
Benoit Valot's avatar
Benoit Valot committed
73
74
}

Edlira Nano's avatar
Edlira Nano committed
75
void PlotAligned::viewAlignedMS2Peaks(const MonitorAlignmentPlot * monitorAlignment) {
Olivier Langella's avatar
Olivier Langella committed
76
    qDebug() << "PlotAligned::viewAlignedMS2Peaks begin";
77
78
79
80
	if(monitorAlignment==0)
		return;

	qDebug() << "View Ms2 point";
81
82
83
	//QwtPlotCurve * curve = new QwtPlotCurve("Common identification");
	_p_curve_ms2->setStyle(QwtPlotCurve::Dots);
	_p_curve_ms2->setRenderHint(QwtPlotItem::RenderAntialiased);
Olivier Langella's avatar
Olivier Langella committed
84
	QwtSymbol symbol(QwtSymbol::Star1, QColor(Qt::black), QColor(Qt::black),
85
			QSize(9, 9));
Olivier Langella's avatar
Olivier Langella committed
86
	_p_curve_ms2->setSymbol(&symbol);
87
	//_alignedPlots.push_back(curve);
88

89
	const std::map<mcq_double,mcq_double>& mapDeltaPeaks =	monitorAlignment->getMs2CommonPeak();
90
91
92
93
94
95
	
	
	
	_msms_data.resize(0);
	//unsigned int plotsize(mapDeltaPeaks.size());
	//mcq_double x1[plotsize], y1[plotsize];
96
	std::map<mcq_double,mcq_double>::const_iterator it;
97
	//int i = 0;
98
	for (it = mapDeltaPeaks.begin(); it != mapDeltaPeaks.end(); ++it) {
Olivier Langella's avatar
Olivier Langella committed
99
		QPointF one_point;
100
101
102
103
104
105
		one_point.setX(it->first);
		one_point.setY(it->second);
		_msms_data.push_back(one_point);
		//y1[i] = it->second;
		//x1[i] =  it->first;
		//i++;
106
	}
Olivier Langella's avatar
Olivier Langella committed
107
	_p_curve_ms2->setSamples(_msms_data);
Benoit Valot's avatar
Benoit Valot committed
108

109
	_p_curve_ms2->attach(this);
110
111
	this->replot();
	initZoomer();
Olivier Langella's avatar
Olivier Langella committed
112
    qDebug() << "PlotAligned::viewAlignedMS2Peaks end";
Benoit Valot's avatar
Benoit Valot committed
113
114
115
}

void PlotAligned::clear() {
Olivier Langella's avatar
Olivier Langella committed
116
	qDebug() << "PlotAligned::clear() begin";
117
118
119
120
121
122
123
124
125
126
	/*
	if (_msms_data.size() > 0) {
		const QwtSymbol symbol(QwtSymbol::Star1, QColor(Qt::white), QColor(Qt::white),
			QSize(9, 9));
		_p_curve_ms2->setSymbol(symbol);
		//QwtData data(_p_curve_ms2->data());
		//QwtData * p_data = _p_curve_ms2->data().copy();
		_p_curve_ms2->setData(_msms_data);
		replot();
	}*/
Olivier Langella's avatar
Olivier Langella committed
127
128
	_p_curve_ms2->setSamples(QVector<QPointF>());
	_p_curve_deltart->setSamples(QVector<QPointF>());
129
130
	_p_curve_ms2->detach();
	_p_curve_deltart->detach();
131
	
Benoit Valot's avatar
Benoit Valot committed
132
133
134
135

	setAxisAutoScale(QwtPlot::xBottom);
	setAxisAutoScale(QwtPlot::yLeft);
	this->setTitle("");
136
	_msms_data.resize(0);
Benoit Valot's avatar
Benoit Valot committed
137
138
139
	replot();
	initZoomer();

Olivier Langella's avatar
Olivier Langella committed
140
	qDebug() << "PlotAligned::clear() end";
Benoit Valot's avatar
Benoit Valot committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
}

void PlotAligned::clearPlot() {
	this->clear();
}


void PlotAligned::initZoomer() {
	// LeftButton for the zooming
	// MidButton for the panning
	// RightButton: zoom out by 1
	// Ctrl+RighButton: zoom out to full size

	if (_zoomer != 0)
		delete _zoomer;

	_zoomer = new QwtPlotZoomer(canvas());
	_zoomer->setResizeMode(QwtPicker::KeepSize);
	_zoomer->setTrackerMode(QwtPicker::AlwaysOn);
	_zoomer->setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton,
			Qt::ControlModifier);
	_zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);

	const QColor c(Qt::darkBlue);
	_zoomer->setRubberBandPen(c);
	_zoomer->setTrackerPen(c);

Olivier Langella's avatar
Olivier Langella committed
168
}