-
Notifications
You must be signed in to change notification settings - Fork 0
/
LargeAli.cpp
255 lines (187 loc) · 5.8 KB
/
LargeAli.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
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
/*
* Copyright (C) 2009-2012 Simon A. Berger
*
* This file is part of visual_papara.
*
* visual_papara is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* visual_papara is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with visual_papara. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QWidget>
#include <string>
#include <QFileDialog>
#include <QScopedPointer>
#include <QScrollArea>
#include <stdint.h>
#include "LargeAli.h"
#include "ivymike/large_phylip.h"
#include "ui_LargeAli.h"
#include "TextGrid.h"
class largali_model : public TextGridModel {
public:
largali_model( ivy_mike::large_phylip *large_phy ) : large_phy_(large_phy) {
}
virtual QSize size() {
size_t width = large_phy_->sequence_len();
size_t height = large_phy_->size();
return QSize( width, height );
}
virtual QChar data( size_t x, size_t y ) {
if( !large_phy_->is_mapped() ) {
return 'X';
}
uint8_t *sfirst = large_phy_->sequence_begin_at(y);
assert( sfirst != 0 );
return sfirst[x];
}
virtual QColor color( size_t x, size_t y ) {
if( !large_phy_->is_mapped() ) {
return QColor( 255, 0, 0 );
}
uint8_t *sfirst = large_phy_->sequence_begin_at(y);
assert( sfirst != 0 );
uint8_t c = toupper(sfirst[x]);
const bool protein = true;
if( !protein ) {
// nucleotice color mapping
switch( c ) {
case 'A':
return QColor( 255, 0, 0 );
case 'C':
return QColor( 0, 255, 0 );
case 'G':
return QColor( 0, 0, 255 );
case 'T':
return QColor( 255, 200, 0 );
default:
return Qt::white;
}
} else {
// protein color mapping
switch( c ) {
case 'A':
case 'I':
case 'L':
case 'M':
case 'F':
case 'W':
case 'V':
return Qt::blue;
case 'R':
case 'K':
return Qt::red;
case 'N':
return Qt::green;
case 'C':
return Qt::blue;
case 'Q':
return Qt::green;
case 'E':
return Qt::magenta;
case 'D':
return Qt::magenta;
case 'G':
return QColor(255,200,0);
case 'H':
case 'Y':
return Qt::cyan;
case 'P':
return Qt::yellow;
case 'S':
case 'T':
return Qt::green;
default:
return Qt::white;
}
}
#if 0
switch( c ) {
case 'A':
case 'I':
case 'L':
case 'M':
case 'F':
case 'W':
case 'V':
return Qt::blue;
case 'R':
case 'K':
return Qt::red;
case 'N':
return Qt::green;
case 'C':
return Qt::blue;
case 'Q':
return Qt::green;
case 'E':
return Qt::magenta;
case 'D':
return Qt::magenta;
case 'G':
return QColor(255,200,0);
case 'H':
case 'Y':
return Qt::cyan;
case 'P':
return Qt::yellow;
case 'S':
case 'T':
return Qt::green;
default:
return Qt::white;
}
#endif
}
private:
ivy_mike::large_phylip *large_phy_;
};
LargeAli::LargeAli(const char* filename, QWidget* parent) :
QWidget(parent),
ui(new Ui::LargaliMain)
{
ui->setupUi(this);
if( filename != 0 ) {
open_file( filename );
}
}
LargeAli::~LargeAli() {}
static std::string de_q_string( QString qs ) {
std::string s = qs.toStdString();
return s;
}
void LargeAli::open_file( const std::string &filename ) {
try {
large_phy_.reset( new ivy_mike::large_phylip(filename.c_str() ));
//std::cout << "name 0: " << large_phy_->getName(0) << "\n";
grid_model_ = QSharedPointer<TextGridModel> (new largali_model(large_phy_.data()));
text_grid_.reset(new TextGrid());
text_grid_->setModel(grid_model_);
connect( ui->slZoom, SIGNAL(valueChanged(int)), text_grid_.data(), SLOT(setZoom(int)));
connect( text_grid_.data(), SIGNAL(zoomChanged(int)), ui->slZoom, SLOT(setValue(int)));
ui->saAlignment->setWidget(text_grid_.data());
} catch( boost::interprocess::interprocess_exception x ) {
std::cerr << "caught: " << x.what() << "\n";
abort();
}
}
void LargeAli::on_pbLoad_clicked() {
open_file( de_q_string(QFileDialog::getOpenFileName(this)) );
}
void LargeAli::on_pbSuspend_clicked() {
if( !large_phy_.isNull() ) {
if( large_phy_->is_mapped() ) {
large_phy_->unmap();
} else {
large_phy_->map();
}
}
}