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

readlistalgo.cc

Go to the documentation of this file.
00001 #include "readlistalgo.h"
00002 #include <qdir.h>
00003 #include <qfiledialog.h>
00004 #include <set>
00005 #include <map>
00006 
00007 using namespace std;
00008 
00009 void ReadListAlgo::start()
00010 {
00011   
00012   //Get readlist filename
00013   
00014   if ( getMAl()->get_num_seq() == 0 ) {
00015     cerr<<"Nothing to be done here! "<<endl;
00016     return;
00017   }
00018   
00019   
00020   
00021   QString currdir = QDir::currentDirPath();
00022   
00023   QString filename = QFileDialog::getOpenFileName(
00024                                            currdir,
00025                                            0,
00026                                            0,
00027                                            "open listfile file dialog",
00028                                            "Choose a read list file to open" );
00029 
00030   if ( filename.isEmpty() ) return;
00031 
00032   //Parse list
00033 
00034   QFile f( filename );
00035   
00036   if ( !f.open(IO_ReadOnly) ) {
00037     cerr<<"ReadListAlgo::start(): Could not open file "<<filename<<", exiting!"<<endl;
00038     return;
00039   }
00040   
00041   QTextStream t( &f );        // use a text stream
00042   QString s;
00043 
00044   set<QString> readlist;
00045 
00046   while ( !t.atEnd() ) {
00047     s = t.readLine();       // line of text excluding '\n'
00048     s = s.simplifyWhiteSpace();
00049 
00050     readlist.insert(s);
00051   }
00052 
00053   //NB, names in list can be truncated and thus match several reads
00054   //Quick'n'dirty: add names of selected reads to a easily searchable structure
00055   
00056   map<QString, size_t> selected_readnames;
00057   
00058   for( size_t i = 0; i < getMAl()->get_num_seq(); i++ ) {
00059     selected_readnames.insert(make_pair(getMAl()->get_name(i), i));
00060     getMAl()->select_read(i, false);    
00061   }
00062   
00063   //Select reads from list
00064   for( set<QString>::iterator it = readlist.begin(); it != readlist.end(); ++it ) {
00065     for( map<QString, size_t>::iterator it2 = selected_readnames.lower_bound(*it);
00066          it2 != selected_readnames.upper_bound(*it + '~'); ++it2 ) {
00067       getMAl()->select_read((*it2).second, true);
00068     }
00069   }
00070 
00071 }
00072 

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