00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <db_cxx.h>
00016 #include <qpainter.h>
00017 #include "featuregui.h"
00018 #include "featuredata.h"
00019 #include <qstring.h>
00020 #include <cmath>
00021 #include <algorithm>
00022 #include <cassert>
00023 #include "tagcolormap.h"
00024
00025 void FeatureGui::paint( QPainter * p, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00026 double width, int height, int center )
00027 {
00028
00029
00030
00031
00032
00033
00034 TR_DNA x1_dna_cut;
00035
00036 if ( (x1_dna_cut = max( m_data->startPos(), x1_dna )) > x2_dna )
00037 return;
00038
00039 TR_DNA x2_dna_cut;
00040
00041 if ( ( x2_dna_cut = min( m_data->endPos(), x2_dna ) ) < x1_dna )
00042 return;
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 x_pix += static_cast<TR_PIX>(( x1_dna_cut - x1_dna ) * width);
00057
00058
00059 paintMe( p, x_pix, y_pix, x1_dna_cut, x2_dna_cut, width, height, center);
00060 }
00061
00062 void DnpGui::paintMe( QPainter * p, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00063 double width, int height, int center )
00064 {
00065 static QColor dnpcolors[] =
00066 {
00067 Qt::red.light(110),
00068 Qt::green.light(110),
00069 Qt::blue.light(110),
00070 Qt::cyan.light(110),
00071 Qt::magenta.light(110),
00072 Qt::yellow.light(110),
00073 Qt::darkRed.light(140),
00074 Qt::darkGreen.light(140),
00075 Qt::darkBlue.light(140),
00076 Qt::darkCyan.light(140),
00077 Qt::darkMagenta.light(140),
00078 Qt::darkYellow.light(140),
00079 Qt::darkGray,
00080 Qt::lightGray
00081 };
00082
00083 static int num_colors = sizeof(dnpcolors)/sizeof(QColor);
00084
00085 QString str;
00086
00087 QBrush brush;
00088 brush.setStyle( Qt::SolidPattern );
00089
00090
00091
00092 assert( dnpData()->get_dnp_type() > -1 );
00093 brush.setColor( dnpcolors[ dnpData()->get_dnp_type() % num_colors ] );
00094
00095
00096 long long int min_width(8);
00097
00098 int used_width = max( min_width, static_cast<long long>((x2_dna - x1_dna + 1 )* width) );
00099
00100
00101 p->fillRect( x_pix, y_pix, used_width , height , brush) ;
00102 return;
00103 }
00104
00105 DnpData * DnpGui::dnpData()
00106 {
00107 return dynamic_cast<DnpData *>( m_data );
00108 }
00109
00110 DnaStrData * DnaStrGui::dnaStrData()
00111 {
00112 return dynamic_cast<DnaStrData *>( m_data );
00113 }
00114
00115 void DnaStrGui::paintMe( QPainter * p,TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00116 double width, int height, int center )
00117 {
00118 if ( height != oldRequestedHeight || width != oldRequestedWidth ) {
00119 oldRequestedHeight = height;
00120 oldRequestedWidth = static_cast<int>(width);
00121
00122 int sz = height;
00123
00124 while ( sz > 0 ) {
00125 f.setPointSize( sz );
00126 QFontMetrics fm( f );
00127
00128 if ( fm.width('m') <= width && fm.height() <= height ) {
00129 currentHeight = fm.height();
00130 currentDescent = fm.descent();
00131 currentWidth = fm.width('m');
00132 break;
00133 }
00134 --sz;
00135 }
00136 }
00137
00138 QString str;
00139 QBrush brush;
00140 brush.setStyle( Qt::SolidPattern );
00141
00142 QColor color;
00143 brush.setColor( Qt::black );
00144
00145 p->setFont(f);
00146
00147 int pixelsHigh = currentHeight;
00148
00149
00150 for ( int i = x1_dna; i <= x2_dna ; ++i ) {
00151 char c = dnaStrData()->dnaVector.stlVector()[i];
00152 QChar c2( c );
00153 QString a( c2 );
00154 p->drawText( static_cast<int>(x_pix + ( ( i- x1_dna ) + 0.25)* width), y_pix + height - ( ( height - pixelsHigh ) / 2 )- currentDescent, a );
00155 }
00156 return;
00157 }
00158 ChromatGui::ChromatGui(SpatialFeatureData * data) : FeatureGui( data )
00159 {
00160
00161 }
00162
00163 ChromatData * ChromatGui::chromatData()
00164 {
00165 return dynamic_cast<ChromatData *>( m_data );
00166 }
00167
00168 void ChromatGui::paintMe( QPainter * p,TR_PIX x_pix, TR_PIX y_pix,TR_DNA x1_dna, TR_DNA x2_dna,
00169 double width, int height, int center )
00170 {
00171
00172
00173
00174 QString str;
00175 QBrush brush;
00176 brush.setStyle( Qt::SolidPattern );
00177 brush.setColor( Qt::red );
00178
00179
00180
00181 int num_tot = chromatData()->cagt_vec[0].stlVector().size();
00182 int length = chromatData()->endPos() - chromatData()->startPos();
00183
00184 int points_per_dna = num_tot/length;
00185
00186 size_t numPoints = points_per_dna*( x2_dna - x1_dna +1);
00187
00188
00189
00190 if ( x2_dna > chromatData()->endPos() || x1_dna < chromatData()->startPos()) {
00191
00192 cerr<<"Out of bounds error"<<endl;
00193 return;
00194 }
00195 int shift = 0;
00196 if ( chromatData()->phd_vec.size() > 0 &&
00197 chromatData()->gap_vec.size() > 0) {
00198
00199
00200
00201
00202
00203 if ( center > 0 && center < chromatData()->endPos()) {
00204 int shift_dna = chromatData()->gap_vec.stlVector()[ center ];
00205 if ( center >= shift_dna ) {
00206
00207 int phd_index = chromatData()->phd_vec.stlVector()[center - shift_dna ];
00208 shift = center*points_per_dna + points_per_dna/2 - phd_index;
00209 }
00210 }
00211 }
00212
00213
00214
00215 double height_scale = double(height)/double(1600);
00216
00217 QPointArray c( numPoints );
00218 QPointArray a( numPoints );
00219 QPointArray g( numPoints );
00220 QPointArray t( numPoints );
00221
00222 for( size_t i = 0; i < numPoints; i++ ) {
00223 int index = i + points_per_dna*x1_dna;
00224
00225 index -= shift;
00226 if ( index < 0 ) index = 0;
00227
00228 if ( static_cast<size_t>(index) > chromatData()->cagt_vec[0].size() - 1 ) index = chromatData()->cagt_vec[0].size() - 1;
00229
00230
00231
00232
00233
00234 c.setPoint(i, static_cast<int>(i* width/points_per_dna + x_pix), static_cast<int>(y_pix + height - chromatData()->cagt_vec[0].stlVector()[index]*height_scale));
00235 a.setPoint(i, static_cast<int>(i* width/points_per_dna + x_pix), static_cast<int>(y_pix + height - chromatData()->cagt_vec[1].stlVector()[index]*height_scale));
00236 g.setPoint(i, static_cast<int>(i* width/points_per_dna + x_pix), static_cast<int>(y_pix + height - chromatData()->cagt_vec[2].stlVector()[index]*height_scale));
00237 t.setPoint(i, static_cast<int>(i* width/points_per_dna + x_pix), static_cast<int>(y_pix + height - chromatData()->cagt_vec[3].stlVector()[index]*height_scale));
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 QPen origpen(p->pen());
00260
00261 p->setPen(QPen(Qt::cyan));
00262 p->drawPolyline(c);
00263 p->setPen(QPen(Qt::green));
00264 p->drawPolyline(a);
00265 p->setPen(QPen(Qt::magenta));
00266 p->drawPolyline(g);
00267 p->setPen(QPen(Qt::red));
00268 p->drawPolyline(t);
00269
00270 p->setPen(origpen);
00271 return;
00272 }
00273
00274 QualityData * QualityGui::qualityData()
00275 {
00276 return dynamic_cast<QualityData *>( m_data );
00277 }
00278
00279 void QualityGui::paintMe( QPainter * p,TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00280 double width, int height, int center )
00281 {
00282 QString str;
00283 QBrush brush;
00284 brush.setStyle( Qt::SolidPattern );
00285
00286 QColor color;
00287 brush.setColor( Qt::red );
00288 for ( int i = x1_dna; i <= x2_dna ; ++i )
00289 {
00290
00291
00292 int v_val = min<int>(255, qualityData()->qualityVector.stlVector()[i] *12);
00293 v_val = max<int>(v_val, 100);
00294
00295 color.setHsv( 0, 0, v_val);
00296
00297 brush.setColor( color );
00298
00299 p->fillRect( static_cast<int>(x_pix + (i - x1_dna )* width),
00300 y_pix, static_cast<int>(width), height , brush) ;
00301
00302
00303
00304
00305
00306
00307 }
00308 return;
00309 }
00310
00311
00312
00313 void TagGui::paintMe( QPainter * p, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00314 double width, int height, int center )
00315 {
00316 static TagColorMap colormap;
00317
00318
00319 QBrush brush;
00320 brush.setStyle( Qt::SolidPattern );
00321
00322
00323
00324 double score = tagData()->getScore();
00325 if ( score < 1 ) {
00326 score = 1;
00327 }
00328
00329 int gb = 255 - (log10(score) * 85);
00330 if (gb < 0) {
00331 gb = 0;
00332 }
00333 brush.setColor( QColor(255, gb, gb) );
00334
00335
00336 p->fillRect( x_pix, y_pix, static_cast<int>((x2_dna - x1_dna + 1 )* width), height , brush) ;
00337
00338 return;
00339 }
00340
00341 TagData * TagGui::tagData()
00342 {
00343 return dynamic_cast<TagData *>( m_data );
00344 }