ms2_alignment_widget.cpp 9.04 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * ms2_alignment_widget.cpp
 *
 *  Created on: 2 août 2012
 *      Author: valot
 */

#include "ms2_alignment_widget.h"
#include <QGroupBox>
#include <QPushButton>
#include <QFormLayout>
#include <QDoubleSpinBox>
#include <QFileDialog>

Ms2AlignmentWidget::Ms2AlignmentWidget(QWidget * parent) :
		AlignmentWidget(parent), MS2_TENDENCY(10), MS2_SMOOTHING(15), MS1_SMOOTHING(
				0) {
	//kill including widget
	setAttribute(Qt::WA_DeleteOnClose);

	_mainLayout = new QVBoxLayout;
	this->addMasschroqmlSelectionGroup();
	this->addMsRunSelectionGroup();
	this->addParametersGroup();
	this->addAlignButton();

	this->setLayout(_mainLayout);

	this->initializeMs2Method();

	_masschroqml_loader_thread.setMaxProgress(3);
	connect(&_masschroqml_loader_thread,
			SIGNAL(loadedMasschroqml(MasschroqGuiData *)), this,
			SLOT(doneLoadingMasschroqml(MasschroqGuiData *)));
	connect(&_masschroqml_loader_thread, SIGNAL(errorDuringLoading(QString)),
			this, SLOT(ErrorLoadingMasschroqml(QString)));
}

Ms2AlignmentWidget::~Ms2AlignmentWidget() {
40
	qDebug() << "delete Ms2alignmentWidget";
41
	this->deleteLoadingThread();
Benoit Valot's avatar
Benoit Valot committed
42
	this->deleteData();
43
	delete (_monitor);
Benoit Valot's avatar
Benoit Valot committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
}

void Ms2AlignmentWidget::addMasschroqmlSelectionGroup() {
	QGroupBox * masschroqml_group = new QGroupBox("MassChroqML selection");

	QVBoxLayout * groupLayout = new QVBoxLayout;

	_masschroqml_edit = new QLineEdit("No MassChroqML Selected");
	_masschroqml_edit->setReadOnly(true);
	groupLayout->addWidget(_masschroqml_edit);

	QHBoxLayout *layout = new QHBoxLayout;
	_masschroqml_message = new RunningQLabel(this);
	layout->addWidget(_masschroqml_message, 2);
	QPushButton * extractButton = new QPushButton(tr("&Load"));
	extractButton->setDefault(true);
	connect(extractButton, SIGNAL(clicked()), this,
			SLOT(startLoadingMasschroqml()));
	layout->addWidget(extractButton, 0);

	groupLayout->addLayout(layout);

	masschroqml_group->setLayout(groupLayout);
	_mainLayout->addWidget(masschroqml_group);
}

void Ms2AlignmentWidget::addMsRunSelectionGroup() {
	QGroupBox * msrun_group = new QGroupBox("MsRun selection");

	QVBoxLayout * groupLayout = new QVBoxLayout;
	_msrun_select_ref = new QComboBox();
	connect(_msrun_select_ref, SIGNAL(activated(int)), this,
			SLOT(startLoadindMsrunRef(int)));

	groupLayout->addWidget(_msrun_select_ref);
	_loadingMsrunRefLabel = new RunningQLabel(this);
	groupLayout->addWidget(_loadingMsrunRefLabel);

	_msrun_select_align = new QComboBox();
	connect(_msrun_select_align, SIGNAL(activated(int)), this,
			SLOT(startLoadindMsrunAligned(int)));

	groupLayout->addWidget(_msrun_select_align);
	_loadingMsruntoALignedLabel = new RunningQLabel(this);
	groupLayout->addWidget(_loadingMsruntoALignedLabel);

	msrun_group->setLayout(groupLayout);
	_mainLayout->addWidget(msrun_group);
}

void Ms2AlignmentWidget::addParametersGroup() {
	QGroupBox * _parameter_group = new QGroupBox("MS2 Parameters");
	QFormLayout * layout = new QFormLayout;

	QDoubleSpinBox * ms2_tendency_box = new QDoubleSpinBox;
	ms2_tendency_box->setMaximum(1000);
	ms2_tendency_box->setWrapping(true);
	ms2_tendency_box->setSingleStep(1);
	ms2_tendency_box->setDecimals(0);
	ms2_tendency_box->setValue(MS2_TENDENCY);
	layout->addRow(tr("MS2 tendency half window"), ms2_tendency_box);

	QDoubleSpinBox * ms2_smoothing_box = new QDoubleSpinBox;
	ms2_smoothing_box->setMaximum(1000);
	ms2_smoothing_box->setWrapping(true);
	ms2_smoothing_box->setSingleStep(1);
	ms2_smoothing_box->setDecimals(0);
	ms2_smoothing_box->setValue(MS2_SMOOTHING);
	layout->addRow(tr("MS2 smoothing half window"), ms2_smoothing_box);

	QDoubleSpinBox * ms1_smoothing_box = new QDoubleSpinBox;
	ms1_smoothing_box->setMaximum(1000);
	ms1_smoothing_box->setWrapping(true);
	ms1_smoothing_box->setSingleStep(1);
	ms1_smoothing_box->setDecimals(0);
	ms1_smoothing_box->setValue(MS1_SMOOTHING);
	layout->addRow(tr("MS1 smoothing half window"), ms1_smoothing_box);

	_parameter_group->setLayout(layout);

	connect(ms2_tendency_box, SIGNAL(valueChanged(double)), this,
			SLOT(setMs2Tendency(double)));

	connect(ms2_smoothing_box, SIGNAL(valueChanged(double)), this,
			SLOT(setMs2Smoothing(double)));

	connect(ms1_smoothing_box, SIGNAL(valueChanged(double)), this,
			SLOT(setMs1Smoothing(double)));

	_mainLayout->addWidget(_parameter_group);
}

void Ms2AlignmentWidget::addAlignButton() {
	QHBoxLayout * layout = new QHBoxLayout;
	_runningQLabel = new RunningQLabel(this);
	layout->addWidget(_runningQLabel, 2);
140
	QPushButton * extractButton = new QPushButton(tr("&Align"));
Benoit Valot's avatar
Benoit Valot committed
141
142
143
144
145
146
147
	extractButton->setDefault(true);
	connect(extractButton, SIGNAL(clicked()), this, SLOT(startAlignment()));
	layout->addWidget(extractButton, 0);
	_mainLayout->addLayout(layout);
}

void Ms2AlignmentWidget::initializeMs2Method() {
148
149
	_monitor = new MonitorAlignmentPlot();
	_alignmentBase = new AlignmentMs2(_monitor);
Benoit Valot's avatar
Benoit Valot committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
	AlignmentMs2 * align((AlignmentMs2 *) _alignmentBase);
	align->setMs2TendencyWindow(MS2_TENDENCY);
	align->setMs2SmoothingWindow(MS2_SMOOTHING);
	align->setMs1SmoothingWindow(MS1_SMOOTHING);
	_masschroqGuidata = 0;
	_msunToAligned = 0;
	_msrunRef = 0;
}

void Ms2AlignmentWidget::setMs2Tendency(double win) {
	AlignmentMs2 * align((AlignmentMs2 *) _alignmentBase);
	align->setMs2TendencyWindow(win);
}

void Ms2AlignmentWidget::setMs2Smoothing(double win) {
	AlignmentMs2 * align((AlignmentMs2 *) _alignmentBase);
	align->setMs2SmoothingWindow(win);
}

void Ms2AlignmentWidget::setMs1Smoothing(double win) {
	AlignmentMs2 * align((AlignmentMs2 *) _alignmentBase);
	align->setMs1SmoothingWindow(win);
}

void Ms2AlignmentWidget::startLoadindMsrunRef(int index) {
175
	if (this->isAlignmentRunning())
176
		return;
Benoit Valot's avatar
Benoit Valot committed
177
178
179
	qDebug() << "Load MsRun Ref index : " << index;
	QString id = _masschroqGuidata->getMsrunIdToNumber(index);
	Msrun * msrun = _masschroqGuidata->getMsrunHashGroup()->getMsRun(id);
180
181
	
	this->triggerLoadingMsRunRef(msrun);
Benoit Valot's avatar
Benoit Valot committed
182
183
184
185

}

void Ms2AlignmentWidget::startLoadindMsrunAligned(int index) {
186
	if (this->isAlignmentRunning())
187
		return;
Benoit Valot's avatar
Benoit Valot committed
188
189
190
191
	qDebug() << "Load MsRun Align index : " << index;
	QString id = _masschroqGuidata->getMsrunIdToNumber(index);
	Msrun * msrun = _masschroqGuidata->getMsrunHashGroup()->getMsRun(id);

192
	this->triggerLoadingMsRunToAlign(msrun);
Benoit Valot's avatar
Benoit Valot committed
193
194
195
}

void Ms2AlignmentWidget::startLoadingMasschroqml() {
196
	if (this->isAlignmentRunning())
197
		return;
Benoit Valot's avatar
Benoit Valot committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
	qDebug() << "Begin MassChroqML Loading";
	//TODO parse masschroml and return a masschroqdata
	QString filename = QFileDialog::getOpenFileName(this,
			tr("Open MasschroqML File"), QString::null,
			tr("masschroqML files (*.masschroqML &  *.xml)"));
	if (filename.isEmpty()) {
		return;
	}

	QFileInfo filenameInfo(filename);

	if (!filenameInfo.exists()) {
		this->viewError(
				tr(
						"The chosen MasschroqML file '%1', does not exist..\nPlease, change the read permissions on this file or load another one. ").arg(
						filename));
		return;
	} else if (!filenameInfo.isReadable()) {
		this->viewError(
				tr(
						"The chosen MasschroqML file '%1', is not readable.\nPlease, change the read permissions on this file or load another one. ").arg(
						filename));
		return;
	}
	_masschroqml_message->startLoading(tr("Loading"));
	_masschroqml_edit->setText(this->strippedFilename(filename));
	_loadingMsrunRefLabel->setText("");
	_loadingMsruntoALignedLabel->setText("");

	this->deleteData();
	this->_msrun_select_ref->clear();
	this->_msrun_select_align->clear();
	//emit resetData();

	MasschroqGuiData * masschroqdata = new MasschroqGuiData(filename);
233
	QDir::setCurrent(filenameInfo.absolutePath());
Benoit Valot's avatar
Benoit Valot committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
	_masschroqml_loader_thread.loadMasschroqml(masschroqdata, filename);

}

void Ms2AlignmentWidget::doneLoadingMasschroqml(MasschroqGuiData * guiData) {
	_masschroqGuidata = guiData;
	_masschroqml_message->stopLoading(tr("MasschroqML correctly loaded"));

//add msrun selection
	const std::vector<QString> FilenameList =
			_masschroqGuidata->getMsrunFilenameList();
	std::vector<QString>::const_iterator it;

	for (it = FilenameList.begin(); it < FilenameList.end(); it++) {
		this->_msrun_select_ref->addItem(this->strippedFilename(*it));
		this->_msrun_select_align->addItem(this->strippedFilename(*it));
	}
//emit updateMasschroqData();
}

void Ms2AlignmentWidget::ErrorLoadingMasschroqml(QString error) {
	_masschroqml_edit->setText(tr("No MassChroqML selected"));
	_masschroqml_message->stopLoading(tr(""));

	this->viewError(error);
}

void Ms2AlignmentWidget::completDataToMsrun(Msrun * msrun) {
	qDebug() << "Complete data to Msrun MS2 Alignment";
	msrun->setPeptideList(
			_masschroqGuidata->getPeptideList().newPeptideListObservedInMsrun(
					msrun));
}

268
void Ms2AlignmentWidget::emitSignalDoneAlignement() {
Olivier Langella's avatar
Olivier Langella committed
269
    qDebug() << "Ms2AlignmentWidget::emitSignalDoneAlignement begin" ;
270
	emit newAlignmentCurve();
271
	MonitorAlignmentPlot * monitor = (MonitorAlignmentPlot *) _monitor;
272
	emit finishMonitorAlignment(monitor);
273
	emit finishAlignment(_msunToAligned);
Olivier Langella's avatar
Olivier Langella committed
274
    qDebug() << "Ms2AlignmentWidget::emitSignalDoneAlignement end" ;
275
276
}

Benoit Valot's avatar
Benoit Valot committed
277
278
279
280
281
282
void Ms2AlignmentWidget::deleteData() {
	if (_masschroqGuidata != 0) {
		delete (_masschroqGuidata);
		_masschroqGuidata = 0;
	}
}
Benoit Valot's avatar
Benoit Valot committed
283

284
285
void Ms2AlignmentWidget::writeElement(
		MasschroqDomDocument * domDocument) const {
Benoit Valot's avatar
Benoit Valot committed
286
	AlignmentMs2 * align((AlignmentMs2 *) _alignmentBase);
287
	domDocument->addMs2AlignmentMethod(*align);
Benoit Valot's avatar
Benoit Valot committed
288
}