libMems/UngappedLocalAlignment.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * $Id: UngappedLocalAlignment.h,v 1.10 2004/03/01 02:40:08 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 __UngappedLocalAlignment_h__
00010 #define __UngappedLocalAlignment_h__
00011 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 #include "libGenome/gnClone.h"
00017 #include "libGenome/gnException.h"
00018 #include "libMems/AbstractMatch.h"
00019 
00020 namespace mems {
00021 
00027 template< class AbstractMatchImpl >
00028 class UngappedLocalAlignment : public AbstractMatchImpl 
00029 {
00030 
00031 public:
00032         UngappedLocalAlignment();
00037         UngappedLocalAlignment( const uint seq_count );
00038 
00039         // use trivial copy constructor, destructor, and operator =
00040 
00041         UngappedLocalAlignment* Clone() const;
00042         UngappedLocalAlignment* Copy() const;
00043         virtual void Free();
00044 
00046         boolean operator==(const UngappedLocalAlignment& mhe) const;
00047 
00048         gnSeqI Length( uint seqI = (std::numeric_limits<uint>::max)() ) const
00049         {
00050                 if( seqI == (std::numeric_limits<uint>::max)() ) 
00051                         return m_length;
00052                 if( this->LeftEnd(seqI) == NO_MATCH )
00053                         return 0;
00054                 return m_length;
00055         }
00056         void SetLength(gnSeqI len, uint seqI = 0){m_length = len;}
00057         gnSeqI AlignmentLength() const{return m_length;}
00058         
00059         //warning:  none of the following do bounds checking.
00060         virtual void Move( int64 distance );
00061         virtual void CropStart(gnSeqI crop_amount);
00062         virtual void CropEnd(gnSeqI crop_amount);
00063         virtual void ExtendStart(gnSeqI extend_amount);
00064         virtual void ExtendEnd(gnSeqI extend_amount);
00065 
00066         virtual void CropLeft(gnSeqI crop_amount, uint seqI);
00067         virtual void CropRight(gnSeqI crop_amount, uint seqI);
00068 
00069         void GetAlignment( std::vector< bitset_t >& align_matrix ) const;
00070 
00071         void GetColumn( gnSeqI col, std::vector<gnSeqI>& pos, std::vector<bool>& column ) const;
00072 
00076         template<typename AMImpl> friend std::ostream& operator<<(std::ostream& os, const UngappedLocalAlignment<AMImpl>& ula); //write to source.
00077 
00078         bool IsGap( uint seqI, gnSeqI col ) const {
00079                 return (this->LeftEnd(seqI) != NO_MATCH && col < m_length);
00080         }
00081 
00082 protected:
00083 
00084         gnSeqI m_length;
00085 };
00086 
00087 
00088 template< class AbstractMatchImpl >
00089 UngappedLocalAlignment< AbstractMatchImpl >::UngappedLocalAlignment() : AbstractMatchImpl()
00090 {
00091 }
00092 
00093 
00094 template< class AbstractMatchImpl >
00095 UngappedLocalAlignment< AbstractMatchImpl >::UngappedLocalAlignment(uint seq_count)
00096  : AbstractMatchImpl( seq_count )
00097 {
00098 }
00099 
00100 
00101 template< class AbstractMatchImpl >
00102 UngappedLocalAlignment< AbstractMatchImpl >* 
00103 UngappedLocalAlignment< AbstractMatchImpl >::Clone() const
00104 {
00105         return new UngappedLocalAlignment(*this);
00106 }
00107 
00108 template< class AbstractMatchImpl >
00109 UngappedLocalAlignment<AbstractMatchImpl>* UngappedLocalAlignment<AbstractMatchImpl>::Copy() const
00110 {
00111         return m_allocateAndCopy( *this );
00112 }
00113 template< class AbstractMatchImpl >
00114 void UngappedLocalAlignment<AbstractMatchImpl>::Free()
00115 {
00116         m_free(this);
00117 }
00118 
00119 template< class AbstractMatchImpl >
00120 boolean UngappedLocalAlignment<AbstractMatchImpl>::operator==(const UngappedLocalAlignment& ula) const
00121 {
00122         if(m_length != ula.m_length)
00123                 return false;
00124         return AbstractMatchImpl::operator==(ula);
00125 }
00126 
00127 template< class AbstractMatchImpl >
00128 void UngappedLocalAlignment<AbstractMatchImpl>::Move( int64 distance )
00129 {
00130         for( uint32 i=0; i < AbstractMatchImpl::SeqCount(); i++ ){
00131                 int64 start = AbstractMatchImpl::Start(i);
00132                 if( start != NO_MATCH )
00133                         AbstractMatchImpl::SetStart(i, start + distance );
00134         }
00135 }
00136 
00137 template< class AbstractMatchImpl >
00138 void UngappedLocalAlignment<AbstractMatchImpl>::CropStart(gnSeqI crop_amount)
00139 {
00140         if( crop_amount > m_length )
00141                 Throw_gnEx( genome::SeqIndexOutOfBounds() );
00142         m_length -= crop_amount;
00143         AbstractMatchImpl::MoveStart(crop_amount);
00144 }
00145 
00146 template< class AbstractMatchImpl >
00147 void UngappedLocalAlignment<AbstractMatchImpl>::CropEnd(gnSeqI crop_amount){
00148         if( crop_amount > m_length )
00149                 Throw_gnEx( genome::SeqIndexOutOfBounds() );
00150         m_length -= crop_amount;
00151         AbstractMatchImpl::MoveEnd(crop_amount);
00152 }
00153 
00154 template< class AbstractMatchImpl >
00155 void UngappedLocalAlignment<AbstractMatchImpl>::ExtendStart(gnSeqI extend_amount){
00156         m_length += extend_amount;
00157         int64 amt = extend_amount;
00158         AbstractMatchImpl::MoveStart(-amt);
00159 }
00160 
00161 template< class AbstractMatchImpl >
00162 void UngappedLocalAlignment<AbstractMatchImpl>::ExtendEnd(gnSeqI extend_amount){
00163         m_length += extend_amount;
00164         int64 amt = extend_amount;
00165         AbstractMatchImpl::MoveEnd(-amt);
00166 }
00167 
00168 template< class AbstractMatchImpl >
00169 void UngappedLocalAlignment<AbstractMatchImpl>::CropLeft(gnSeqI crop_amount, uint seqI)
00170 {
00171         if(AbstractMatchImpl::Orientation(seqI) == AbstractMatch::forward)
00172                 CropStart(crop_amount);
00173         else
00174                 CropEnd(crop_amount);
00175 }
00176 
00177 template< class AbstractMatchImpl >
00178 void UngappedLocalAlignment<AbstractMatchImpl>::CropRight(gnSeqI crop_amount, uint seqI)
00179 {
00180         if(AbstractMatchImpl::Orientation(seqI) == AbstractMatch::forward)
00181                 CropEnd(crop_amount);
00182         else
00183                 CropStart(crop_amount);
00184 }
00185 
00186 template< class AbstractMatchImpl >
00187 void UngappedLocalAlignment< AbstractMatchImpl >::GetAlignment( std::vector< bitset_t >& align_matrix ) const
00188 {
00189         align_matrix = std::vector< bitset_t >(this->SeqCount(), bitset_t( this->AlignmentLength(), false ) );
00190         for( uint seqI = 0; seqI < this->SeqCount(); seqI++ )
00191         {
00192                 if( this->LeftEnd(seqI) != NO_MATCH )
00193                         align_matrix[seqI].flip();
00194         }
00195 }
00196 
00197 template< typename AbstractMatchImpl >
00198 std::ostream& operator<<(std::ostream& os, const UngappedLocalAlignment< AbstractMatchImpl >& ula);
00199 
00200 template< typename AbstractMatchImpl >
00201 std::ostream& operator<<(std::ostream& os, const UngappedLocalAlignment< AbstractMatchImpl >& ula){ //write to stream.
00202         os << ula.m_length;
00203         for(uint i=0; i < ula.SeqCount(); i++)
00204                 os << '\t' << ula.Start(i);
00205         return os;
00206 }
00207 
00208 
00209 template< class AbstractMatchImpl >
00210 void UngappedLocalAlignment< AbstractMatchImpl >::GetColumn( gnSeqI col, std::vector<gnSeqI>& pos, std::vector<bool>& column ) const
00211 {
00212         pos = std::vector<gnSeqI>(this->SeqCount(), NO_MATCH);
00213         column = std::vector<bool>(this->SeqCount(), true);
00214         for( uint seqI = 0; seqI < this->SeqCount(); seqI++ )
00215         {
00216                 if( this->Orientation(seqI) == AbstractMatch::forward )
00217                         pos[seqI] = this->LeftEnd(seqI) + col;
00218                 else if( this->Orientation(seqI) == AbstractMatch::reverse )
00219                         pos[seqI] = this->RightEnd(seqI) - col;
00220                 else
00221                         column[seqI] = false;
00222         }
00223 }
00224 
00225 }
00226 
00227 #endif // _UngappedLocalAlignment_h_

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