-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
260 lines (213 loc) · 9.14 KB
/
Copy pathMainWindow.cpp
File metadata and controls
260 lines (213 loc) · 9.14 KB
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
223
224
225
226
227
228
229
230
231
232
233
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
#include "mainWindow.h"
#define ERR -1
MainWindow::MainWindow(QWidget* parent)
: BaseClass(parent)
{
// top label
topLabel->setText(tr("de Bruijn Sequence Parser"));
QFont labelFont = topLabel->font();
labelFont.setPointSize(30);
labelFont.setBold(true);
topLabel->setFont(labelFont);
topLabel->setAlignment(Qt::AlignCenter);
// form group box
createFormGroupBox();
connect(fieldComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onFieldChanged(int)));
connect(spanComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSpanChanged(int)));
formGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// summary overview group box
createSummaryGroupBox();
summaryGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// button box
leftButton->setText(tr("Next"));
openExcelButton->setToolTip(tr("Click to proceed to the next page"));
connect(leftButton, &QPushButton::clicked, this, &MainWindow::onNextButtonClicked);
rightButton->setText(tr("Exit"));
openExcelButton->setToolTip(tr("Click to quit the application"));
connect(rightButton, &QPushButton::clicked, this, &MainWindow::reject);
buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// main layout
mainLayout->addWidget(topLabel);
mainLayout->addSpacing(20);
mainLayout->addWidget(summaryGroupBox);
mainLayout->addSpacing(5);
mainLayout->addWidget(formGroupBox);
mainLayout->addSpacing(10);
mainLayout->addWidget(buttonBox);
// main widget
QWidget* mainWidget = new QWidget(this);
mainWidget->setLayout(mainLayout);
setLayout(mainLayout);
}
void MainWindow::createFormGroupBox()
{
QFormLayout* layout = new QFormLayout;
formGroupBox = new QGroupBox(tr("Load Sequence Data"));
// LABELS
QLabel* orderLabel = new QLabel(tr("Over Field: "));
QLabel* spanLabel = new QLabel(tr("Span: "));
QLabel* complexityLabel = new QLabel(tr("Complexity:"));
// LABEL FONT
QFont groupBoxFont = formGroupBox->font();
groupBoxFont.setPointSize(11);
formGroupBox->setFont(groupBoxFont); // group box title
orderLabel->setFont(groupBoxFont);
spanLabel->setFont(groupBoxFont);
complexityLabel->setFont(groupBoxFont);
//COMBO BOXES
fieldComboBox = new QComboBox;
spanComboBox = new QComboBox;
complexityComboBox = new QComboBox;
fieldComboBox->addItem("<select>", QVariant(0));
fieldComboBox->addItem("2", QVariant(2));
for (int i = 3; i <= 7; i += 2)
fieldComboBox->addItem(QString::number(i), QVariant(i));
// LAYOUT
layout->addRow(orderLabel, fieldComboBox);
layout->addRow(spanLabel, spanComboBox);
layout->addRow(complexityLabel, complexityComboBox);
formGroupBox->setLayout(layout);
}
void MainWindow::createSummaryGroupBox()
{
QFormLayout* layout = new QFormLayout;
summaryGroupBox = new QGroupBox(tr("Data Overview"));
// LABEL
QLabel* label = new QLabel(tr("A summary Excel sheet, which provides a comprehensive overview of the resulting data"));
// LABEL FONT
QFont groupBoxFont = summaryGroupBox->font();
groupBoxFont.setPointSize(11);
summaryGroupBox->setFont(groupBoxFont); // group box title
label->setFont(groupBoxFont);
//BUTTON BOX
summarybuttonBox = new QDialogButtonBox(this);
openExcelButton = new QPushButton(tr("Open File"));
openExcelButton->setToolTip(tr("Click to open the summary Excel sheet"));
connect(openExcelButton, &QPushButton::clicked, this, &MainWindow::onOpenExcelButtonClicked);
summarybuttonBox->addButton(openExcelButton, QDialogButtonBox::NoRole);
summarybuttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
// LAYOUT
layout->addRow(label);
layout->addRow(summarybuttonBox);
summaryGroupBox->setLayout(layout);
}
void MainWindow::onFieldChanged(int index) {
spanComboBox->clear();
complexityComboBox->clear();
if (index != -1) {
if (fieldComboBox->itemText(index) == "<select>")
return; // don't populate ComboBox if placeholder is selected
int p = fieldComboBox->itemData(index).toInt();
populateSpanComboBox(p);
}
}
void MainWindow::populateSpanComboBox(int p) {
if (p != 2) //non-binary field
{
spanComboBox->addItem("2", QVariant(2));
}
else { //binary field
spanComboBox->addItem("<select>", QVariant(0));
spanComboBox->addItem("6", QVariant(6));
spanComboBox->addItem("7", QVariant(7));
}
}
void MainWindow::onSpanChanged(int index) {
if (index != -1) {
complexityComboBox->clear();
if (spanComboBox->itemText(index) == "<select>") {
return; // don't populate ComboBox if placeholder is selected
}
int span = spanComboBox->itemData(spanComboBox->currentIndex()).toInt();
int p = fieldComboBox->itemData(fieldComboBox->currentIndex()).toInt();
populateComplexityComboBox(span, p);
}
}
void MainWindow::populateComplexityComboBox(int span, int p) {
complexityComboBox->addItem("<select>", QVariant(0));
if (p != 2) // non binary
{
for (int i = 2*p + 1; i < qPow(p, span); ++i) {
if (p == 7 && i > 25) //for f7: support complexities up until 25
break;
complexityComboBox->addItem(QString::number(i), QVariant(i));
}
return;
}
//binary
for (int i = qPow(p, span - 1) + span; i <= qPow(p, span - 1) + 24; ++i) // i <= qPow(p, span) - 1 for all possible complexities
complexityComboBox->addItem(QString::number(i), QVariant(i));
}
void MainWindow::onNextButtonClicked() {
int field = fieldComboBox->currentData().toInt();
int span = spanComboBox->currentData().toInt();
int complexity = complexityComboBox->currentData().toInt();
int totaldbSeq = -1;
int totalSmallSeq = -1;
int totalYielding = -1;
int totalNonYielding = -1;
// Check if any of the values is the placeholder '<select>'
if (field == 0 || span == 0 || complexity == 0) {
QMessageBox::warning(this, tr("Incomplete Selection Detected"), tr("All fields must be selected before proceeding."));
return;
}
// fetch corresponding file
QString filePath = QString(":/summary/data/F_%1/span_%2/%3/%3_summary.txt").arg(field).arg(span).arg(complexity);
int returnVal = getSequenceData(totaldbSeq, totalSmallSeq, totalYielding, totalNonYielding, filePath);
if (returnVal == ERR)
return;
DataDisplayWindow* dataDisplayWindow = new DataDisplayWindow(this, field, span, complexity, totaldbSeq, totalSmallSeq, totalYielding, totalNonYielding);
dataDisplayWindow->setAttribute(Qt::WA_DeleteOnClose);
dataDisplayWindow->show();
}
void MainWindow::onOpenExcelButtonClicked()
{
QString appDir = QCoreApplication::applicationDirPath();
#ifdef _DEBUG // go up two directories from the Release/Debug folder
appDir = QDir(appDir).absoluteFilePath("../../");
#endif
QString filePath = "/data/summary.xlsx";
QString localFilePath = appDir + filePath;
QUrl fileUrl = QUrl::fromLocalFile(localFilePath);
if (!QDesktopServices::openUrl(fileUrl)) {
QMessageBox::warning(this, tr("File Open Error"), tr("Unable to open file: ") + localFilePath);
}
}
int MainWindow::getSequenceData(int& totaldbSeq, int& totalSmallSeq, int& totalYielding, int& totalNonYielding, QString filePath)
{
static QRegularExpression dbSeqRegex(R"(total number of debruijn sequences of complexity \d+ is: (\d+))");
static QRegularExpression smallSeqRegex(R"(total number of sequences of small complexity \d+ is: (\d+))");
static QRegularExpression yieldingSeqRegex(R"(The total number of sequences of small complexity=\d+ which yield debruijn sequences is: (\d+))");
static QRegularExpression nonYieldingSeqRegex(R"(The total number of sequences of small complexity=\d+ which DO NOT yield any debruijn sequences is: (\d+))");
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::warning(this, tr("File Open Error"), tr("Unable to open the file for reading."));
return ERR;
}
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
// Check for the dbSeq line
QRegularExpressionMatch dbSeqMatch = dbSeqRegex.match(line);
if (dbSeqMatch.hasMatch()) {
totaldbSeq = dbSeqMatch.captured(1).toInt();
}
// Check for the smallSeq line
QRegularExpressionMatch smallSeqMatch = smallSeqRegex.match(line);
if (smallSeqMatch.hasMatch()) {
totalSmallSeq = smallSeqMatch.captured(1).toInt();
}
// Check for yielding line
QRegularExpressionMatch yieldingSeqMatch = yieldingSeqRegex.match(line);
if (yieldingSeqMatch.hasMatch()) {
totalYielding = yieldingSeqMatch.captured(1).toInt();
}
// Check for non yielding line
QRegularExpressionMatch nonYieldingSeqMatch = nonYieldingSeqRegex.match(line);
if (nonYieldingSeqMatch.hasMatch()) {
totalNonYielding = nonYieldingSeqMatch.captured(1).toInt();
}
}
file.close();
return 0;
}