00001 #ifndef __PairwiseMatchAdapter_h__
00002 #define __PairwiseMatchAdapter_h__
00003
00004 #include "libMems/AbstractMatch.h"
00005 #include "libMems/ProgressiveAligner.h"
00006 #include <vector>
00007
00008 namespace mems {
00009
00015 class PairwiseMatchAdapter : public mems::AbstractMatch
00016 {
00017 public:
00018 PairwiseMatchAdapter() : m(NULL) {}
00019 PairwiseMatchAdapter( AbstractMatch* match, uint seq1, uint seq2 ) :
00020 m(match)
00021 {
00022 seq[0] = seq1;
00023 seq[1] = seq2;
00024 inverted = false;
00025 }
00026
00027 PairwiseMatchAdapter* Clone() const { return new PairwiseMatchAdapter( *this ); }
00028
00029 PairwiseMatchAdapter* Copy() const
00030 {
00031 return m_allocateAndCopy( *this );
00032 }
00033
00034 void Free()
00035 {
00036 m_free(this);
00037 }
00038
00039
00040
00041
00042 gnSeqI Length( uint seqI ) const { return m->Length(seq[seqI]); }
00043 void SetLength( gnSeqI len, uint seqI ) { m->SetLength(len, seq[seqI]); }
00044 int64 Start(uint startI) const {
00045 if(inverted)
00046 return -m->Start(seq[startI]);
00047 return m->Start(seq[startI]);
00048 }
00049 void SetStart(uint seqI, int64 start) { m->SetStart(seq[seqI],start); }
00050 gnSeqI LeftEnd(uint seqI) const { return m->LeftEnd(seq[seqI]); }
00051 orientation Orientation(uint seqI) const {
00052 orientation o = m->Orientation(seq[seqI]);
00053 if(inverted && o != AbstractMatch::undefined )
00054 o = o == AbstractMatch::forward ? AbstractMatch::reverse : AbstractMatch::forward;
00055 return o;
00056 }
00057 void SetLeftEnd(uint seqI, gnSeqI start) { m->SetLeftEnd(seq[seqI],start); }
00058 void SetOrientation(uint seqI, orientation o) { m->SetOrientation(seq[seqI],o); }
00059 void MoveStart(int64 move_amount) { m->MoveStart(move_amount); }
00060 void MoveEnd(int64 move_amount) { m->MoveEnd(move_amount); }
00061 uint Multiplicity() const { return 2; }
00062 uint SeqCount() const { return 2; }
00063 uint FirstStart() const { return 0; }
00064 gnSeqI AlignmentLength() const { return m->AlignmentLength(); }
00065 void Invert() { inverted = !inverted; }
00066 void CropStart(gnSeqI crop_amount) { m->CropStart(crop_amount); }
00067 void CropEnd(gnSeqI crop_amount) { m->CropEnd(crop_amount); }
00068 void CropLeft(gnSeqI crop_amount, uint seqI) { m->CropLeft(crop_amount, seq[seqI]); }
00069 void CropRight(gnSeqI crop_amount, uint seqI) { m->CropRight(crop_amount, seq[seqI]); }
00070 void GetAlignment( std::vector< mems::bitset_t >& align_matrix ) const
00071 {
00072 if( inverted )
00073 m->Invert();
00074 std::vector< mems::bitset_t > aln_mat;
00075 m->GetAlignment(aln_mat);
00076 align_matrix.clear();
00077 align_matrix.push_back(aln_mat[seq[0]]);
00078 align_matrix.push_back(aln_mat[seq[1]]);
00079 if( inverted )
00080 m->Invert();
00081 }
00082 void GetColumn( gnSeqI col, std::vector<gnSeqI>& pos, std::vector<bool>& column ) const
00083 {
00084 if( inverted )
00085 m->Invert();
00086 std::vector<gnSeqI> m_pos;
00087 std::vector<bool> m_column;
00088 m->GetColumn(col,m_pos,m_column);
00089 pos.clear();
00090 pos.push_back(m_pos[seq[0]]);
00091 pos.push_back(m_pos[seq[1]]);
00092 column.push_back(m_column[seq[0]]);
00093 column.push_back(m_column[seq[1]]);
00094 if( inverted )
00095 m->Invert();
00096 }
00097
00098 bool IsGap( uint seqI, gnSeqI col ) const { return m->IsGap( seq[seqI],col ); }
00099 uint UsedSeq( uint seqI ) const
00100 {
00101 if(m->Start(seq[0]) != NO_MATCH)
00102 return 0;
00103 if(m->Start(seq[1]) != NO_MATCH)
00104 return 1;
00105 return (std::numeric_limits<uint>::max)();
00106 };
00107
00108 AbstractMatch* m;
00109 TrackingMatch* tm;
00110 uint seq[2];
00111 bool inverted;
00112 };
00113
00114 }
00115
00116 #endif // __PairwiseMatchAdapter_h__
00117