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

findmatesalgo.cc

Go to the documentation of this file.
00001 #include "findmatesalgo.h"
00002 #include "algoparam.h"
00003 #include <iostream>
00004 #include "readdata.h"
00005 #include "generaldata.h"
00006 #include <cassert>
00007 #include <qmessagebox.h>
00008 #include <qinputdialog.h>
00009 #include <limits>
00010 
00011 using namespace std;
00012 
00013 void FindMatesAlgo::start()
00014 {
00015   if ( selectedReads.empty() ) {
00016     return;
00017   }
00018 
00019   int res = QMessageBox::question( 0, "Find mates", "All mates, or mates within an interval?", "All", "Interval", "Cancel", 0, 2 );
00020   
00021   size_t min_ = 0;
00022   size_t max_ = numeric_limits<size_t>::max();
00023 
00024   if( res == 2 ) {
00025     return;
00026   }
00027   else if ( res == 1 ) {
00028     bool ok;
00029     int low = QInputDialog::getInteger(
00030                                        "Find mates", "Lower bound", 0, 0, numeric_limits<int>::max(), 1,
00031                                        &ok, 0 );
00032     
00033     if ( ok ) {
00034       // user entered something and pressed OK
00035       min_ = low;
00036     } else {
00037       // user pressed Cancel
00038       return;
00039     }
00040     int high = QInputDialog::getInteger(
00041                                         "Find mates", "Upper bound", numeric_limits<int>::max(), low, numeric_limits<int>::max(), 1,
00042                                         &ok, 0 );
00043     
00044     if ( ok ) {
00045       // user entered something and pressed OK
00046       max_ = high;
00047     } else {
00048       // user pressed Cancel
00049       return;
00050     }
00051     
00052   }
00053   
00054 
00055   set< db_recno_t > selected_temp = selectedReads;
00056   
00057   selectedReads.clear();
00058 
00059   for (set< db_recno_t >::iterator it = selected_temp.begin(); it != selected_temp.end(); it++ ){
00060 
00061     Database::PrimaryIterator<ReadData>* read_it = new Database::PrimaryIterator<ReadData>(pDoc, "ReadData");
00062 
00063     int ret_read = read_it->setFromRecno(*it);
00064     ReadData* r_test = (ret_read != DB_NOTFOUND) ? read_it->answer() : 0;
00065     assert( r_test );
00066     
00067 
00068     //Find mate (if any) and get its recno
00069     
00070     Database::SecondaryIterator<ReadData>* name_it =
00071       new Database::SecondaryIterator<ReadData>( "name", pDoc, "ReadData" );
00072     name_it->key()->setName( r_test->mate() );
00073     if ( name_it->set() == 0 && 
00074          name_it->answer()->mateLength() >= min_ && 
00075          name_it->answer()->mateLength() <= max_ ) {
00076       selectedReads.insert(*it);
00077       selectedReads.insert(name_it->answer()->getRecno());
00078       
00079     }
00080     
00081     delete name_it;
00082     delete read_it;
00083     
00084 
00085   }
00086   
00087 }
00088 

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