| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/alignOverlap/overlap-spanTree.H`/ |
| 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 OVERLAP_SPANTREE_H |
| 20 | #define OVERLAP_SPANTREE_Hcxx . . $ `atac-driver/alignOverlap/overlap-spanTree.H:20:9`! |
| 21 | |
| 22 | #include "overlap.H"cxx . . $ `<file>/atac-driver/alignOverlap/overlap.H`/ |
| 23 | |
| 24 | class spanTreecxx . . $ spanTree# { |
| 25 | public: |
| 26 | spanTreecxx . . $ spanTree#spanTree(49f6e7a06ebc5aa8).() { |
| 27 | _treecxx . . $ spanTree#_tree. = dict_create(DICTCOUNT_T_MAXcxx . . $ `libutil/kazlib/dict.h:36:9`!, spanComparecxx . . $ spanCompare(9148c8c3ff42c9d8).); |
| 28 | }; |
| 29 | ~cxx . . $ spanTree#`~spanTree`(ced63f7c635d850d).spanTreecxx . . $ spanTree#() { |
| 30 | dict_free_nodes(_treecxx . . $ spanTree#_tree.); |
| 31 | dict_free(_treecxx . . $ spanTree#_tree.); |
| 32 | }; |
| 33 | |
| 34 | void addNewSpancxx . . $ spanTree#addNewSpan(b4d55b1286ff73e8).(uint32cxx . . $ uint32# iid, uint32cxx . . $ uint32# len) { |
| 35 | span_tcxx . . $ span_t# *span = new span_tcxx . . $ span_t#(iid, 0, len); |
| 36 | dict_alloc_insert(_treecxx . . $ spanTree#_tree., span, 0L); |
| 37 | }; |
| 38 | |
| 39 | uint32cxx . . $ uint32# sizecxx . . $ spanTree#size(db52760e79bf9054).(void) { |
| 40 | return((uint32cxx . . $ uint32#)dict_countcxx . . $ `libutil/kazlib/dict.h:131:9`!(_tree)); |
| 41 | }; |
| 42 | |
| 43 | void addMatchcxx . . $ spanTree#addMatch(c37c57dc8a530d2f).(atacMatchcxx . . $ atacMatch# *match, uint32cxx . . $ uint32# side, uint32cxx . . $ uint32# color) { |
| 44 | |
| 45 | // Query the tree for the first match before this position. |
| 46 | // We're guaranteed to find one before, since the tree was |
| 47 | // initialized with a span for the whole sequence. |
| 48 | // |
| 49 | span_tcxx . . $ span_t# *span = 0L; |
| 50 | uint32cxx . . $ uint32# beg = 0; |
| 51 | uint32cxx . . $ uint32# end = 0; |
| 52 | |
| 53 | if (side == 0) { |
| 54 | span = new span_tcxx . . $ span_t#(match->iid1cxx . . $ atacMatch#iid1., match->pos1cxx . . $ atacMatch#pos1., match->pos1cxx . . $ atacMatch#pos1. + match->len1cxx . . $ atacMatch#len1.); |
| 55 | beg = match->pos1cxx . . $ atacMatch#pos1.; |
| 56 | end = match->pos1cxx . . $ atacMatch#pos1. + match->len1cxx . . $ atacMatch#len1.; |
| 57 | } else { |
| 58 | span = new span_tcxx . . $ span_t#(match->iid2cxx . . $ atacMatch#iid2., match->pos2cxx . . $ atacMatch#pos2., match->pos2cxx . . $ atacMatch#pos2. + match->len2cxx . . $ atacMatch#len2.); |
| 59 | beg = match->pos2cxx . . $ atacMatch#pos2.; |
| 60 | end = match->pos2cxx . . $ atacMatch#pos2. + match->len2cxx . . $ atacMatch#len2.; |
| 61 | } |
| 62 | |
| 63 | dnode_t *node = dict_upper_bound(_treecxx . . $ spanTree#_tree., span); |
| 64 | delete span; |
| 65 | span = (span_tcxx . . $ span_t# *)dnode_getkeycxx . . $ `libutil/kazlib/dict.h:134:9`!(node); |
| 66 | |
| 67 | // We need to split the span pointed to by node, iterate through |
| 68 | // all the spans, and split the last one. |
| 69 | |
| 70 | if (span->_begcxx . . $ span_t#_beg. != beg) { |
| 71 | span_tcxx . . $ span_t# *l = 0L; |
| 72 | span_tcxx . . $ span_t# *r = 0L; |
| 73 | span->splitcxx . . $ span_t#split(5bc8c286f40965a5).(beg, l, r); |
| 74 | |
| 75 | // Kill this node, insert the new ones |
| 76 | |
| 77 | dict_delete(_treecxx . . $ spanTree#_tree., node); |
| 78 | dnode_destroy(node); |
| 79 | dict_alloc_insert(_treecxx . . $ spanTree#_tree., l, 0L); |
| 80 | dict_alloc_insert(_treecxx . . $ spanTree#_tree., r, 0L); |
| 81 | |
| 82 | delete span; |
| 83 | span = r; |
| 84 | |
| 85 | // Argh! Now find the node we just inserted... |
| 86 | |
| 87 | node = dict_lookup(_treecxx . . $ spanTree#_tree., r); |
| 88 | } |
| 89 | |
| 90 | // Until we hit the last span, add the match to the span |
| 91 | |
| 92 | while (span->_endcxx . . $ span_t#_end. < end) { |
| 93 | span->addMatchcxx . . $ span_t#addMatch(b4d55b1286ff73e8).(match->matchiidcxx . . $ atacMatch#matchiid., color); |
| 94 | node = dict_next(_treecxx . . $ spanTree#_tree., node); |
| 95 | span = (span_tcxx . . $ span_t# *)dnode_getkeycxx . . $ `libutil/kazlib/dict.h:134:9`!(node); |
| 96 | } |
| 97 | |
| 98 | // We're at the last span, so split it like the beginning |
| 99 | |
| 100 | if (span->_endcxx . . $ span_t#_end. != end) { |
| 101 | span_tcxx . . $ span_t# *l = 0L; |
| 102 | span_tcxx . . $ span_t# *r = 0L; |
| 103 | span->splitcxx . . $ span_t#split(5bc8c286f40965a5).(end, l, r); |
| 104 | |
| 105 | // Kill this node, insert the new ones |
| 106 | |
| 107 | dict_delete(_treecxx . . $ spanTree#_tree., node); |
| 108 | dnode_destroy(node); |
| 109 | dict_alloc_insert(_treecxx . . $ spanTree#_tree., l, 0L); |
| 110 | dict_alloc_insert(_treecxx . . $ spanTree#_tree., r, 0L); |
| 111 | |
| 112 | delete span; |
| 113 | span = l; |
| 114 | } |
| 115 | |
| 116 | // FInally, add the match to the last span |
| 117 | |
| 118 | span->addMatchcxx . . $ span_t#addMatch(b4d55b1286ff73e8).(match->matchiidcxx . . $ atacMatch#matchiid., color); |
| 119 | }; |
| 120 | |
| 121 | dict_t *_treecxx . . $ spanTree#_tree.; |
| 122 | dict_load_t _loadcxx . . $ spanTree#_load.; |
| 123 | }; |
| 124 | |
| 125 | #endif // OVERLAP_SPANTREE_H |