libMems/AbstractGappedAlignment.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * $Id: AbstractGappedAlignment.h,v 1.12 2004/04/19 23:10:50 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 __AbstractGappedAlignment_h__
00010 #define __AbstractGappedAlignment_h__
00011 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 #include "libMems/AbstractMatch.h"
00017 #include "libGenome/gnFilter.h"
00018 
00019 namespace mems {
00020 
00021 template<class AbstractMatchImpl>
00022 class AbstractGappedAlignment : public AbstractMatchImpl
00023 {
00024 public:
00025         AbstractGappedAlignment();
00026         AbstractGappedAlignment( uint seq_count, gnSeqI align_length );
00027         
00032         virtual void SetAlignment( const std::vector< std::string >& seq_align ) = 0;
00033 
00034         // Inherited methods from AbstractMatch:
00035         gnSeqI Length( uint seqI = UINT_MAX ) const; 
00036         virtual void SetLength( gnSeqI len, uint seqI ) { length[ seqI ] = len; }
00037 
00038         gnSeqI AlignmentLength() const {return align_length;}
00039         void SetAlignmentLength(gnSeqI len){ align_length = len; }
00040 
00041 protected:
00042         // for use by derived classes in order to swap contents
00043         void swap( AbstractGappedAlignment* other );    
00044 private:
00045         std::vector< gnSeqI > length;
00046         gnSeqI align_length;
00047 };
00048 
00049 
00050 template<class AbstractMatchImpl>
00051 AbstractGappedAlignment<AbstractMatchImpl>::AbstractGappedAlignment() : AbstractMatchImpl()
00052 {
00053         align_length = 0;
00054 }
00055 
00056 template<class AbstractMatchImpl>
00057 AbstractGappedAlignment<AbstractMatchImpl>::AbstractGappedAlignment( uint seq_count, gnSeqI align_length ) : AbstractMatchImpl( seq_count )
00058 {
00059         length = std::vector< gnSeqI >( seq_count, 0 );
00060         this->align_length = align_length;
00061 }
00062 
00063 template<class AbstractMatchImpl>
00064 void AbstractGappedAlignment<AbstractMatchImpl>::swap( AbstractGappedAlignment* other )
00065 {
00066         std::swap( length, other->length );
00067         std::swap( align_length, other->align_length );
00068         AbstractMatchImpl::swap( other );
00069 }
00070 
00071 template<class AbstractMatchImpl>
00072 gnSeqI AbstractGappedAlignment<AbstractMatchImpl>::Length( uint seqI ) const 
00073 {
00074         if( seqI == UINT_MAX )
00075                 return align_length;
00076         return length[ seqI ]; 
00077 }
00078 
00079 //template<class AbstractGappedAlignmentImpl>
00080 void GetAlignment( const AbstractMatch& ga, const std::vector< genome::gnSequence* >& seq_table, std::vector<std::string>& alignment );
00081 
00082 //template<class AbstractGappedAlignmentImpl>
00083 inline
00084 void GetAlignment( const AbstractMatch& ga, const std::vector< genome::gnSequence* >& seq_table, std::vector<std::string>& alignment )
00085 {
00086         std::vector< bitset_t > aln_mat;
00087         ga.GetAlignment(aln_mat);
00088         alignment = std::vector<std::string>( aln_mat.size() );
00089         const genome::gnFilter* comp_filter = genome::gnFilter::DNAComplementFilter();
00090         for( std::size_t seqI = 0; seqI < alignment.size(); seqI++ )
00091         {
00092                 alignment[seqI] = std::string( aln_mat[0].size(), '-' );
00093                 if( ga.LeftEnd(seqI) == NO_MATCH )
00094                         continue;
00095                 std::string cur_seq;
00096                 seq_table[seqI]->ToString( cur_seq, ga.Length(seqI), ga.LeftEnd(seqI) );
00097                 if( ga.Orientation(seqI) == AbstractMatch::reverse )
00098                         comp_filter->ReverseFilter(cur_seq);
00099                 std::size_t cI = 0; 
00100                 for( std::size_t gI = 0; gI < alignment[seqI].size(); gI++ )
00101                         if( aln_mat[seqI][gI] )
00102                                 alignment[seqI][gI] = cur_seq[cI++];
00103         }
00104 }
00105 
00106 }
00107 
00108 #endif // __AbstractGappedAlignment_h__
00109 

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