00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __MatchProjectionAdapter_h__
00010 #define __MatchProjectionAdapter_h__
00011
00012 #include "libMems/AbstractMatch.h"
00013 #include <vector>
00014
00015 #ifdef HAVE_CONFIG_H
00016 #include "config.h"
00017 #endif
00018
00019 namespace mems {
00020
00026 class MatchProjectionAdapter : public mems::AbstractMatch
00027 {
00028 public:
00029 MatchProjectionAdapter() : m(NULL){};
00030 MatchProjectionAdapter( mems::AbstractMatch* match, const std::vector< size_t >& projection ) :
00031 seq(projection)
00032 {
00033 m = match->Copy();
00034 }
00035
00036 MatchProjectionAdapter( const MatchProjectionAdapter& mpa ) :
00037 seq( mpa.seq )
00038 {
00039 if( mpa.m != NULL )
00040 m = mpa.m->Copy();
00041 else
00042 m = NULL;
00043 }
00044
00045 ~MatchProjectionAdapter()
00046 {
00047 if( m != NULL )
00048 m->Free();
00049 }
00050
00051 MatchProjectionAdapter* Clone() const { return new MatchProjectionAdapter( *this ); }
00052
00053 inline
00054 MatchProjectionAdapter* Copy() const
00055 {
00056 return m_allocateAndCopy( *this );
00057 }
00058
00059 void Free()
00060 {
00061 m_free(this);
00062 }
00063
00064 MatchProjectionAdapter& operator=( const MatchProjectionAdapter& mpa )
00065 {
00066 if( m != NULL )
00067 m->Free();
00068 m = mpa.m->Copy();
00069 seq = mpa.seq;
00070 return *this;
00071 }
00072
00073
00074
00075
00076 gnSeqI Length( uint seqI ) const { return m->Length(seq[seqI]); }
00077 void SetLength( gnSeqI len, uint seqI ) { m->SetLength(len, seq[seqI]); }
00078 int64 Start(uint startI) const { return m->Start(seq[startI]); }
00079 void SetStart(uint seqI, int64 start) { m->SetStart(seq[seqI],start); }
00080 gnSeqI LeftEnd(uint seqI) const { return m->LeftEnd(seq[seqI]); }
00081 orientation Orientation(uint seqI) const { return m->Orientation(seq[seqI]); }
00082 void SetLeftEnd(uint seqI, gnSeqI start) { m->SetLeftEnd(seq[seqI],start); }
00083 void SetOrientation(uint seqI, orientation o) { m->SetOrientation(seq[seqI],o); }
00084 void MoveStart(int64 move_amount) { m->MoveStart(move_amount); }
00085 void MoveEnd(int64 move_amount) { m->MoveEnd(move_amount); }
00086 uint Multiplicity() const
00087 {
00088 size_t mult = 0;
00089 for( size_t projI = 0; projI < seq.size(); projI++ )
00090 if( m->LeftEnd(projI) != mems::NO_MATCH )
00091 ++mult;
00092 return mult;
00093 }
00094 uint SeqCount() const { return seq.size(); }
00095 uint FirstStart() const { return 0; }
00096 gnSeqI AlignmentLength() const { return m->AlignmentLength(); }
00097 void Invert() { m->Invert(); }
00098 void CropStart(gnSeqI crop_amount) { m->CropStart(crop_amount); }
00099 void CropEnd(gnSeqI crop_amount) { m->CropEnd(crop_amount); }
00100 void CropLeft(gnSeqI crop_amount, uint seqI) { m->CropLeft(crop_amount, seq[seqI]); }
00101 void CropRight(gnSeqI crop_amount, uint seqI) { m->CropRight(crop_amount, seq[seqI]); }
00102 void GetAlignment( std::vector< mems::bitset_t >& align_matrix ) const
00103 {
00104 std::vector< mems::bitset_t > aln_mat;
00105 m->GetAlignment(aln_mat);
00106 align_matrix.clear();
00107 for( size_t seqI = 0; seqI < seq.size(); ++seqI )
00108 align_matrix.push_back(aln_mat[seq[seqI]]);
00109 }
00110 void GetColumn( gnSeqI col, std::vector<gnSeqI>& pos, std::vector<bool>& column ) const
00111 {
00112 std::vector<gnSeqI> m_pos;
00113 std::vector<bool> m_column;
00114 m->GetColumn(col,m_pos,m_column);
00115 pos.clear();
00116 for( size_t seqI = 0; seqI < seq.size(); ++seqI )
00117 {
00118 pos.push_back(m_pos[seq[seqI]]);
00119 column.push_back(m_column[seq[seqI]]);
00120 }
00121 }
00122 bool IsGap( uint seqI, gnSeqI col ) const { return m->IsGap( seq[seqI],col ); }
00123 uint UsedSeq( uint seqI ) const
00124 {
00125 uint c = 0;
00126 for( uint i = 0; i < seq.size(); i++ )
00127 {
00128 if(m->Start(seq[i]) != 0)
00129 c++;
00130 if(c>seqI)
00131 return i;
00132 }
00133 return (std::numeric_limits<uint>::max)();
00134 };
00135
00136 mems::AbstractMatch* m;
00137 std::vector< size_t > seq;
00138 };
00139
00140 }
00141
00142 #endif // __MatchProjectionAdapter_h__