spatialfeaturedata.h

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 #ifndef FEATUREDATA_H
00016 #define FEATUREDATA_H
00017 
00018 #include <db_cxx.h>
00019 
00020 #include <qcstring.h>
00021 #include <qvaluelist.h>
00022 #include <qdom.h>
00023 #include "generaldata.h"
00024 
00025 #include "trappertypes.h"
00026 #include "trdb.h"
00027 #include "featuregui.h"
00028 #include "trappervector.h"
00029 #include <vector>
00030 #include "featureinfo.h"
00031 #include <iosfwd>
00032 
00033 class QDataStream;
00034 class QString;
00035 
00036 /** \brief Provides a abstract feature object representing a feature, i.e. an attribute to a read. 
00037   * Holds its corresponding read index (recno)  and geometric placement relative to its read.
00038   * 
00039   * The geometrical placement of this feature should be inside the dimensions of its read.
00040   * 
00041   */ 
00042 
00043 class FeatureData : public GeneralData
00044 {
00045 public:
00046   FeatureData( db_recno_t readRecno = 0, TR_DNA startPos = 0, TR_DNA endPos = 0);
00047   virtual ~FeatureData();
00048   TrDb::IndexMap getIndexMap();
00049   TR_DNA startPos() { return s.startPos; }
00050   TR_DNA endPos() { return s.endPos; }
00051   void setStartPos( TR_DNA startPos ) { s.startPos = startPos; }
00052   void setEndPos( TR_DNA endPos ) { s.endPos = endPos; }
00053   void setReadRecno( db_recno_t readRecno ) {  s.readRecno = readRecno; }
00054   FeatureGui * gui();
00055   FeatureInfo* info();
00056   
00057   static int getSeqRecNo(Db * /* dbp */ , const Dbt *  /* pkey */, const Dbt *pdata, Dbt *skey);
00058   static int bt_compare_seqRecNo(DB * db, const DBT *dbt1, const DBT *dbt2);
00059   virtual void readStream( QDataStream & str );
00060   virtual void writeStream( QDataStream & str );
00061   virtual void readAttributes( const QXmlAttributes& attr );
00062   virtual void writeXml( ostream& stream );
00063   virtual void print_debug_info();
00064 
00065 
00066 protected:
00067   virtual FeatureGui * makeGui() = 0;
00068   virtual FeatureInfo* makeInfo();
00069   /** \brief to keep the order of the data members when serializing/unserializing
00070    *
00071    * This might make the serializing/unserializing a bit faster ( probably not significant at all, not tested ).
00072    *   But the main reason for the existence of this class is that the order is kept right between serializing and unserializing. But a problem with this 
00073    approach might be that the endian awareness of QDataStream might be lost, when we don't serialize the
00074    types one by one. It might be a problem when moving berkeley dbs around archictures. But berkeley db probably doesn't allow this anyway?*/
00075   
00076   
00077   struct StorageData
00078   {
00079     TR_DNA startPos;
00080     TR_DNA endPos;
00081     db_recno_t readRecno;
00082   };
00083   StorageData s;
00084   FeatureGui * m_gui;
00085   
00086   FeatureInfo* m_info;
00087   
00088 };
00089 
00090 /** \brief A "dnp", i.e. a defined nucleotype position
00091  */
00092 class DnpData : public FeatureData
00093 {
00094 public:
00095   DnpData( ) : FeatureData(), dnpID(-1)
00096   {}
00097   DnpData( db_recno_t readRecno, TR_DNA startPos, TR_DNA endPos );
00098   void readDom( QDomElement & elem );
00099   std::string uniqueName()  { return std::string("DnpData"); }
00100 //   TrDb::IndexMap getIndexMap() { return FeatureData::getIndexMap(); }
00101   virtual ~DnpData()
00102   {}
00103   void readStream( QDataStream & str );
00104   void writeStream( QDataStream & str );
00105   void writeDom( QDomElement & elem );
00106   void readAttributes( const QXmlAttributes& attr );
00107   void writeXml( ostream& stream );
00108   void set_dnpID(int id);
00109   int get_dnpID();
00110   void set_dnp_type(int t);
00111   int get_dnp_type();
00112   
00113 protected:
00114   FeatureGui * makeGui() { return new DnpGui( this ); }
00115   FeatureInfo * makeInfo() { return new DnpInfo( this ); }
00116   int dnpID;
00117   int type;
00118 };
00119 
00120 /** \brief The nucleotide sequence for the read, e.g. "atag*ct*cgcg"
00121  */
00122 
00123 
00124 class DnaStrData : public FeatureData
00125 {
00126 public:
00127   DnaStrData( ) : FeatureData()
00128   {}
00129   DnaStrData( db_recno_t readRecno, TR_DNA startPos, TR_DNA endPos );
00130   std::string uniqueName() { return std::string("DnaStrData"); }
00131   virtual ~DnaStrData();
00132   void readStream( QDataStream & str );
00133   void writeStream( QDataStream & str );
00134   void writeDom( QDomElement & elem );
00135   void readDom( QDomElement & elem );
00136   void readAttributes( const QXmlAttributes& attr );
00137   void writeXml( ostream& stream );
00138   TrapperVector<char> dnaVector;
00139 protected:
00140   FeatureGui * makeGui() { return new DnaStrGui(this); }
00141   FeatureInfo * makeInfo() { return new DnaStrInfo(this); }
00142 };
00143 /** \brief The chromatogram data for the read */
00144 
00145 class ChromatData : public FeatureData
00146 {
00147 public:
00148   ChromatData() : FeatureData(), cagt_vec(4)
00149   {}
00150   ChromatData( db_recno_t readRecno, TR_DNA startPos, TR_DNA endPos );
00151   std::string uniqueName() { return std::string("ChromatData"); }
00152   virtual ~ChromatData()
00153   {}
00154   void readStream( QDataStream & str );
00155   void writeStream( QDataStream & str );
00156   void writeDom( QDomElement & elem );
00157   void readDom( QDomElement & elem );
00158   void readAttributes( const QXmlAttributes& attr );
00159   void writeXml( ostream& stream );
00160 
00161   std::vector<TrapperVector<Q_UINT32> > cagt_vec;
00162   TrapperVector<Q_UINT32> phd_vec;
00163   TrapperVector<Q_UINT32> gap_vec;
00164   
00165 protected:
00166   FeatureGui * makeGui() { return new ChromatGui(this); }
00167   
00168 };
00169 
00170 /** \brief Quality values of the meassurements/predicted bases
00171  */
00172 
00173 
00174 class QualityData : public FeatureData
00175 {
00176 public:
00177   QualityData() : FeatureData()
00178   {
00179     
00180   }
00181   QualityData( db_recno_t readRecno, TR_DNA startPos, TR_DNA endPos );
00182   std::string uniqueName()
00183   {
00184     return std::string("QualityData");
00185   }
00186   virtual ~QualityData()
00187   {}
00188   //     void setQuality( int quality_ ) { m_quality = quality_; }
00189   int quality(int pos) { return qualityVector.stlVector()[pos]; }
00190   void readStream( QDataStream & str );
00191   void writeStream( QDataStream & str );
00192   void writeDom( QDomElement & elem );
00193   void readDom( QDomElement & elem );
00194   void readAttributes( const QXmlAttributes& attr );
00195   void writeXml( ostream& stream );
00196   
00197   TrapperVector<Q_UINT32> qualityVector;
00198   
00199 protected:
00200   FeatureGui * makeGui() { return new QualityGui(this); }
00201   FeatureInfo * makeInfo() { return new QualityInfo(this); }
00202 };
00203 
00204 
00205 /** \brief General Tag data
00206  */
00207 class TagData : public FeatureData
00208 {
00209 public:
00210   TagData( ) : FeatureData()
00211   {}
00212   TagData( db_recno_t readRecno, TR_DNA startPos, TR_DNA endPos );
00213   void readDom( QDomElement & elem );
00214   virtual std::string uniqueName()  { return std::string("TagData"); }
00215 //   TrDb::IndexMap getIndexMap() { return FeatureData::getIndexMap(); }
00216   virtual ~TagData()
00217   {}
00218   void readStream( QDataStream & str );
00219   void writeStream( QDataStream & str );
00220   void writeDom( QDomElement & elem );
00221   void readAttributes( const QXmlAttributes& attr );
00222   void writeXml( ostream& stream );
00223   
00224   void setInfo(const std::string& inf);
00225   std::string getInfo();
00226   void setScore(const double& s);
00227   double getScore();
00228 
00229 protected:
00230   FeatureGui * makeGui() { return new TagGui( this ); }
00231   FeatureInfo * makeInfo() { return new TagInfo( this ); }
00232   
00233   std::string info;
00234   double score;
00235 };
00236 
00237 #endif

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