| 1 | #ifndef MATCH_H |
| 2 | #define MATCH_H |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <unistd.h> |
| 7 | |
| 8 | #include "atac.H" |
| 9 | #include "bio++.H" |
| 10 | #include "seqCache.H" |
| 11 | |
| 12 | class match_s { |
| 13 | public: |
| 14 | char _matchId[32]; |
| 15 | |
| 16 | seqInCore *_seq1; |
| 17 | FastAAccessor *_acc1; |
| 18 | uint32 _iid1; |
| 19 | uint32 _pos1; |
| 20 | uint32 _len1; |
| 21 | uint32 _ori1; |
| 22 | |
| 23 | seqInCore *_seq2; |
| 24 | FastAAccessor *_acc2; |
| 25 | uint32 _iid2; |
| 26 | uint32 _pos2; |
| 27 | uint32 _len2; |
| 28 | uint32 _ori2; |
| 29 | |
| 30 | bool _isDeleted; |
| 31 | |
| 32 | // Our diagonal never, ever changes |
| 33 | uint32 _diagonal; |
| 34 | |
| 35 | public: |
| 36 | match_s(char *matchId, |
| 37 | seqInCore *s1, uint32 i1, uint32 p1, uint32 l1, uint32 o1, |
| 38 | seqInCore *s2, uint32 i2, uint32 p2, uint32 l2, uint32 o2) { |
| 39 | |
| 40 | strncpy(_matchId, matchId, 32); |
| 41 | |
| 42 | _seq1 = s1; |
| 43 | _acc1 = new FastAAccessor(_seq1, false); |
| 44 | _iid1 = i1; |
| 45 | _pos1 = p1; |
| 46 | _len1 = l1; |
| 47 | _ori1 = o1; |
| 48 | |
| 49 | _seq2 = s2; |
| 50 | _acc2 = new FastAAccessor(_seq2, (o1 != o2)); |
| 51 | _iid2 = i2; |
| 52 | _pos2 = p2; |
| 53 | _len2 = l2; |
| 54 | _ori2 = o2; |
| 55 | |
| 56 | _isDeleted = false; |
| 57 | |
| 58 | _acc1->setRange(_pos1, _len1); |
| 59 | _acc2->setRange(_pos2, _len2); |
| 60 | |
| 61 | _acc1->setPosition(_pos1); |
| 62 | _acc2->setPosition(_pos2); |
| 63 | |
| 64 | // the diagonal is.... |
| 65 | if (_ori1 == _ori2) |
| 66 | _diagonal = _seq1->sequenceLength() - _pos1 + _pos2; |
| 67 | else |
| 68 | _diagonal = _seq1->sequenceLength() - _pos1 + _seq2->sequenceLength() - (_pos2 + _len2); |
| 69 | }; |
| 70 | |
| 71 | ~match_s() { |
| 72 | delete _acc1; |
| 73 | delete _acc2; |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | // Compare by diagonal, then by position in the first sequence. |
| 78 | // |
| 79 | bool operator<(const match_s& r) const { |
| 80 | if (_diagonal < r._diagonal) return(true); |
| 81 | if (_diagonal == r._diagonal) return(_pos1 < r._pos1); |
| 82 | return(false); |
| 83 | }; |
| 84 | |
| 85 | void dump(FILE *out, const char *descr, bool showSeq=false); |
| 86 | |
| 87 | |
| 88 | // For compatibility |
| 89 | |
| 90 | void extendLeft(int32 num) { |
| 91 | _acc1->extendLeft(num); |
| 92 | _acc2->extendLeft(num); |
| 93 | }; |
| 94 | |
| 95 | void extendRight(int32 num) { |
| 96 | _acc1->extendRight(num); |
| 97 | _acc2->extendRight(num); |
| 98 | }; |
| 99 | |
| 100 | bool isDeleted(void) { return(_isDeleted); }; |
| 101 | void setDeleted(void) { _isDeleted = true; }; |
| 102 | |
| 103 | |
| 104 | // Since we're on the same diagonal, and ungapped, the choice of |
| 105 | // testing sequence 1 or 2 is arbirary. |
| 106 | // |
| 107 | bool canMergeWith(match_s *m) { |
| 108 | return((m != 0L) && |
| 109 | (_diagonal == m->_diagonal) && |
| 110 | (_acc1->getRangeEnd() >= m->_acc1->getRangeBegin())); |
| 111 | }; |
| 112 | |
| 113 | // Extend us to end where m ends |
| 114 | // |
| 115 | void consume(match_s *m) { |
| 116 | if (m->_acc1->getRangeEnd() > _acc1->getRangeEnd()) |
| 117 | extendRight(m->_acc1->getRangeEnd() - _acc1->getRangeEnd()); |
| 118 | }; |
| 119 | |
| 120 | uint32 len(void) { return(_acc1->getRangeEnd() - _acc1->getRangeBegin()); }; |
| 121 | uint32 pos1(void) { return(_acc1->getRangeBegin()); }; |
| 122 | uint32 pos2(void) { return(_acc2->getRangeBegin()); }; |
| 123 | seqInCore *seq1(void) { return(_seq1); }; |
| 124 | seqInCore *seq2(void) { return(_seq2); }; |
| 125 | }; |
| 126 | |
| 127 | #endif // MATCH_H |