-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
222 lines (178 loc) · 5.46 KB
/
mainwindow.cpp
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
40
41
42
43
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
140
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
#include "nucbase.hpp"
#include <QFileDialog>
#include <QMessageBox>
#include <QErrorMessage>
#include <list>
#include <vector>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
_ui(new Ui::MainWindow), _worker(parent), _timer(parent)
{
_ui->setupUi(this);
_ui->seqfolder_frame->setHidden(true);
_worker.setFolderMode(false);
connect(&_timer, SIGNAL(timeout()), this, SLOT(checkWorker()));
}
MainWindow::~MainWindow()
{
delete _ui;
}
void MainWindow::openDatabase()
{
QString path = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Text files (*.txt)"));
if(path != 0)
{
_ui->status_bar->showMessage("Opening database...");
_worker.setDB(path);
if(!_worker.failed())
{
_ui->db_lineEdit->setText(QDir::toNativeSeparators(path));
_ui->list_widget->clear();
vector<string> labels;
_worker.getLabels(labels);
_ui->status_bar->showMessage(QString::number(_worker.getNlines()).append(" line(s)."));
_ui->progress_bar->setMaximum(_worker.getNlines());
// If more than one column, we ignore the first column
if(labels.size() > 0)
{
if(labels.size() > 1)
for(unsigned int i=1;i<labels.size(); ++i)
_ui->list_widget->addItem(QString(labels[i].c_str()));
else
_ui->list_widget->addItem(QString(labels[0].c_str()));
}
}
else
{
QString message = _worker.getMessage();
QErrorMessage * error = new QErrorMessage(this);
error->showMessage(message);
_ui->status_bar->clearMessage();
}
}
}
void MainWindow::setDatabaseSelection()
{
vector<string> labels;
_worker.getLabels(labels);
bool unique = labels.size() == 1;
vector<int> selection;
QModelIndexList indexes = _ui->list_widget->selectionModel()->selectedIndexes();
foreach(QModelIndex index, indexes)
{
if(!unique)
selection.push_back(index.row()+1);
else
selection.push_back(index.row());
}
_worker.setSelection(selection);
_ui->start_button->setEnabled(_worker.isReady());
}
void MainWindow::setFolderMode(bool val)
{
_worker.setFolderMode(val);
_ui->start_button->setEnabled(_worker.isReady());
}
void MainWindow::selectSequencesFolder()
{
QString path = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if(path != 0)
{
_worker.setSeqFolder(path);
_ui->seqfolder_lineEdit->setText(QDir::toNativeSeparators(path));
_ui->start_button->setEnabled(_worker.isReady());
}
}
void MainWindow::selectSequenceFile()
{
QString path = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Sequence files (*.txt *.fa *.fasta)"));
if(path != 0)
{
_worker.setSeqFilename(path);
_ui->seqfilename_lineEdit->setText(QDir::toNativeSeparators(path));
_ui->start_button->setEnabled(_worker.isReady());
}
}
void MainWindow::setSequenceName()
{
QString seqname = _ui->input_name->text();
QRegExp regex("[0-9a-zA-Z ]+");
QRegExpValidator validator(regex, 0);
int pos = 0;
if(validator.validate(seqname, pos) == 2)
_worker.setSeqName(seqname);
else
_worker.setSeqName("");
_ui->start_button->setEnabled(_worker.isReady());
}
void MainWindow::setSequenceValue()
{
QString text = _ui->input_sequence->toPlainText();
QRegExp regex("[acgntACGNT]+");
QRegExpValidator validator(regex, 0);
int pos = 0;
if(validator.validate(text, pos) == 2)
_worker.setSeqVal(text);
else
_worker.setSeqVal("");
_ui->start_button->setEnabled(_worker.isReady());
}
void MainWindow::start()
{
// We disable the UI (except the progress bar)
_ui->progress_bar->setEnabled(true);
_ui->data_widget->setDisabled(true);
_ui->start_button->setDisabled(true);
_ui->start_button->setText("Running...");
// We set the search parameters
_worker.setMismatches(_ui->mismatches_spinBox->value());
_worker.setSubmatches(_ui->submatches_spinBox->value());
_worker.setMapnum(_ui->mapnum_checkBox->isChecked());
_worker.setAbsent(_ui->absent_checkBox->isChecked());
_worker.setUnmatched(_ui->unmatched_checkBox->isChecked());
// We start the worker thread and the timer
_timer.start(100);
_worker.start();
}
void MainWindow::checkWorker()
{
if(_worker.isRunning())
{
_ui->progress_bar->setMaximum(_worker.getMaximum());
_ui->progress_bar->setValue(_worker.getProgress());
_ui->status_bar->showMessage(_worker.getStatus());
}
else if(_worker.isFinished())
{
// We stop the timer
_timer.stop();
// The progress bar should be at 100%
_ui->progress_bar->setValue(_worker.getMaximum());
// We show the status
_ui->status_bar->showMessage(_worker.getStatus());
// We check if the worker failed
bool failed = _worker.failed();
// We get the worker thread message
QString message = _worker.getMessage();
if(failed)
{
QErrorMessage * error = new QErrorMessage(this);
error->showMessage(message);
}
else
QMessageBox::information(this, "Information", message);
// We re-enable everything
_ui->start_button->setText("Start");
_ui->start_button->setDisabled(false);
_ui->data_widget->setDisabled(false);
// Except the progress bar, which we reset
_ui->progress_bar->setEnabled(false);
_ui->progress_bar->setValue(0);
// We clear the status bar
_ui->status_bar->clearMessage();
}
}