Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

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 
00024 
00025 
00026 void FeatureGui::paint( QPainter * p, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00027               /*int*/double width, int height, int center )
00028 {
00029     /* we don't need to paint outside the window, thus we seak max and min values */
00030 
00031 //     TR_DNA x1_dna_cut = max( m_data->startPos(), x1_dna )  ;
00032 //     TR_DNA x2_dna_cut = min( m_data->endPos(), x2_dna );
00033 
00034     //EA smarter alternative?
00035   TR_DNA x1_dna_cut;
00036   
00037   if ( (x1_dna_cut = max( m_data->startPos(), x1_dna )) > x2_dna )
00038     return;
00039   
00040   TR_DNA x2_dna_cut;
00041   
00042   if ( ( x2_dna_cut = min( m_data->endPos(), x2_dna ) ) < x1_dna )
00043     return;
00044     
00045 
00046     /*
00047     cerr << "uniquename=" << m_data->uniqueName()
00048 << " x1_dna=" << x1_dna 
00049          << " x2_dna=" << x2_dna
00050          << " startPos=" << m_data->startPos()
00051          << " endPos=" << m_data->endPos()
00052          << " x1_dna_cut=" << x1_dna_cut
00053          << " x2_dna_cut=" << x2_dna_cut
00054          << endl;
00055     */
00056   
00057            x_pix  += ( x1_dna_cut - x1_dna ) * width;
00058 
00059 
00060     paintMe( p, x_pix, y_pix, x1_dna_cut, x2_dna_cut, width, height, center);
00061 }
00062 
00063 void DnpGui::paintMe( QPainter * p, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00064               /*int*/double width, int height, int center )
00065 {
00066   static QColor dnpcolors[] = 
00067     {
00068       Qt::red.light(110),
00069       Qt::green.light(110),
00070       Qt::blue.light(110),
00071       Qt::cyan.light(110),
00072       Qt::magenta.light(110),
00073       Qt::yellow.light(110),
00074       Qt::darkRed.light(140),
00075       Qt::darkGreen.light(140),
00076       Qt::darkBlue.light(140),
00077       Qt::darkCyan.light(140),
00078       Qt::darkMagenta.light(140),
00079       Qt::darkYellow.light(140)
00080     };
00081   
00082   static int num_colors = sizeof(dnpcolors)/sizeof(QColor);
00083   
00084   QString str;
00085 
00086   QBrush brush;
00087   brush.setStyle( Qt::SolidPattern );
00088 
00089 //   assert( dnpData()->get_dnpID() > -1 );
00090 //   brush.setColor( dnpcolors[ dnpData()->get_dnpID() % num_colors ] );
00091   assert( dnpData()->get_dnp_type() > -1 );
00092   brush.setColor( dnpcolors[ dnpData()->get_dnp_type() % num_colors ] );
00093 
00094   
00095   long long int min_width(8);
00096   
00097   int used_width = max( min_width, static_cast<long long>((x2_dna - x1_dna + 1 )* width) );
00098   
00099   //     p->fillRect( x_pix, y_pix, (x2_dna - x1_dna + 1 )* width , height , brush) ;
00100   p->fillRect( x_pix, y_pix, used_width , height , brush) ;
00101   return;
00102 }
00103 
00104 DnpData * DnpGui::dnpData()
00105 {
00106     return dynamic_cast<DnpData *>( m_data );
00107 }
00108 
00109 DnaStrData * DnaStrGui::dnaStrData()
00110 {
00111     return dynamic_cast<DnaStrData *>( m_data );
00112 }
00113 
00114 void DnaStrGui::paintMe( QPainter * p,TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00115                        /*int*/double width, int height, int center )
00116 {
00117   if ( height != oldRequestedHeight || width != oldRequestedWidth ) {
00118     oldRequestedHeight = height;
00119     oldRequestedWidth = width;
00120     
00121     int sz = height;
00122     
00123     while ( sz > 0 ) {
00124       f.setPointSize( sz );
00125       QFontMetrics fm( f );
00126       
00127       if ( fm.width('m') <= width && fm.height() <= height ) {
00128         currentHeight = fm.height();
00129         currentDescent = fm.descent();
00130         currentWidth = fm.width('m');
00131         break;
00132       }
00133       --sz;
00134     }
00135   }
00136   
00137   QString str;
00138   QBrush brush;
00139   brush.setStyle( Qt::SolidPattern );
00140   
00141   QColor color;
00142   brush.setColor( Qt::black );
00143   
00144   p->setFont(f);
00145   
00146   int pixelsHigh = currentHeight;
00147   
00148   
00149   for ( int i = x1_dna; i <= x2_dna ; ++i ) {
00150     char c = dnaStrData()->dnaVector.stlVector()[i];
00151     QChar c2( c );
00152     QString a( c2 );
00153     p->drawText( x_pix + ( ( i- x1_dna ) + 0.25)* width , y_pix + height - ( ( height - pixelsHigh ) / 2 )- currentDescent, a );
00154   }
00155   return;
00156 }
00157 ChromatGui::ChromatGui(FeatureData * data) : FeatureGui( data )
00158 {
00159   
00160 }
00161 
00162 ChromatData * ChromatGui::chromatData()
00163 {
00164     return dynamic_cast<ChromatData *>( m_data );
00165 }
00166 
00167 void ChromatGui::paintMe( QPainter * p,TR_PIX x_pix, TR_PIX y_pix,TR_DNA x1_dna, TR_DNA x2_dna,
00168            /*int*/double width, int height, int center )
00169 {
00170 
00171 
00172 
00173   QString str;
00174   QBrush brush;
00175   brush.setStyle( Qt::SolidPattern );
00176   brush.setColor( Qt::red );
00177   
00178   
00179   //     int numPoints = ( x2_dna - x1_dna +1)*2 ;
00180   int num_tot = chromatData()->cagt_vec[0].stlVector().size();
00181   int length = chromatData()->endPos() - chromatData()->startPos();
00182   
00183   int points_per_dna = num_tot/length;
00184 
00185   int numPoints = points_per_dna*( x2_dna - x1_dna +1); 
00186 
00187   
00188   //Shift calc
00189   if ( x2_dna > chromatData()->endPos() || x1_dna < chromatData()->startPos()) {
00190 //     cerr<<"*************** STRANGE "<<endl;
00191     cerr<<"Out of bounds error"<<endl;
00192     return;
00193   }
00194   int shift = 0;
00195   if ( chromatData()->phd_vec.size() > 0 && 
00196        chromatData()->gap_vec.size() > 0) {
00197     
00198    //Recalc shift
00199     
00200 
00201     
00202     if ( center > 0 && center < chromatData()->endPos()) {
00203       int shift_dna = chromatData()->gap_vec.stlVector()[ center ];
00204       if ( center >= shift_dna ) {
00205         //Should always be true unless we have end gaps which should be impossible...
00206         int phd_index = chromatData()->phd_vec.stlVector()[center - shift_dna ];
00207         shift = center*points_per_dna + points_per_dna/2 - phd_index;
00208       }
00209     }
00210   }
00211   
00212   
00213 
00214   double height_scale = double(height)/double(1600);
00215 
00216   QPointArray c( numPoints );
00217   QPointArray a( numPoints );
00218   QPointArray g( numPoints );
00219   QPointArray t( numPoints );
00220 
00221   for( size_t i = 0; i < numPoints; i++ ) {
00222     int index = i + points_per_dna*x1_dna;
00223     
00224     index -= shift;
00225     if ( index < 0 ) index = 0;
00226     if ( index > chromatData()->cagt_vec[0].size() - 1 ) index = index > chromatData()->cagt_vec[0].size() - 1;
00227     
00228 //     g.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[0].stlVector()[index]*height_scale);
00229 //     a.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[1].stlVector()[index]*height_scale);
00230 //     t.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[2].stlVector()[index]*height_scale);
00231 //     c.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[3].stlVector()[index]*height_scale);
00232     c.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[0].stlVector()[index]*height_scale);
00233     a.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[1].stlVector()[index]*height_scale);
00234     g.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[2].stlVector()[index]*height_scale);
00235     t.setPoint(i, i* width/points_per_dna + x_pix, y_pix + height - chromatData()->cagt_vec[3].stlVector()[index]*height_scale);
00236   }
00237   /*
00238     C = cyan
00239     A = green
00240     G = magenta
00241     T = red
00242   */
00243   /*
00244     normal:
00245     C = red
00246     A = green
00247     G = cyan
00248     T = magenta
00249   */
00250   /*
00251     reverse:
00252     C = magenta
00253     A = cyan
00254     G = green
00255     T = red
00256   */
00257   QPen origpen(p->pen());
00258 
00259   p->setPen(QPen(Qt::cyan));
00260   p->drawPolyline(c);
00261   p->setPen(QPen(Qt::green));
00262   p->drawPolyline(a);
00263   p->setPen(QPen(Qt::magenta));
00264   p->drawPolyline(g);
00265   p->setPen(QPen(Qt::red));
00266   p->drawPolyline(t);
00267   
00268   p->setPen(origpen);
00269   return;
00270 }
00271 
00272 QualityData * QualityGui::qualityData()
00273 {
00274     return dynamic_cast<QualityData *>( m_data );
00275 }
00276 
00277 void QualityGui::paintMe( QPainter * p,TR_PIX x_pix, TR_PIX y_pix, TR_DNA x1_dna, TR_DNA x2_dna,
00278                         /*int*/double width, int height, int center )
00279 {
00280     QString str;
00281     QBrush brush;
00282     brush.setStyle( Qt::SolidPattern );
00283 
00284     QColor color;
00285     brush.setColor( Qt::red );
00286     for ( int i = x1_dna; i <= x2_dna ; ++i )
00287     {
00288 //         color.setHsv( 0, 0, 255 -qualityData()->qualityVector.stlVector()[i] *4);
00289       
00290       int v_val = min<int>(255, qualityData()->qualityVector.stlVector()[i] *12);
00291       v_val = max<int>(v_val, 100);
00292 
00293       color.setHsv( 0, 0, v_val);
00294       
00295       brush.setColor( color );
00296       
00297       p->fillRect( x_pix + (i - x1_dna   )* width  ,
00298                    y_pix,  width , height , brush) ;
00299       
00300       
00301       
00302       
00303       
00304       
00305     }
00306     return;
00307 }

Generated on Fri Mar 17 17:44:24 2006 for trapper by  doxygen 1.4.4