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

DnpSortAlgo Class Reference

#include <dnpsort.h>

Inheritance diagram for DnpSortAlgo:

Inheritance graph
[legend]
Collaboration diagram for DnpSortAlgo:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DnpSortAlgo (TrapperDoc *pDoc_, std::set< db_recno_t > &recnoList, AlgoParam *param)
void start ()
void init ()
bool dnpDone (int dnp_id)

Private Types

typedef std::map< int, std::set<
size_t > > 
MapSet
typedef std::vector< std::set<
int > > 
VectorSet

Private Attributes

MapSet dnpID_to_readID
VectorSet readID_to_dnpID
vector< bool > used_reads

Detailed Description

Definition at line 9 of file dnpsort.h.


Member Typedef Documentation

typedef std::map<int, std::set<size_t> > DnpSortAlgo::MapSet [private]
 

Definition at line 20 of file dnpsort.h.

typedef std::vector<std::set<int> > DnpSortAlgo::VectorSet [private]
 

Definition at line 23 of file dnpsort.h.


Constructor & Destructor Documentation

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

Definition at line 12 of file dnpsort.h.

00012                                                                                      : 
00013     RWAlgo(pDoc_, recnoList, param) {}


Member Function Documentation

bool DnpSortAlgo::dnpDone int  dnp_id  ) 
 

Definition at line 126 of file dnpsort.cc.

References dnpID_to_readID.

Referenced by start().

00127 {
00128   return dnpID_to_readID.find( dnp_id ) == dnpID_to_readID.end();
00129 }

void DnpSortAlgo::init  ) 
 

Definition at line 107 of file dnpsort.cc.

References dnpID_to_readID, MAl_Readonly::get_DNP_ID(), MAl_Readonly::get_num_seq(), MAl_Readonly::get_seq_end(), RWAlgo::getMAl(), readID_to_dnpID, and used_reads.

Referenced by start().

00108 {
00109   for( size_t i = 0; i < getMAl()->get_num_seq(); i++ ) {
00110     set<int> tmpset;
00111     readID_to_dnpID.push_back(tmpset);
00112     used_reads.push_back(false);
00113     
00114     for( size_t j = 0; j < getMAl()->get_seq_end( i ); j++ ) {
00115 
00116       if ( getMAl()->is_DNP(i, j) ) {
00117         dnpID_to_readID[ getMAl()->get_DNP_ID(i, j) ].insert( i );
00118         readID_to_dnpID[ i ].insert( getMAl()->get_DNP_ID(i, j) );
00119         used_reads[i] = true;
00120       }
00121       
00122     }
00123   }
00124 }

void DnpSortAlgo::start  )  [virtual]
 

Implements RWAlgo.

Definition at line 7 of file dnpsort.cc.

References dnpDone(), dnpID_to_readID, RWAlgo::getMAl(), init(), readID_to_dnpID, Algo::selectedReads, MAl::set_seq_row(), and used_reads.

00008 {
00009   if ( selectedReads.empty() ) {
00010     return;
00011   }
00012 
00013   bool ok;
00014   int res = QInputDialog::getInteger(
00015                                      "DNP sort", "Enter start row for selected reads:", 0, 1, numeric_limits<int>::max(), 1,
00016                                      &ok, 0 );
00017   
00018   size_t row(1);
00019   if ( ok ) {
00020     // user entered something and pressed OK
00021     row = res;
00022   } else {
00023     // user pressed Cancel
00024     return;
00025   }
00026   
00027 
00028   //Fill structures for bookkeeping
00029   init();
00030 
00031   if ( dnpID_to_readID.empty() ) {
00032     return;
00033   }
00034 
00035   vector<vector<size_t> > groups;
00036   
00037   while ( !dnpID_to_readID.empty() ) {
00038     
00039     //Pick dnp with ID dnp_id
00040     MapSet::iterator firstIt = dnpID_to_readID.begin();
00041     
00042     int dnp_id = firstIt->first;
00043 
00044     //Put into working set
00045     set<int> working_set;
00046     working_set.insert( dnp_id );
00047     
00048     //create new group
00049     groups.push_back( vector<size_t>() );
00050 
00051     while ( !working_set.empty() ) {
00052       
00053       int curr_dnp_id = *(working_set.begin());
00054       working_set.erase( working_set.begin() );
00055       assert( !dnpDone( curr_dnp_id ) );
00056 
00057       //Pull out all reads with dnp curr_dnp_id and add to current group and register new dnps
00058       for( set<size_t>::iterator it = dnpID_to_readID[ curr_dnp_id ].begin(); 
00059            it != dnpID_to_readID[ curr_dnp_id ].end(); ++it ) {
00060         
00061         if ( readID_to_dnpID[ *it ].empty() ) continue;
00062         
00063         assert( used_reads[ *it ] );
00064         groups[ groups.size() - 1 ].push_back( *it );
00065         
00066         for( set<int>::iterator it2 = readID_to_dnpID[ *it ].begin(); 
00067              it2 != readID_to_dnpID[ *it ].end(); ++it2 ) {
00068           if ( *it2 != curr_dnp_id ) {
00069             working_set.insert( *it2 );
00070           }
00071           
00072         }
00073         readID_to_dnpID[ *it ].clear();
00074       } 
00075       
00076       dnpID_to_readID.erase( curr_dnp_id );
00077       assert( dnpDone( curr_dnp_id ) );
00078 
00079     }
00080 
00081   }
00082   
00083   //Assign new rows to groups
00084 //   size_t row(1);
00085   for( size_t i = 0; i < groups.size(); i++ ) {
00086     
00087     for( size_t j = 0; j < groups[ i ].size(); j++ ) {
00088       assert( used_reads[ groups[i][j] ] );
00089       getMAl()->set_seq_row( groups[i][j], row );
00090       row++;
00091     }
00092     row += 5;
00093   }
00094   
00095   //put remaining reads at the bottom
00096   for( size_t i = 0; i < used_reads.size(); i++ ) {
00097     if ( !used_reads[ i ] ) {
00098       getMAl()->set_seq_row( i, row );
00099       row++;
00100       
00101     }
00102     
00103   }
00104   
00105 }


Member Data Documentation

MapSet DnpSortAlgo::dnpID_to_readID [private]
 

Definition at line 21 of file dnpsort.h.

Referenced by dnpDone(), init(), and start().

VectorSet DnpSortAlgo::readID_to_dnpID [private]
 

Definition at line 24 of file dnpsort.h.

Referenced by init(), and start().

vector<bool> DnpSortAlgo::used_reads [private]
 

Definition at line 26 of file dnpsort.h.

Referenced by init(), and start().


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