libMems/DenseAbstractMatch.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * $Id: DenseAbstractMatch.h,v 1.8 2004/02/27 23:08:55 darling Exp $
00003  * This file is copyright 2002-2007 Aaron Darling and authors listed in the AUTHORS file.
00004  * This file is licensed under the GPL.
00005  * Please see the file called COPYING for licensing details.
00006  * **************
00007  ******************************************************************************/
00008 
00009 #ifndef __DenseAbstractMatch_h__
00010 #define __DenseAbstractMatch_h__
00011 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 #include "libGenome/gnClone.h"
00017 #include "libMems/AbstractMatch.h"
00018 #include <limits>
00019 
00020 namespace mems {
00021 
00028 template< unsigned int MAX_SEQS >
00029 class DenseAbstractMatch : public AbstractMatch 
00030 {
00031 public:
00032         DenseAbstractMatch();
00037         DenseAbstractMatch(const uint seq_count );
00038         // use the compiler generated copy constructor, assignment operator, and destructor
00039 
00040         virtual AbstractMatch* Clone() const = 0;
00041         
00042         // see AbstractMatch base class documentation for these functions
00043 
00044         int64 Start(uint seqI) const{
00045                 int64 s = leftend[seqI];
00046                 return orient[seqI]? -s : s;
00047         }
00048         void SetStart(uint seqI, int64 startI)
00049         {
00050                 SetLeftEnd( seqI, genome::absolut(startI) );
00051                 orient[seqI] = startI < 0;
00052         }
00053         uint Multiplicity() const{return m_multiplicity;}
00054         uint SeqCount() const{return m_seq_count;}
00055         virtual uint FirstStart() const;
00056         virtual void Invert();
00057 
00058         virtual gnSeqI LeftEnd(uint seqI) const{ return leftend[seqI]; }
00059         virtual orientation Orientation(uint seqI) const;
00060         virtual void SetLeftEnd(uint seqI, gnSeqI position)
00061         { 
00062                 if( position == NO_MATCH && leftend[seqI] != NO_MATCH )
00063                         --m_multiplicity;
00064                 else if( position != NO_MATCH && leftend[seqI] == NO_MATCH )
00065                         ++m_multiplicity;
00066                 leftend[seqI]=position; 
00067         }
00068         virtual void SetOrientation(uint seqI, orientation o){ orient[seqI]= (o == reverse); }
00069         
00070         virtual boolean operator==( const DenseAbstractMatch& dam ) const;
00071         
00072         void MoveStart(int64 move_amount);
00073 
00074         void MoveEnd(int64 move_amount);
00075 
00076         virtual uint UsedSeq( uint seqI ) const {
00077                 return seqI;
00078         }
00079 
00080 protected:
00081 
00082         uint m_seq_count;
00083         gnSeqI leftend[ MAX_SEQS ];
00084         bool orient[ MAX_SEQS ];
00085         uint m_multiplicity;
00086 };
00087 
00088 template< unsigned int MAX_SEQS >
00089 DenseAbstractMatch<MAX_SEQS>::DenseAbstractMatch() :
00090 m_seq_count(0),
00091 m_multiplicity(0)
00092 {
00093         memset( leftend, 0, MAX_SEQS * sizeof(gnSeqI) );
00094         memset( orient, 0, sizeof( orient ) );
00095 }
00096 
00097 template< unsigned int MAX_SEQS >
00098 DenseAbstractMatch<MAX_SEQS>::DenseAbstractMatch(const uint seq_count ) :
00099 m_seq_count(seq_count),
00100 m_multiplicity(0)
00101 {
00102         memset( leftend, 0, MAX_SEQS * sizeof(gnSeqI) );
00103         memset( orient, 0, sizeof( orient ) );
00104 }
00105 
00106 template< unsigned int MAX_SEQS >
00107 boolean DenseAbstractMatch<MAX_SEQS>::operator==( const DenseAbstractMatch<MAX_SEQS>& dam ) const
00108 {
00109         for( uint seqI = 0; seqI < m_seq_count; ++seqI )
00110         {
00111                 if( leftend[seqI] != dam.leftend[seqI] ||
00112                         (leftend[seqI] != 0 && orient[seqI] != orient[seqI]))
00113                         return false;
00114         }
00115         return true;
00116 }
00117 
00118 template< unsigned int MAX_SEQS >
00119 AbstractMatch::orientation DenseAbstractMatch<MAX_SEQS>::Orientation(uint seqI) const
00120 { 
00121         if( leftend[seqI] != NO_MATCH && seqI < m_seq_count )
00122                 return orient[seqI] ? reverse : forward; 
00123         return undefined;
00124 }
00125 
00126 template< unsigned int MAX_SEQS >
00127 void DenseAbstractMatch<MAX_SEQS>::Invert()
00128 {
00129         for( uint seqI = 0; seqI < MAX_SEQS; ++seqI )
00130                 orient[seqI] = !orient[seqI];
00131 }
00132 
00133 template< unsigned int MAX_SEQS >
00134 uint DenseAbstractMatch<MAX_SEQS>::FirstStart() const
00135 {
00136         for( uint m_firstStart = 0; m_firstStart < SeqCount(); ++m_firstStart )
00137                 if( leftend[m_firstStart] != NO_MATCH )
00138                         return m_firstStart;
00139         return (std::numeric_limits<uint>::max)();
00140 }
00141 
00142 template< unsigned int MAX_SEQS >
00143 void DenseAbstractMatch<MAX_SEQS>::MoveStart(int64 move_amount)
00144 {
00145         for( uint i=0; i < m_seq_count; ++i )
00146                 if( leftend[i] != NO_MATCH && orient[i] == false )
00147                         leftend[i] += move_amount;
00148 }
00149 
00150 template< unsigned int MAX_SEQS >
00151 void DenseAbstractMatch<MAX_SEQS>::MoveEnd(int64 move_amount)
00152 {
00153         for( uint i=0; i < m_seq_count; ++i )
00154                 if( leftend[i] != NO_MATCH && orient[i] )
00155                         leftend[i] += move_amount;
00156 }
00157 
00158 
00159 typedef DenseAbstractMatch<2> DenseAbstractMatch2;
00160 typedef DenseAbstractMatch<4> DenseAbstractMatch4;
00161 typedef DenseAbstractMatch<8> DenseAbstractMatch8;
00162 typedef DenseAbstractMatch<16> DenseAbstractMatch16;
00163 typedef DenseAbstractMatch<32> DenseAbstractMatch32;
00164 typedef DenseAbstractMatch<64> DenseAbstractMatch64;
00165 typedef DenseAbstractMatch<128> DenseAbstractMatch128;
00166 
00167 }
00168 
00169 #endif // _DenseAbstractMatch_h_

Generated on Fri Mar 14 06:01:02 2008 for libMems by doxygen 1.3.6