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

ReadData Class Reference

Representing a read stored in the berkeley db. Holds its name and geometric placement in the contig. More...

#include <readdata.h>

Inheritance diagram for ReadData:

Inheritance graph
[legend]
Collaboration diagram for ReadData:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 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)
 ReadData (const ReadData &other)
 ~ReadData ()
void print_debug_info ()
std::string uniqueName ()
TrDb::IndexMap getIndexMap ()
void setRow (TR_DNA row)
void setStartPos (TR_DNA startPos)
void setEndPos (TR_DNA endPos)
void setName (const std::string &n)
void setMate (const std::string &m)
void setMateLength (const std::size_t &l)
void setStrand (const std::string &m)
void setBeginGood (TR_DNA index)
void setEndGood (TR_DNA index)
TR_DNA row ()
TR_DNA startPos ()
TR_DNA endPos ()
std::string name ()
std::string mate ()
std::size_t mateLength ()
std::string strand ()
TR_DNA beginGood ()
TR_DNA endGood ()
void writeXml (std::ostream &stream)
void readStream (QDataStream &stream)
void writeStream (QDataStream &stream)
void writeDom (QDomElement &elem)
void readDom (QDomElement &elem)
void readAttributes (const QXmlAttributes &attr)

Static Public Member Functions

static int getRowPos (Db *dbp, const Dbt *pkey, const Dbt *pdata, Dbt *skey)
static int getName (Db *dbp, const Dbt *pkey, const Dbt *pdata, Dbt *skey)
static int bt_compare_rowPos (DB *db, const DBT *a, const DBT *b)
static int bt_compare_end (DB *db, const DBT *dbt1, const DBT *dbt2)
static int bt_compare_name (DB *db, const DBT *dbt1, const DBT *dbt2)

Protected Attributes

StorageData s
std::string name_
std::string mate_
std::size_t matelen_
std::string strand_
TR_DNA beginGood_
TR_DNA endGood_

Classes

struct  StorageData
 to keep the order of the data members when serializing/unserializing More...

Detailed Description

Representing a read stored in the berkeley db. Holds its name and geometric placement in the contig.

The index value of this read, m_recno, is used as a secondary search index for subclasses of FeatureData.

Definition at line 31 of file readdata.h.


Constructor & Destructor Documentation

ReadData::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
[inline]
 

Definition at line 34 of file readdata.h.

References beginGood_, endGood_, endPos(), ReadData::StorageData::endPos, mate(), mate_, matelen_, name(), name_, row(), ReadData::StorageData::row, s, startPos(), ReadData::StorageData::startPos, strand(), and strand_.

00034                                                                                                                                                                                                   : GeneralData()
00035   {
00036     s.row = row;
00037     s.startPos = startPos;
00038     s.endPos = endPos;
00039 
00040     name_ = name;
00041     mate_ = mate;
00042     matelen_ = matelen;
00043     strand_ = strand;
00044     beginGood_ = bg;
00045     endGood_ = eg;
00046   }

ReadData::ReadData const ReadData other  ) 
 

Definition at line 21 of file readdata.cpp.

References beginGood_, endGood_, mate_, matelen_, name_, s, and strand_.

00021                                           : GeneralData(other)
00022 {
00023   s = other.s;//Works since StorageData is trivial
00024 //   cerr<<"other.name_: "<<other.name_<<endl;
00025   name_ = other.name_;
00026   mate_ = other.mate_;
00027   matelen_ = other.matelen_;
00028   strand_ = other.strand_;
00029   beginGood_ = other.beginGood_;
00030   endGood_ = other.endGood_;
00031   
00032 }

ReadData::~ReadData  ) 
 

Definition at line 35 of file readdata.cpp.

00036 {}


Member Function Documentation

TR_DNA ReadData::beginGood  )  [inline]
 

Definition at line 74 of file readdata.h.

References beginGood_.

Referenced by TrapperView::getInfo(), and MAl_Readonly::read_seq_from_db().

00074 { return beginGood_; }

int ReadData::bt_compare_end DB *  db,
const DBT *  dbt1,
const DBT *  dbt2
[static]
 

Definition at line 219 of file readdata.cpp.

References ReadData::StorageData::endPos.

Referenced by getIndexMap().

00220 {
00221   /* order after end position */
00222   
00223   ReadData::StorageData * seqData1 = ( ReadData::StorageData *) dbt1->data;
00224   ReadData::StorageData * seqData2 = ( ReadData::StorageData *) dbt2->data;
00225   if ( seqData1->endPos > seqData2->endPos )
00226     return 1;
00227   if ( seqData1->endPos < seqData2->endPos )
00228     return -1;
00229   if ( seqData1->endPos == seqData2->endPos )
00230     return 0;
00231   
00232   /* should never reach this point */
00233   return 0;
00234 }

int ReadData::bt_compare_name DB *  db,
const DBT *  dbt1,
const DBT *  dbt2
[static]
 

Definition at line 236 of file readdata.cpp.

Referenced by getIndexMap().

00237 {
00238   /* order after end position */
00239   
00240   char* seqData1 = ( char* ) dbt1->data;
00241   char* seqData2 = ( char* ) dbt2->data;
00242 
00243 //   cerr<<seqData1<<'\t'<<seqData2<<'\t'<<strcmp(seqData1, seqData2)<<endl;
00244   
00245   return strcmp(seqData1, seqData2);
00246 }

int ReadData::bt_compare_rowPos DB *  db,
const DBT *  a,
const DBT *  b
[static]
 

Definition at line 198 of file readdata.cpp.

References ReadData::StorageData::endPos, and ReadData::StorageData::row.

Referenced by getIndexMap().

00199 {
00200   /* order after row and then after end position */
00201   
00202   ReadData::StorageData * seqData1 = ( ReadData::StorageData *) dbt1->data;
00203   ReadData::StorageData * seqData2 = ( ReadData::StorageData *) dbt2->data;
00204   if ( seqData1->row > seqData2->row )
00205     return 1;
00206   if ( seqData1->row < seqData2->row )
00207     return -1;
00208   if ( seqData1->endPos == seqData2->endPos )
00209     return 0;
00210   if ( seqData1->endPos > seqData2->endPos )
00211     return 1;
00212   if ( seqData1->endPos < seqData2->endPos )
00213     return -1;
00214   
00215   /* should never reach this point */
00216   return 0;
00217 }

TR_DNA ReadData::endGood  )  [inline]
 

Definition at line 75 of file readdata.h.

References endGood_.

Referenced by TrapperView::getInfo(), and MAl_Readonly::read_seq_from_db().

00075 { return endGood_; }

TR_DNA ReadData::endPos  )  [inline]
 

Returns the end position in DNA coordinates where this "read" is placed in the contig

Definition at line 69 of file readdata.h.

References ReadData::StorageData::endPos, and s.

Referenced by ReadsInRect::find(), TrapperView::fitContentsizeToData(), TrapperView::getInfo(), ReadsInRect::hasAnythingInsideWindow(), ReadsInRect::hasRightEndInsideWindow(), print_debug_info(), MAl_Readonly::read_seq_from_db(), ReadData(), and writeDom().

00069 { return s.endPos; }

TrDb::IndexMap ReadData::getIndexMap  )  [virtual]
 

Returns a TrDb::IndexMap that specifies which secondary indexes should be generated for stored data objects of this class in the Berkeley Db backend. Each record in the TrDb::IndexMap generates a secondary index built as a btree ( a DB_BTREE in Berkeley Db wording ). The secondary index is sorted which makes it possible to do queries like "Give me the object that has the smallest value, bigger or equal than x".

And about speed performance, a quote from Berkeley Db documentation says: "Searches take O(log base_b N) time, where base_b is the average number of keys per page, and N is the total number of keys stored"

Implements GeneralData.

Definition at line 168 of file readdata.cpp.

References bt_compare_end(), bt_compare_name(), bt_compare_rowPos(), getName(), getRowPos(), and TrDb::Index::name.

00169 {
00170   TrDb::IndexMap iMap;
00171   TrDb::Index i = {
00172     &ReadData::bt_compare_rowPos,
00173     &ReadData::getRowPos,
00174     QString("pos"),
00175     NULL
00176   };
00177   iMap.insert( make_pair( i.name.ascii(), i ) );
00178   
00179   TrDb::Index i2 = {
00180     &ReadData::bt_compare_end,
00181     &ReadData::getRowPos,
00182     QString("end"),
00183     NULL
00184   };
00185   iMap.insert( make_pair( i2.name.ascii(), i2 ) );
00186 
00187   TrDb::Index i3 = {
00188     &ReadData::bt_compare_name,
00189     &ReadData::getName,
00190     QString("name"),
00191     NULL
00192   };
00193   iMap.insert( make_pair( i3.name.ascii(), i3 ) );
00194   
00195   return iMap;
00196 }

int ReadData::getName Db *  dbp,
const Dbt *  pkey,
const Dbt *  pdata,
Dbt *  skey
[static]
 

Definition at line 262 of file readdata.cpp.

References name(), and Database::setFromDbt().

Referenced by getIndexMap().

00264 {
00265   
00266   memset(skey, 0, sizeof(Dbt));
00267 
00268 //   ReadData* tmp = new ReadData();
00269 //   Database::setFromDbt(pdata, tmp);
00270 
00271 //   skey->set_data( (void*)tmp->name().c_str() );
00272 //   skey->set_size(strlen( tmp->name().c_str() ) + 1 );
00273   
00274   ReadData tmp;
00275   Database::setFromDbt(pdata, &tmp);
00276   char* name = (char*)malloc(sizeof(char)*(tmp.name().length() + 1));
00277   strcpy(name, tmp.name().c_str());
00278   assert( name[ tmp.name().length() ] == '\0' );
00279   skey->set_flags( DB_DBT_APPMALLOC );
00280   skey->set_data( (void*)name ); 
00281   skey->set_size(sizeof(char)*(strlen(name) + 1) );
00282   
00283 
00284   return 0;
00285 }

int ReadData::getRowPos Db *  dbp,
const Dbt *  pkey,
const Dbt *  pdata,
Dbt *  skey
[static]
 

Definition at line 248 of file readdata.cpp.

Referenced by getIndexMap().

00250 {
00251   //  memset(skey, 0, sizeof(Dbt));
00252   //  ReadData::StorageData * data = ( ReadData::StorageData * ) pdata->get_data();
00253   //  skey->set_data( ( u_int8_t * ) (& (data->readRecno)) );
00254   // skey->set_size(sizeof( db_recno_t ));
00255   
00256   memset(skey, 0, sizeof(Dbt));
00257   skey->set_data( pdata->get_data() );
00258   skey->set_size(sizeof( struct ReadData::StorageData ));
00259   return(0);
00260 }

std::string ReadData::mate  )  [inline]
 

Definition at line 71 of file readdata.h.

References mate_.

Referenced by TrapperView::getInfo(), MAl_Readonly::read_seq_from_db(), ReadData(), and FindMatesAlgo::start().

00071 { return mate_; }

std::size_t ReadData::mateLength  )  [inline]
 

Definition at line 72 of file readdata.h.

References matelen_.

Referenced by TrapperView::getInfo(), MAl_Readonly::read_seq_from_db(), and FindMatesAlgo::start().

00072 { return matelen_; }

std::string ReadData::name  )  [inline]
 

Definition at line 70 of file readdata.h.

References name_.

Referenced by TrapperDoc::all_readnames(), TrapperView::getInfo(), getName(), TrapperApp::map_reads_to_docs(), MAl_Readonly::read_seq_from_db(), and ReadData().

00070 { return name_; }

void ReadData::print_debug_info  )  [virtual]
 

Prints some info for debugging, this should be removed in release version!

Reimplemented from GeneralData.

Definition at line 38 of file readdata.cpp.

References endPos(), GeneralData::getRecno(), row(), startPos(), and uniqueName().

00039 {
00040   cerr<<"This is class "<<uniqueName()<<endl;
00041   cerr<<"recno: "<<getRecno()<<endl;
00042   cerr<<"row: "<<row()<<endl;
00043   cerr<<"startPos: "<<startPos()<<endl;
00044   cerr<<"endPos: "<<endPos()<<endl;
00045 }

void ReadData::readAttributes const QXmlAttributes &  attr  )  [virtual]
 

Loads the state of this object from QXmlAttributes.This method is used for importing.

Implements GeneralData.

Definition at line 119 of file readdata.cpp.

References beginGood_, endGood_, ReadData::StorageData::endPos, mate_, matelen_, name_, ReadData::StorageData::row, s, ReadData::StorageData::startPos, and strand_.

00120 {
00121   if ( attr.value("row") != "" ) {
00122     QString rowPosStr = attr.value("row");
00123     s.row = rowPosStr.toLong();
00124   }
00125   if ( attr.value("startPos") != "" ) {
00126     QString startPosStr = attr.value("startPos");
00127     s.startPos = startPosStr.toLong();
00128   }
00129   if ( attr.value("endPos") != "" ) {
00130     QString endPosStr = attr.value("endPos");
00131     s.endPos = endPosStr.toLong();
00132     endGood_ = s.endPos - s.startPos;
00133   }
00134   if ( attr.value("name") != "" ) {
00135     name_ = attr.value("name").ascii();
00136   }
00137   if ( attr.value("mate") != "" ) {
00138     mate_ = attr.value("mate").ascii();
00139   }
00140   if ( attr.value("matelen") != "" ) {
00141     matelen_ = attr.value("matelen").toInt();
00142   }
00143   if ( attr.value("strand") != "" ) {
00144     strand_ = attr.value("strand").ascii();
00145   }
00146   if ( attr.value("beginGood") != "" ) {
00147     beginGood_ = attr.value("beginGood").toInt();
00148   }
00149   if ( attr.value("endGood") != "" ) {
00150     endGood_ = attr.value("endGood").toInt();
00151   }
00152 }

void ReadData::readDom QDomElement &  elem  )  [virtual]
 

Loads the state of this object from a dom tree. Or in other words reads in the values of the data members of this class from a dom tree underneath the QDomElement elem. This method is used for importing.

Reimplemented from GeneralData.

Definition at line 104 of file readdata.cpp.

References ReadData::StorageData::endPos, name_, GeneralData::readDom(), ReadData::StorageData::row, s, and ReadData::StorageData::startPos.

00105 {
00106   GeneralData::readDom( elem );
00107   QString startPosStr = elem.attribute("startPos");
00108   long startPosLong = startPosStr.toLong();
00109   // is long the same thing as Q_INT64 ?
00110   s.startPos = startPosLong;
00111   QString endPosStr = elem.attribute("endPos");
00112   long endPosLong = endPosStr.toLong();
00113   s.endPos = endPosLong;
00114   QString rowStr = elem.attribute("row");
00115   long rowLong = rowStr.toLong();
00116   s.row = rowLong;
00117   name_ = elem.attribute("name").ascii();
00118 }

void ReadData::readStream QDataStream &  stream  )  [virtual]
 

Loads the state of this object from a byte stream. Or in other words reads and unserializes a byte stream to set the values of this class object. This method is used for loading a GeneralData object from Berkeley Db.

Implements GeneralData.

Definition at line 47 of file readdata.cpp.

References beginGood_, endGood_, mate_, matelen_, name_, s, and strand_.

00048 {
00049   QIODevice * dev = stream.device();
00050   Q_ASSERT( dev );
00051   stream.readRawBytes( ( char * ) &s, sizeof ( StorageData ) );  
00052   //Should work, since std::string conforms to trappervector interface
00053   QString tmp;
00054   stream>>tmp;
00055   name_ = tmp.ascii();
00056   stream>>tmp;
00057   mate_ = tmp.ascii();
00058   stream>>matelen_;
00059   stream>>tmp;
00060   strand_ = tmp.ascii();
00061   stream>>beginGood_;
00062   stream>>endGood_;
00063 }

TR_DNA ReadData::row  )  [inline]
 

Returns the row where this "read" is placed in the contig

Definition at line 65 of file readdata.h.

References ReadData::StorageData::row, and s.

Referenced by ReadsInRect::find(), TrapperView::findRead(), TrapperView::fitContentsizeToData(), ReadsInRect::hasAnythingInsideWindow(), print_debug_info(), MAl_Readonly::read_seq_from_db(), ReadData(), TrapperView::selectBetween(), MoveAlgo::start(), and writeDom().

00065 { return s.row; }

void ReadData::setBeginGood TR_DNA  index  )  [inline]
 

Definition at line 62 of file readdata.h.

References beginGood_.

Referenced by MAl::commit_seq_to_db(), and MoveAlgo::start().

00062 { beginGood_ = index; }

void ReadData::setEndGood TR_DNA  index  )  [inline]
 

Definition at line 63 of file readdata.h.

References endGood_.

Referenced by MAl::commit_seq_to_db(), and MoveAlgo::start().

00063 { endGood_ = index; }

void ReadData::setEndPos TR_DNA  endPos  )  [inline]
 

Set the end position in DNA coordinates where this "read" is placed in the contig

Definition at line 57 of file readdata.h.

References ReadData::StorageData::endPos, and s.

Referenced by MAl::commit_seq_to_db(), ReadsInRect::find(), and MoveAlgo::start().

00057 { s.endPos = endPos; }

void ReadData::setMate const std::string &  m  )  [inline]
 

Definition at line 59 of file readdata.h.

References mate_.

Referenced by MAl::commit_seq_to_db(), TrapperDoc::importMates(), and MoveAlgo::start().

00059 { mate_ = m; }

void ReadData::setMateLength const std::size_t &  l  )  [inline]
 

Definition at line 60 of file readdata.h.

References matelen_.

Referenced by MAl::commit_seq_to_db(), TrapperDoc::importMates(), and MoveAlgo::start().

00060 { matelen_ = l; }

void ReadData::setName const std::string &  n  )  [inline]
 

Definition at line 58 of file readdata.h.

References name_.

Referenced by MAl::commit_seq_to_db(), TrapperView::findRead(), TrapperDoc::importChromat(), TrapperDoc::importMates(), TrapperDoc::importPhd(), MoveAlgo::start(), and FindMatesAlgo::start().

00058 { name_ = n; }

void ReadData::setRow TR_DNA  row  )  [inline]
 

Set the row where this "read" is placed in the contig

Definition at line 53 of file readdata.h.

References ReadData::StorageData::row, and s.

Referenced by MAl::commit_seq_to_db(), ReadsInRect::find(), TrapperView::selectBetween(), and MoveAlgo::start().

00053 { s.row = row; }

void ReadData::setStartPos TR_DNA  startPos  )  [inline]
 

Set the start position in DNA coordinates where this "read" is placed in the contig

Definition at line 55 of file readdata.h.

References s, and ReadData::StorageData::startPos.

Referenced by MAl::commit_seq_to_db(), TrapperView::selectBetween(), and MoveAlgo::start().

00055 { s.startPos = startPos; }

void ReadData::setStrand const std::string &  m  )  [inline]
 

Definition at line 61 of file readdata.h.

References strand_.

Referenced by MAl::commit_seq_to_db(), and MoveAlgo::start().

00061 { strand_ = m; }

TR_DNA ReadData::startPos  )  [inline]
 

Returns the start position in DNA coordinates where this "read" is placed in the contig

Definition at line 67 of file readdata.h.

References s, and ReadData::StorageData::startPos.

Referenced by TrapperView::findRead(), TrapperView::getInfo(), ReadsInRect::hasAnythingInsideWindow(), print_debug_info(), MAl_Readonly::read_seq_from_db(), ReadData(), MoveAlgo::start(), and writeDom().

00067 { return s.startPos; }

std::string ReadData::strand  )  [inline]
 

Definition at line 73 of file readdata.h.

References strand_.

Referenced by TrapperView::getInfo(), TrapperDoc::importChromat(), TrapperDoc::importPhd(), MAl_Readonly::read_seq_from_db(), and ReadData().

00073 { return strand_; }

std::string ReadData::uniqueName  )  [inline, virtual]
 

Specifies a name that uniquely should identify this class. It will be used for lookups in the GeneralMaker class.

Implements GeneralData.

Definition at line 50 of file readdata.h.

Referenced by print_debug_info().

00050 { return std::string("ReadData"); }

void ReadData::writeDom QDomElement &  elem  )  [virtual]
 

Saves the state of this object to a dom tree. Or in other words writes out the internal data held in this class to a dom tree underneath the QDomElement elem. This method is used for exporting.

Reimplemented from GeneralData.

Definition at line 88 of file readdata.cpp.

References ReadData::StorageData::endPos, endPos(), name_, ReadData::StorageData::row, row(), s, ReadData::StorageData::startPos, startPos(), and GeneralData::writeDom().

00089 {
00090   GeneralData::writeDom( elem );
00091   Q_INT32 startPos = s.startPos;
00092   Q_INT32 endPos = s.endPos;
00093   Q_INT32 row = s.row;
00094   QString startPosStr, endPosStr, rowStr;
00095   startPosStr.setNum( startPos );
00096   endPosStr.setNum( endPos );
00097   rowStr.setNum( row );
00098   elem.setAttribute("startPos", startPosStr );
00099   elem.setAttribute("endPos", endPosStr);
00100   elem.setAttribute("row", rowStr);
00101   elem.setAttribute("name", name_ );
00102 }

void ReadData::writeStream QDataStream &  stream  )  [virtual]
 

Saves the state of this object to a byte stream. Or in other words serializes and writes the internal data held in this class object to a byte stream. This method is used for storing a GeneralData object into Berkeley Db.

Implements GeneralData.

Definition at line 65 of file readdata.cpp.

References beginGood_, endGood_, mate_, matelen_, name_, s, and strand_.

Referenced by TrapperView::writeSelected().

00066 {
00067   QIODevice * dev = stream.device();
00068   Q_ASSERT( dev );
00069   if ( ! ( IO_WriteOnly & dev->mode() ) )
00070     {
00071       cerr << "data stream should be writeonly" << endl;
00072       exit(1);
00073     }
00074   stream.writeRawBytes( ( char * ) &s, sizeof ( StorageData ) );
00075   //Should work, since std::string conforms to trappervector interface
00076   QString tmp;
00077   tmp = name_;
00078   stream<<tmp;
00079   tmp = mate_;
00080   stream<<tmp;
00081   stream<<matelen_;
00082   tmp = strand_;
00083   stream<<tmp;
00084   stream<<beginGood_;
00085   stream<<endGood_;
00086 }

void ReadData::writeXml std::ostream &  stream  )  [virtual]
 

Writes the state of this object to a stream as an XML entry. This method is used for exporting

Implements GeneralData.

Referenced by TrapperDoc::saveExport().


Member Data Documentation

TR_DNA ReadData::beginGood_ [protected]
 

Definition at line 111 of file readdata.h.

Referenced by beginGood(), readAttributes(), ReadData(), readStream(), setBeginGood(), and writeStream().

TR_DNA ReadData::endGood_ [protected]
 

Definition at line 112 of file readdata.h.

Referenced by endGood(), readAttributes(), ReadData(), readStream(), setEndGood(), and writeStream().

std::string ReadData::mate_ [protected]
 

Definition at line 108 of file readdata.h.

Referenced by mate(), readAttributes(), ReadData(), readStream(), setMate(), and writeStream().

std::size_t ReadData::matelen_ [protected]
 

Definition at line 109 of file readdata.h.

Referenced by mateLength(), readAttributes(), ReadData(), readStream(), setMateLength(), and writeStream().

std::string ReadData::name_ [protected]
 

Definition at line 107 of file readdata.h.

Referenced by name(), readAttributes(), ReadData(), readDom(), readStream(), setName(), writeDom(), and writeStream().

StorageData ReadData::s [protected]
 

Definition at line 106 of file readdata.h.

Referenced by endPos(), readAttributes(), ReadData(), readDom(), readStream(), row(), setEndPos(), setRow(), setStartPos(), startPos(), writeDom(), and writeStream().

std::string ReadData::strand_ [protected]
 

Definition at line 110 of file readdata.h.

Referenced by readAttributes(), ReadData(), readStream(), setStrand(), strand(), and writeStream().


The documentation for this class was generated from the following files:
Generated on Fri Mar 17 17:45:00 2006 for trapper by  doxygen 1.4.4