featuregui.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *                                                                             *
00003  *   Copyright (C) 2003  Erik Sjolund,  (<html>Erik Sj&ouml;lund</html>)       *
00004  *                       Center for Genomics and Bioinformatics,               *
00005  *                       Karolinska Institutet,                                *
00006  *                       Stockholm,                                            *
00007  *                       Sweden                                                *
00008  *                                                                             *
00009  *  Author: Erik Sjolund                                                       *
00010  *  Email: erik.sjolund@adivo.se                                               *
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               /*int*/double width, int height, int center )
00027 {
00028     /* we don't need to paint outside the window, thus we seak max and min values */
00029 
00030 //     TR_DNA x1_dna_cut = max( m_data->startPos(), x1_dna )  ;
00031 //     TR_DNA x2_dna_cut = min( m_data->endPos(), x2_dna );
00032 
00033     //EA smarter alternative?
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     cerr << "uniquename=" << m_data->uniqueName()
00047 << " x1_dna=" << x1_dna 
00048          << " x2_dna=" << x2_dna
00049          << " startPos=" << m_data->startPos()
00050          << " endPos=" << m_data->endPos()
00051          << " x1_dna_cut=" << x1_dna_cut
00052          << " x2_dna_cut=" << x2_dna_cut
00053          << endl;
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               /*int*/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 //   assert( dnpData()->get_dnpID() > -1 );
00091 //   brush.setColor( dnpcolors[ dnpData()->get_dnpID() % num_colors ] );
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   //     p->fillRect( x_pix, y_pix, (x2_dna - x1_dna + 1 )* width , height , brush) ;
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                        /*int*/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            /*int*/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   //     int numPoints = ( x2_dna - x1_dna +1)*2 ;
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   //Shift calc
00190   if ( x2_dna > chromatData()->endPos() || x1_dna < chromatData()->startPos()) {
00191 //     cerr<<"*************** STRANGE "<<endl;
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    //Recalc shift
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         //Should always be true unless we have end gaps which should be impossible...
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 //    if ( index > chromatData()->cagt_vec[0].size() - 1 ) index = index > chromatData()->cagt_vec[0].size() - 1;
00228     if ( static_cast<size_t>(index) > chromatData()->cagt_vec[0].size() - 1 ) index = chromatData()->cagt_vec[0].size() - 1;
00229     
00230 //     g.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[0].stlVector()[index]*height_scale);
00231 //     a.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[1].stlVector()[index]*height_scale);
00232 //     t.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[2].stlVector()[index]*height_scale);
00233 //     c.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[3].stlVector()[index]*height_scale);
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     C = cyan
00241     A = green
00242     G = magenta
00243     T = red
00244   */
00245   /*
00246     normal:
00247     C = red
00248     A = green
00249     G = cyan
00250     T = magenta
00251   */
00252   /*
00253     reverse:
00254     C = magenta
00255     A = cyan
00256     G = green
00257     T = red
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                         /*int*/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 //         color.setHsv( 0, 0, 255 -qualityData()->qualityVector.stlVector()[i] *4);
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 //Tag stuff
00312 
00313 void TagGui::paintMe( QPainter * p, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00314               /*int*/double width, int height, int center )
00315 {
00316   static TagColorMap colormap;
00317 
00318 
00319   QBrush brush;
00320   brush.setStyle( Qt::SolidPattern );
00321   
00322 //   brush.setColor( colormap.getColor(tagData()->uniqueName()) );
00323 //   brush.setColor( colormap.getColor(tagData()->getInfo()) );
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 }

Generated on Fri Jul 17 20:19:29 2009 for ngsview by  doxygen 1.5.1