-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
76 lines (65 loc) · 2.13 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btnCount_clicked()
{
if(ui->checkBoxPararell->isChecked())
calculatePararell();
else
calculateLinear();
}
void MainWindow::calculateLinear(){
pair<vector<char>, int **> matrix = readMatrix();
linearNeedlemanWunsch lnw(matrix.first, matrix.second, ui->punishment->text().toInt());
QTime startTime=QTime::currentTime();
int result = lnw.calculate(ui->seq1->text().toStdString(), ui->seq2->text().toStdString());
pair<string, string> path = lnw.getBackwardPath(ui->seq1->text().toStdString(), ui->seq2->text().toStdString());
int mseconds = startTime.msecsTo(QTime::currentTime());
ui->time->setText(QString::number(mseconds));
ui->result->setText(QString::number(result));
ui->best_fit1->setText(QString::fromStdString(path.first));
ui->best_fit2->setText(QString::fromStdString(path.second));
}
void MainWindow::calculatePararell(){
}
void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Matrix file"), "/home/", tr("Text files (*.txt)"));
ui->matriFile->setText(fileName);
}
pair<vector<char>, int **> MainWindow::readMatrix(){
QString fileName = ui->matriFile->text();
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
throw "Cannot open file";
QTextStream in(&file);
QString line = in.readLine();
vector<char> signs;
QStringList splitted = line.split("\t");
int signsNum = splitted.size();
for(int i=0; i<signsNum; i++){
signs.push_back(splitted.at(i).at(0).toLatin1());
}
int** matrix = new int*[signsNum];
int i=0;
while (!in.atEnd()) {
line = in.readLine();
matrix[i] = new int[signsNum];
splitted = line.split("\t");
for(int j=0; j<signsNum; j++){
matrix[i][j] = splitted.at(j).toInt();
}
i++;
}
return make_pair(signs, matrix);
}