QueryManager/QueryManager.h

Go to the documentation of this file.
00001 /*  Last edited: Mar 25 15:35 2002 (ac2) */
00002 
00003 // #######################################################################
00004 
00005 // SSAHA : Sequence Search and Alignment by Hashing Algorithm
00006 // Version 3.2, released 1st March 2004
00007 // Copyright (c) Genome Research 2002
00008 
00009 // SSAHA is free software; you can redistribute it and/or modify 
00010 // it under the terms of version 2 of the GNU General Public Licence
00011 // as published by the Free Software Foundation.
00012  
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public Licence for more details.
00017  
00018 // You should have received a copy of the GNU General Public Licence
00019 // along with this program; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021 // or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
00022 
00023 // #######################################################################
00024 
00025 // Module Name  : QueryManager
00026 // File Name    : QueryManager.h
00027 // Language     : C++
00028 // Module Author: Anthony J. Cox (ac2@sanger.ac.uk)
00029 
00030 // Include guard:
00031 #ifndef INCLUDED_QueryManager
00032 #define INCLUDED_QueryManager
00033 
00034 // Description:
00035 
00036 // Includes:
00037 #include "MatchStore.h"
00038 
00039 // NB it is good practise for #include statements in header files to be
00040 // replaced by forward declarations if at all possible
00041 class SequenceReader;
00042 class HashTableGeneric;
00043 class HashTableTranslated;
00044 class HashTablePackedProtein;
00045 class MatchAlgorithm;
00046 #include "GlobalDefinitions.h"
00047 #include "MatchStore.h"
00048 #include <iosfwd>
00049 #include <string>
00050 
00051 
00052 // ### Class Declarations ###
00053 
00054 #ifdef MOVED_TO_GLOBAL_DEFINITIONS
00055 // Struct Name: HitInfo
00056 // Description: This contains all info for a 'hit', i.e. when a word from
00057 // the query sequence matches a word in one of the subject sequences. 
00058 struct HitInfo
00059 {
00060   // subjectNum: number of the sequence in the subject database
00061   SequenceNumber subjectNum;
00062   // diff: this is defined as 
00063   //   { position of matching word in subject sequence }
00064   // - { position of matching word in query sequence }
00065   SequenceOffset diff;
00066   // queryPos: this is defined as the position of the matching word in the
00067   // query sequence.
00068   SequenceOffset queryPos;
00069 
00070   // Simple constructor
00071   HitInfo( PositionInDatabase inputHitPos, SequenceOffset inputQueryPos ) :
00072   subjectNum( inputHitPos.sequence ),
00073   diff( inputHitPos.offset - inputQueryPos ),
00074   queryPos( inputQueryPos + 1 ) {}
00075 
00076   // '<' operator must be defined to enable vectors of HitInfo instances
00077   // to be sorted
00078   bool operator<( const HitInfo& hit) const
00079   {
00080     return (    ( subjectNum < hit.subjectNum )
00081              || (    ( subjectNum == hit.subjectNum )
00082                   && (    ( diff < hit.diff )      
00083                        || (    ( diff == hit.diff )      
00084                             && ( queryPos < hit.queryPos )  )  )  )  );
00085   } // ~operator<
00086 
00087   bool operator==( const HitInfo& hit) const
00088   {
00089     return (    ( subjectNum == hit.subjectNum )
00090              && ( diff == hit.diff   ) 
00091              && ( queryPos == hit.queryPos )   );
00092   } // ~operator<
00093 
00094 };
00095 #endif
00096 
00097 class LessThanQuery
00098 {
00099   public:
00100   bool operator()( const HitInfo& lhs, const HitInfo& rhs ) const
00101   {
00102     return ( lhs.queryPos < rhs.queryPos ); 
00103     //  return ( lhs.queryPos + lhs.diff < rhs.queryPos + rhs.diff ); // %%%%%
00104 
00105   }
00106 };
00107 
00108 class LessThanSubject
00109 {
00110   public:
00111   bool operator()( const HitInfo& lhs, const HitInfo& rhs ) const
00112   {
00113     return (    ( lhs.subjectNum < rhs.subjectNum )
00114              || (    ( lhs.subjectNum == rhs.subjectNum )
00115                   && ( lhs.diff < rhs.diff )   )   );   
00116   }
00117 };
00118 
00119 
00120 
00121 #ifdef MOVED_TO_GLOBAL_DEFINITIONS
00122 // Class Name : HitListVector
00123 // Description: This class is a basic storage class for database hit
00124 // information. Inherits interface from HitList and implementation
00125 // from the STL vector class.
00126 class HitListVector : 
00127 public vector<HitInfo>, public HitList
00128 {
00129  public:
00130   virtual void addHit( const PositionInDatabase& hitPos, 
00131                const SequenceOffset& queryPos ) 
00132   { push_back( HitInfo( hitPos,queryPos ) ); }
00133 
00134 }; // ~HitListVector
00135 #endif
00136 
00137 // Match Adder & subclasses
00138 
00139 class MatchAdder
00140 {
00141  public:
00142   MatchAdder( HashTableGeneric& subjectTable ) :
00143     isQueryForward_(true),
00144     //    isSubjectForward_(true), 
00145     //    readFrame_(0), 
00146     pStore_(NULL), 
00147     subjectTable_( subjectTable ) {}
00148   virtual void operator()(  SequenceNumber subjectNum,
00149                             SequenceOffset numBases,
00150                             SequenceOffset queryStart,
00151                             SequenceOffset queryEnd,
00152                             SequenceOffset subjectStart,
00153                             SequenceOffset subjectEnd )=0;
00154   void link( MatchStore& store ) { pStore_ = &store; }
00155   void setQueryForward( void ) { isQueryForward_=true; }
00156   void setQueryReverse( void ) { isQueryForward_=false; }
00157   //  void setSubjectForward( void ) { isSubjectForward_=true; }
00158   //  void setSubjectReverse( void ) { isSubjectForward_=false; }
00159   void setQuerySize( int size ) { querySize_=size; }
00160   //  void setReadFrame( int frame ) { readFrame_ = frame; }
00161 protected:
00162   bool isQueryForward_;
00163   //  bool isSubjectForward_;
00164   //  int  readFrame_;
00165   int  querySize_;
00166   MatchStore* pStore_;
00167   HashTableGeneric& subjectTable_;
00168 };
00169 
00170 
00171 class MatchAdderImp : public MatchAdder
00172 {
00173 public:
00174   MatchAdderImp( HashTableGeneric& subjectTable ) : 
00175     lastSubjectNum_(0), name_(), MatchAdder( subjectTable ) {}
00176     virtual void operator()(  SequenceNumber subjectNum,
00177                                      SequenceOffset numBases,
00178                                      SequenceOffset queryStart,
00179                                      SequenceOffset queryEnd,
00180                                      SequenceOffset subjectStart,
00181                                      SequenceOffset subjectEnd );
00182 
00183 
00184 protected:
00185   string name_;
00186   SequenceNumber lastSubjectNum_;
00187 };
00188 
00189 
00190 // codon query against protein hash table
00191 class MatchAdderCodonProtein : public MatchAdderImp
00192 {
00193 public:
00194   MatchAdderCodonProtein( HashTableGeneric& subjectTable );
00195   virtual void operator()(  SequenceNumber subjectNum,
00196                                      SequenceOffset numBases,
00197                                      SequenceOffset queryStart,
00198                                      SequenceOffset queryEnd,
00199                                      SequenceOffset subjectStart,
00200                                      SequenceOffset subjectEnd );
00201 
00202 };
00203 
00204 // protein query against codon hash table
00205 class MatchAdderProteinCodon : public MatchAdderImp
00206 {
00207 public:
00208   MatchAdderProteinCodon( HashTableTranslated& subjectTable );
00209   virtual void operator()(  SequenceNumber subjectNum,
00210                                      SequenceOffset numBases,
00211                                      SequenceOffset queryStart,
00212                                      SequenceOffset queryEnd,
00213                                      SequenceOffset subjectStart,
00214                                      SequenceOffset subjectEnd );
00215  private:
00216   SequenceOffset size_;
00217   HashTableTranslated& subjectTable_;
00218 
00219 };
00220 
00221 // codon query against codon hash table
00222 class MatchAdderCodonCodon : public MatchAdderImp
00223 {
00224   public:
00225   MatchAdderCodonCodon( HashTableTranslated& subjectTable );
00226   virtual void operator()(  SequenceNumber subjectNum,
00227                                      SequenceOffset numBases,
00228                                      SequenceOffset queryStart,
00229                                      SequenceOffset queryEnd,
00230                                      SequenceOffset subjectStart,
00231                                      SequenceOffset subjectEnd );
00232 
00233  private:
00234   SequenceOffset size_;
00235   HashTableTranslated& subjectTable_;
00236 };
00237 
00238 // MatchPolicy and subclasses
00239 
00240 class MatchPolicy
00241 {
00242  public:
00243   MatchPolicy( HashTableGeneric& subjectTable );
00244   virtual ~MatchPolicy() { delete addMatch_; }
00245 
00246   virtual void operator()
00247   ( WordSequence& querySeqFwd, MatchStore& store, 
00248     MatchAlgorithm& findMatch ) =0;
00249   int getWordLength( void ) const { return queryWordLength_; }
00250  protected:
00251   int queryWordLength_; 
00252   HashTableGeneric& subjectTable_;
00253   MatchAdder* addMatch_;
00254 
00255 };
00256 
00257 
00258 class MatchPolicyDNADNA : public MatchPolicy 
00259 {
00260  public:
00261   MatchPolicyDNADNA( HashTableGeneric& subjectTable );
00262 
00263   virtual void operator()
00264   ( WordSequence& querySeqFwd, 
00265     MatchStore& store, MatchAlgorithm& findMatch );
00266 
00267 };
00268 
00269 class MatchPolicyProteinProtein : public MatchPolicy 
00270 {
00271  public:
00272   MatchPolicyProteinProtein( HashTablePackedProtein& subjectTable );
00273 
00274   virtual void operator()
00275   ( WordSequence& querySeqFwd, 
00276     MatchStore& store, MatchAlgorithm& findMatch );
00277 
00278  protected:
00279   HashTablePackedProtein& subjectTable_;
00280 };
00281 
00282 class SequenceEncoderCodon;
00283 
00284 class MatchPolicyDNAProtein : public MatchPolicy 
00285 {
00286  public:
00287   MatchPolicyDNAProtein( HashTablePackedProtein& subjectTable );
00288 
00289   virtual void operator()
00290   ( WordSequence& querySeqFwd, 
00291     MatchStore& store, MatchAlgorithm& findMatch );
00292 
00293 
00294  protected:
00295   HashTablePackedProtein& subjectTable_;
00296 };
00297 
00298 class MatchPolicyDNATranslated : public MatchPolicy 
00299 {
00300  public:
00301   MatchPolicyDNATranslated( HashTableTranslated& subjectTable );
00302 
00303   virtual void operator()
00304   ( WordSequence& querySeqFwd, 
00305     MatchStore& store, MatchAlgorithm& findMatch );
00306 
00307  protected:
00308   HashTableTranslated& subjectTable_;
00309 };
00310 
00311 
00312 class MatchPolicyProteinTranslated : public MatchPolicy 
00313 {
00314  public:
00315   MatchPolicyProteinTranslated( HashTableTranslated& subjectTable ) ;
00316 
00317   virtual void operator()
00318   ( WordSequence& querySeqFwd, 
00319     MatchStore& store, MatchAlgorithm& findMatch );
00320 
00321 
00322  protected:
00323   HashTableTranslated& subjectTable_;
00324 };
00325 
00326 
00327 // QueryManager and subclasses
00328 
00329 // Class Name : QueryManager
00330 // Description: This class binds together an instance of SequenceReader and
00331 // an instance of HashTableGeneric. 
00332 
00333 class QueryManager
00334 {
00335 
00336   // PUBLIC MEMBER FUNCTIONS
00337   public:
00338 
00339   // Constructors and Destructors
00340 
00341   // Function Name:
00342   // Arguments:
00343   // TYPE  NAME  IN/OUT COMMENT
00344   // Returns: TYPE COMMENT
00345     QueryManager
00346     ( SequenceReader& querySeqs,  HashTableGeneric& subjectSeqs, 
00347       ostream& monitoringStream = cerr);
00348 
00349   // Function Name:
00350   // Arguments:
00351   // TYPE  NAME  IN/OUT COMMENT
00352   // Returns: TYPE COMMENT
00353   virtual ~QueryManager(); 
00354   // (NB destructor should be virtual if class is to be derived from)
00355 
00356   // Manipulator Functions
00357 
00358   // Function Name:
00359   // Arguments:
00360   // TYPE  NAME  IN/OUT COMMENT
00361   // Returns: TYPE COMMENT
00362   void doQuery
00363   ( MatchAlgorithm& match, 
00364     //  ( MatchStore& store, 
00365     MatchTask& task,
00366     int queryStart = 1, 
00367     int queryEnd = -1 );
00368   
00369   // Accessor Functions
00370   // (NB all accessor functions should be 'const')
00371 
00372   // Function Name:
00373   // Arguments:
00374   // TYPE  NAME  IN/OUT COMMENT
00375   // Returns: TYPE COMMENT
00376 
00377   // PROTECTED MEMBER FUNCTIONS 
00378   // (visible to this class and derived classes only)
00379   protected:
00380 
00381   // PRIVATE MEMBER FUNCTIONS
00382   // (visible to instances of this class only)
00383   
00384   private:
00385   QueryManager( const QueryManager&);             // NOT IMPLEMENTED
00386   QueryManager& operator=(const QueryManager&);   // NOT IMPLEMENTED
00387 
00388   public:
00389   HashTableGeneric& subjectTable_;       
00390   ostream& monitoringStream_;
00391 
00392 
00393   // PROTECTED MEMBER DATA
00394   // (visible to this class and derived classes only)
00395   //  protected:
00396  protected:  
00397   SequenceReader&       queryReader_;
00398   MatchPolicy* policy_;
00399 
00400   // PRIVATE MEMBER DATA
00401   private:
00402 
00403 
00404 }; // QueryManager
00405 
00406 
00407 
00408 
00409 
00410 
00411 // ### Function Declarations ###
00412 
00413 // Name:
00414 // Arguments:
00415 // TYPE  NAME  IN/OUT COMMENT
00416 // Returns: TYPE COMMENT
00417 
00418 // End of include guard:
00419 #endif
00420 
00421 // End of file QueryManager.h
00422 
00423 
00424 

Generated on Fri Dec 21 13:12:16 2007 for ssaha by  doxygen 1.5.2