00001 /******************************************************************************* 00002 * * 00003 * Copyright (C) 2003 Erik Sjolund, (<html>Erik Sjö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 #ifndef READDATA_H 00015 #define READDATA_H 00016 00017 #include "generaldata.h" 00018 #include "trdb.h" 00019 #include "trappertypes.h" 00020 #include "trappervector.h" 00021 #include <string> 00022 #include <iosfwd> 00023 00024 /** \brief Representing a read stored in the berkeley db. Holds its name and geometric placement 00025 * in the contig. 00026 * 00027 * The index value of this read, m_recno, is used as a secondary search index for subclasses of 00028 * FeatureData. 00029 */ 00030 00031 00032 class ReadData : public GeneralData 00033 { 00034 public: 00035 // ReadData( TR_DNA row = 0 , TR_DNA startPos = 0, TR_DNA endPos = 0, std::string name = "N/A", std::string mate = "N/A", std::size_t matelen = 0, std::string strand = "U", TR_DNA bg = 0, TR_DNA eg = 0) : GeneralData(), tc_vec(0) 00036 // { 00037 // s.row = row; 00038 // s.startPos = startPos; 00039 // s.endPos = endPos; 00040 00041 // name_ = name; 00042 // mate_ = mate; 00043 // matelen_ = matelen; 00044 // strand_ = strand; 00045 // beginGood_ = bg; 00046 // endGood_ = eg; 00047 // } 00048 ReadData( TR_DNA row = 0 , TR_DNA startPos = 0, TR_DNA endPos = 0) : GeneralData() 00049 { 00050 s.row = row; 00051 s.startPos = startPos; 00052 s.endPos = endPos; 00053 } 00054 ReadData( const ReadData& other ); 00055 ~ReadData(); 00056 void print_debug_info(); 00057 std::string uniqueName() { return std::string("ReadData"); } 00058 TrDb::IndexMap getIndexMap(); 00059 /** Set the row where this "read" is placed in the contig */ 00060 void setRow( TR_DNA row ) { s.row = row; } 00061 /** Set the start position in DNA coordinates where this "read" is placed in the contig */ 00062 void setStartPos( TR_DNA startPos ) { s.startPos = startPos; } 00063 /** Set the end position in DNA coordinates where this "read" is placed in the contig */ 00064 void setEndPos( TR_DNA endPos ) { s.endPos = endPos; } 00065 // void setName( const std::string& n ) { name_ = n; } 00066 // void setMate( const std::string& m ) { mate_ = m; } 00067 // void setMateLength( const std::size_t& l ) { matelen_ = l; } 00068 // void setStrand( const std::string& m ) { strand_ = m; } 00069 // void setBeginGood( TR_DNA index ) { beginGood_ = index; } 00070 // void setEndGood( TR_DNA index ) { endGood_ = index; } 00071 /** Returns the row where this "read" is placed in the contig */ 00072 TR_DNA row() { return s.row; } 00073 /** Returns the start position in DNA coordinates where this "read" is placed in the contig */ 00074 TR_DNA startPos() { return s.startPos; } 00075 /** Returns the end position in DNA coordinates where this "read" is placed in the contig */ 00076 TR_DNA endPos() { return s.endPos; } 00077 // std::string name() { return name_; } 00078 // std::string mate() { return mate_; } 00079 // std::size_t mateLength() { return matelen_; } 00080 // std::string strand() { return strand_; } 00081 // TR_DNA beginGood() { return beginGood_; } 00082 // TR_DNA endGood() { return endGood_; } 00083 00084 00085 //Associate functions for secondary indices 00086 static int getRowPos(Db *dbp, const Dbt *pkey, const Dbt *pdata, Dbt *skey); 00087 // static int getName(Db *dbp, const Dbt *pkey, const Dbt *pdata, Dbt *skey); 00088 //Compare functions for secondary indices 00089 static int bt_compare_rowPos(DB * db, const DBT *a, const DBT *b); 00090 static int bt_compare_end( DB * db, const DBT *dbt1, const DBT *dbt2); 00091 static int bt_compare_start( DB * db, const DBT *dbt1, const DBT *dbt2); 00092 // static int bt_compare_name( DB * db, const DBT *dbt1, const DBT *dbt2); 00093 00094 00095 /** \brief to keep the order of the data members when serializing/unserializing 00096 * 00097 * This might make the serializing/unserializing slightly faster ( probably not significant at all, not tested ). 00098 * And specially the order is kept right between serializing and unserializing. But a problem with this 00099 * approach might be that the endian awareness of QDataStream might be lost, when we don't serialize the 00100 * types one by one. It might be a problem when moving berkeley dbs around archictures. But berkeley db probably doesn't allow this anyway?*/ 00101 struct StorageData 00102 { 00103 TR_DNA row; 00104 TR_DNA startPos; 00105 TR_DNA endPos; 00106 }; 00107 void writeXml( std::ostream& stream ); 00108 void readStream( QDataStream & stream ); 00109 void writeStream( QDataStream & stream ); 00110 void readAttributes( const QXmlAttributes& attr ); 00111 protected: 00112 StorageData s; 00113 // std::string name_; 00114 // std::string mate_; 00115 // std::size_t matelen_; 00116 // std::string strand_; 00117 // TR_DNA beginGood_; 00118 // TR_DNA endGood_; 00119 public: 00120 // TrapperVector<double> tc_vec; 00121 00122 }; 00123 00124 #endif