Generated on Tue Dec 16 12:49:16 2008 for BIU-2.2.0 by doxygen 1.5.1

src/biu/RNAStructure_TB.hh

Go to the documentation of this file.
00001 #ifndef RNASTRUCTURE_TB_HH_
00002 #define RNASTRUCTURE_TB_HH_
00003 
00004 
00005 #include "biu/BioMolecule.hh"
00006 #include "biu/AllowedBasePairs.hh"
00007 
00008 namespace biu
00009 {
00010     
00030     class RNAStructure_TB : public BioMolecule
00031     {
00032     protected:
00033         
00034             // Before:
00035             //  -A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z-
00036             
00037             // After binding S with K
00038             //  -A-B-C-D-E-F-G-H-I-J-K-T-U-V-W-X-Y-Z-
00039             //                       |
00040             //                      -S-L-M-N-O-P-Q-R-
00041             
00042             //      -   <=>     next
00043             //      |   <=>     pair
00044         class TreeItem {
00045         public:
00046             
00047             size_t next;    //  next in sequence if there are no bonds, 
00048                             //  next in the same level, where a new bond does not cause a non-nested structure
00049             size_t pair;    // (lower/upper) level when paired
00050                              
00051             
00052             bool 
00053             operator == (const TreeItem& op2) const {
00054                 return ((this->next==op2.next)&&(this->pair==op2.pair));
00055             }
00056         };
00057         
00058         
00059         
00060         
00061     public: //----------- abstract functions (BioMolecule)
00062             
00063         
00064             Sequence getSequence() const ;
00065 
00066             
00068             Structure getStructure() const ;
00069         
00073             virtual double  getEnergy() const ;
00074     
00075             
00078             size_t  getLength() const ;
00079         
00080             
00085             bool isValid() const;
00086             
00087             
00092             std::string getStringRepresentation() const;
00093             
00094         
00095             //-----------(END) abstract functions (BioMolecule)
00096         
00097         
00098         
00099         
00100     protected:
00101 
00102 
00104          static const size_t    MIN_LOOP_LENGTH;
00105 
00106         
00110          static const Alphabet STRUCT_ALPH;
00111         
00112         
00114         const bool      seqShared;
00115 
00116         
00120         const AllowedBasePairs*     bPair;
00121 
00122         
00123             // - Detailed status about the structure, i.e. why exactly the structure "is" invalid.
00124             //   Structure problem, Basepair problem or Loopsize problem 
00125             // - 0 if valid
00126             // - Status is used internally to determine whether an invalidity cause is determined or not yet
00127         mutable size_t strucStatus;
00128         
00129         
00131         Sequence*       rnaSeq;
00132         
00133 
00135             //  - Storing it as string was prefered because the energy calculation requires a string,
00136             //      otherwise the Structure datatype could be used instead.  
00137         std::string bracketStructStr;
00138         
00139 
00141         std::vector<TreeItem>* validTreeStruc; 
00142         
00143         
00144     public:
00145         
00146         
00148         static const Alphabet::AlphElem STRUCT_BND_OPEN;
00150         static const Alphabet::AlphElem STRUCT_BND_CLOSE;
00152         static const Alphabet::AlphElem STRUCT_UNBOUND;
00153         
00155             //  i.e. means that it is not pair to any base
00156         static const size_t INVALID_INDEX;
00157         
00158         
00159             // Structure Status Bits 
00160         static const size_t BASEPAIRS_VALIDITY ;            //000001
00161         static const size_t BASEPAIRS_VALIDITY_CALCULATED ; //000010
00162         static const size_t LOOPSIZE_VALIDITY ;             //000100
00163         static const size_t LOOPSIZE_VALIDITY_CALCULATED ;  //001000
00164         static const size_t STRUCTURE_VALIDITY ;            //010000
00165         static const size_t STRUCTURE_VALIDITY_CALCULATED ; //100000
00166         
00167         //  Do not change the following values without checking 
00168         //size_t moveType(size_t i, size_t j) const;
00169         static const size_t INSERT_MOVE;
00170         static const size_t SHIFT_MOVE;
00171         static const size_t REVERSE_SHIFT_MOVE;
00172         static const size_t INVALID_DELETE_MOVE;
00173         static const size_t DELETE_MOVE;
00174         
00175         
00176         
00177         // All global properties
00178         static const size_t getMinLoopLength() ;
00179         
00180         static const Alphabet* getStructureAlphabet() ;
00181 
00182 
00183         
00193         RNAStructure_TB(    const std::string& rnaSeqStr, 
00194                         const std::string& rnaStructBracketDotStr, 
00195                         const AllowedBasePairs* const bPair);
00196             
00197         
00208         RNAStructure_TB(    Sequence* rnaSeq, 
00209                         const Structure* const rnaStructBracketDot, 
00210                         const AllowedBasePairs* const bPair,
00211                         const bool seqIsShared);
00212                  
00213                 
00214         RNAStructure_TB(const RNAStructure_TB& rnaStruct);
00215                 
00216         
00217         virtual ~RNAStructure_TB();
00218     
00219         
00220         RNAStructure_TB&    operator= (const RNAStructure_TB& rnaStruct2);
00221         bool                operator== (const RNAStructure_TB& rnaStruct2) const;
00222         bool                operator!= (const RNAStructure_TB& rnaStruct2) const;
00223 
00224         
00225         
00229         virtual void setStructure(const Structure& str);
00230         
00231         
00232         // String representation of the sequence
00233         std::string getSequenceString() const ;
00234         
00235         // String representation of the structure
00236         std::string getStructureString() const ;
00237 
00238         // Reference to string representation of the structure
00239         const std::string& getStructureStringRef() const ;
00240 
00241         
00242         //The following three methods calculate the return value only if not yet calculated (by initialization)
00243         // and only for once, unless structure is changed
00244         
00245         
00249         bool hasValidStructure() const ;
00250         
00251         
00255         bool hasValidBasePairs() const ;
00256         
00257         
00261         bool hasValidLoopSize() const ;
00262         
00263         
00264         // Single move operations, (insert, delete, shift)
00265 
00266         // Move validity check: i,j order does not matter, k is always the free base
00267         bool isValidInsertMove(const size_t i, const size_t j) const;
00268         bool isValidDeleteMove(const size_t i, const size_t j) const;
00269         
00275         int isValidSingleMove( const size_t i, const size_t j) const;
00276         
00277         bool isValidLeftShiftMove(const size_t i, const size_t j, const size_t k) const;
00278         bool isValidRightShiftMove(const size_t i, const size_t j, const size_t k) const;
00279         
00280     
00281         
00282         
00283         
00284         
00285         
00286         
00287         
00288         // Move Set 1: i,j order does not matter
00289         void insertBond(const size_t i, const size_t j);
00290         void deleteBond(const size_t i, const size_t j);
00291                 
00292         //  Move Set 2: i,j are the already existing bond, k is the open base
00293         void leftShift(const size_t i, const size_t j, const size_t k);
00294         void rightShift(const size_t i, const size_t j, const size_t k);
00295         
00296         void shiftUnordered(const size_t i, const size_t j);
00297         
00298         void shiftToBond(const size_t i, const size_t k);
00299         
00300         void shiftToBond(const size_t i, const size_t j, const size_t k);
00301         
00302         
00303         
00304         size_t moveType(size_t i, size_t j) const ;
00305                 
00306         void executeOrderedMove(size_t i, size_t j);
00307 
00308         bool executeOrderedMoveTry(size_t i, size_t j);
00309         
00310         
00323         bool getNextSingleMove( size_t& i, size_t& j ) const ;
00324         
00325         
00326         
00332         size_t getCorrespondingBase(size_t basePos) const;
00333     
00334         
00338         bool isAllowedBasePair(size_t pos1, size_t pos2) const;
00339         
00340         
00341 
00342         
00343 
00344     
00345     protected:
00346 
00347         
00349         bool initTree(const Structure& str);
00350         
00351         
00352         // auxiliary function used by the move validity checking functions
00353         bool areOnSameLevel(const size_t i, const size_t j) const ;
00354         
00355         
00356         // auxiliary function used to set the brackets in the string representation 
00357         // for the not necessarily ordered i,j pair 
00358         void setStringBrackets(const size_t i, const size_t j);
00359 
00360         
00361         
00362         
00363         
00364         
00365     private:
00366 
00367         std::string decodedStatus() const;
00368         
00369         
00370         
00371         
00372     public:
00373         bool isValidUnorderedShift(const size_t i, const size_t j) const;
00374             
00375             
00376         bool isValidShift(const size_t i, const size_t j) const;
00377         
00378         
00379         void decodeMoveIndex(size_t const index,  size_t&  i,  size_t&  j) const;
00380                         
00381         bool executeOrderedMoveTry(size_t const index);
00382         
00383         size_t getMoveIndexCount() const;
00384 
00385         
00386     };
00387 
00388 
00389 } // namespace biu
00390 
00391 #include "biu/RNAStructure_TB.icc"
00392 
00393 #endif /*RNASTRUCTURE_TB_HH_*/