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

MoveAlgo Class Reference

#include <movealgo.h>

Inheritance diagram for MoveAlgo:

Inheritance graph
[legend]
Collaboration diagram for MoveAlgo:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 MoveAlgo (TrapperDoc *pDoc_, std::set< db_recno_t > &recnoList, AlgoParam *param)
void start ()

Detailed Description

Definition at line 6 of file movealgo.h.


Constructor & Destructor Documentation

MoveAlgo::MoveAlgo TrapperDoc pDoc_,
std::set< db_recno_t > &  recnoList,
AlgoParam param
[inline]
 

Definition at line 9 of file movealgo.h.

00009 : Algo(pDoc_, recnoList, param) {}


Member Function Documentation

void MoveAlgo::start  )  [virtual]
 

Implements Algo.

Definition at line 13 of file movealgo.cpp.

References Database::PrimaryIterator< T >::answer(), Database::Creator< T >::create(), Database::Creator< T >::data(), ReadsInRect::first(), AlgoMoveParam::get_x_delta(), AlgoMoveParam::get_y_delta(), Algo::my_param, Algo::pDoc, ReadData::row(), Algo::selectedReads, AlgoMoveParam::set_x_delta(), AlgoMoveParam::set_y_delta(), ReadData::setBeginGood(), ReadData::setEndGood(), ReadData::setEndPos(), Database::PrimaryIterator< T >::setFromRecno(), ReadData::setMate(), ReadData::setMateLength(), ReadData::setName(), GeneralData::setRecno(), ReadData::setRow(), ReadData::setStartPos(), ReadData::setStrand(), ReadsInRect::setWindowCoord(), and ReadData::startPos().

00014 {
00015   if ( selectedReads.empty() ) {
00016     return;
00017   }
00018 
00019   bool allow_overlap(true);
00020 
00021   AlgoMoveParam* param = (AlgoMoveParam*)my_param;//This is so ugly, needs to be fixed!!
00022   assert(param);
00023   
00024   int y_delta = param->get_y_delta();
00025   int x_delta = param->get_x_delta();
00026 
00027   if ( y_delta == 0 && x_delta == 0) {
00028     return;
00029   }
00030   
00031   //NB: This should be encapsulated, see TODO list...
00032 
00033   //Have to do it in this ugly way since multiple cursors can't be open simultaneously...
00034 
00035   vector<ReadData> readvec;
00036 
00037 
00038   int debug_i(0);
00039   for (set< db_recno_t >::iterator it = selectedReads.begin(); it != selectedReads.end(); it++ ){
00040     //Have to do it in this ugly way since multiple cursors can't be open simultaneously... FIX THIS!!
00041     //Also, had to move this sucker here (see above) beacause of some NASTY bug with changing read names...
00042     Database::PrimaryIterator<ReadData>* read_it = new Database::PrimaryIterator<ReadData>(pDoc, "ReadData");
00043 
00044     int ret_read = read_it->setFromRecno(*it);
00045     ReadData* r_test = (ret_read != DB_NOTFOUND) ? read_it->answer() : 0;
00046     assert( r_test );
00047     readvec.push_back( *r_test );//Need a copy constructor...
00048   
00049     delete read_it;
00050 
00051     //Check that read does not end up on negative row or negative start index
00052 
00053     if ( (static_cast<int>(r_test->row()) + y_delta) < 0 ||
00054          (static_cast<int>(r_test->startPos()) + x_delta) < 0 ) {
00055       param->set_y_delta(0);
00056       param->set_x_delta(0);
00057       
00058       cerr<<"Read will end up on negative row or col, cancelling move "<<endl;
00059       return;
00060     }
00061 
00062   }
00063   
00064 
00065   
00066   for(size_t i = 0; i < readvec.size(); i++ ) {
00067         
00068     
00069     //Check so that new destination isn't on another read. Might cause cursor problem, so watch out...
00070     
00071     ReadsInRect* dest_it = new ReadsInRect(pDoc);
00072     dest_it->setWindowCoord( readvec[i].startPos() + x_delta, readvec[i].row() + y_delta, readvec[i].endPos() - readvec[i].startPos(), 1);
00073     
00074     if ( !allow_overlap && dest_it->first() ) {
00075       //Ooops, read already here...
00076 //       cerr<<"Can't move read to occupied space!"<<endl;
00077       delete dest_it;
00078     }
00079     else {
00080       delete dest_it;//This is so ugly...
00081       Database::Creator<ReadData> a_creator(pDoc, "ReadData");
00082       
00083 //       cerr<<"r_test->getRecno(): "<<readvec[i].getRecno()<<endl;
00084       a_creator.data()->setRecno(readvec[i].getRecno());
00085       a_creator.data()->setRow(readvec[i].row() + y_delta);
00086       a_creator.data()->setStartPos(readvec[i].startPos() + x_delta);
00087       a_creator.data()->setEndPos(readvec[i].endPos() + x_delta);
00088       a_creator.data()->setName(readvec[i].name());
00089       a_creator.data()->setMate(readvec[i].mate());
00090       a_creator.data()->setMateLength(readvec[i].mateLength());
00091       a_creator.data()->setStrand(readvec[i].strand());
00092       a_creator.data()->setBeginGood(readvec[i].beginGood());
00093       a_creator.data()->setEndGood(readvec[i].endGood());
00094       
00095 
00096 
00097       a_creator.create(true);
00098     }
00099     
00100   }
00101 }


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