| 1 | // This file is part of A2Amapper. |
| 2 | // Copyright (c) 2005 J. Craig Venter Institute |
| 3 | // Author: Brian Walenz |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received (LICENSE.txt) a copy of the GNU General Public |
| 16 | // License along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | #ifndef ATAC_MATCHORDER_H |
| 20 | #define ATAC_MATCHORDER_H |
| 21 | |
| 22 | #include <string> |
| 23 | #include <map> |
| 24 | using namespace std; |
| 25 | |
| 26 | #include "bio++.H" |
| 27 | |
| 28 | |
| 29 | class atacMatchOrder { |
| 30 | private: |
| 31 | void initialize(atacMatchList *ML) { |
| 32 | _matchesLen = ML->numberOfMatches(); |
| 33 | _matchesMax = ML->numberOfMatches(); |
| 34 | _matches = new atacMatch * [_matchesLen]; |
| 35 | _matchIIDtoIdx = new uint32 [_matchesLen]; |
| 36 | for (uint32 i=0; i<_matchesLen; i++) { |
| 37 | _matches[i] = ML->getMatch(i); |
| 38 | _matchIIDtoIdx[i] = ~uint32ZERO; |
| 39 | } |
| 40 | }; |
| 41 | public: |
| 42 | atacMatchOrder(atacMatchList *ML) { |
| 43 | initialize(ML); |
| 44 | }; |
| 45 | atacMatchOrder(atacMatchList &ML) { |
| 46 | initialize(&ML); |
| 47 | }; |
| 48 | ~atacMatchOrder() { |
| 49 | delete [] _matches; |
| 50 | }; |
| 51 | |
| 52 | uint32 numMatches(void) { return(_matchesLen); }; |
| 53 | uint32 numberOfMatches(void) { return(_matchesLen); }; |
| 54 | |
| 55 | // Return match i in our list. Common usage would be |
| 56 | // getMatch(index(iid) + 1) // return the match after the one we have |
| 57 | // getMatch(index(iid) - 1) |
| 58 | // |
| 59 | atacMatch *getMatch(uint32 i) { |
| 60 | return(_matches[i]); |
| 61 | }; |
| 62 | atacMatch *operator[](uint32 i) { |
| 63 | return(_matches[i]); |
| 64 | }; |
| 65 | |
| 66 | // Return the index, in our sorted list, of the matchiid supplied. |
| 67 | // |
| 68 | uint32 index(uint32 matchiid) { |
| 69 | return(_matchIIDtoIdx[matchiid]); |
| 70 | }; |
| 71 | |
| 72 | // Merge the r match into the l match. The l match gets the result. |
| 73 | void mergeMatches(atacMatch *l, atacMatch *r, uint32 mergeuid); |
| 74 | |
| 75 | void sortA(uint32 first=0, uint32 len=0); |
| 76 | void sortB(uint32 first=0, uint32 len=0); |
| 77 | void sortDiagonal(uint32 first=0, uint32 len=0); |
| 78 | void sortMatchUID(uint32 first=0, uint32 len=0); |
| 79 | void sortParentUID(uint32 first=0, uint32 len=0); |
| 80 | |
| 81 | private: |
| 82 | uint32 _matchesLen; |
| 83 | uint32 _matchesMax; |
| 84 | atacMatch **_matches; |
| 85 | |
| 86 | atacMatchList *_ML; |
| 87 | |
| 88 | void updateIndex(void) { |
| 89 | for (uint32 i=0; i<_matchesLen; i++) |
| 90 | _matchIIDtoIdx[i] = ~uint32ZERO; |
| 91 | for (uint32 i=0; i<_matchesLen; i++) |
| 92 | _matchIIDtoIdx[_matches[i]->matchiid] = i; |
| 93 | }; |
| 94 | |
| 95 | uint32 *_matchIIDtoIdx; |
| 96 | }; |
| 97 | |
| 98 | |
| 99 | #endif // ATAC_MATCHORDER_H |