Debian Codegraph @

seagen/hitMatrix.H

raw symbols SCIP
1 #cxx . . $ `<file>/seagen/hitMatrix.H`/ifndef HITMATRIX_H
2 #define HITMATRIX_Hcxx . . $ `seagen/hitMatrix.H:2:9`!
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <new>
7
8 #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/
9 #include "positionDB.H"cxx . . $ `<file>/libkmer/positionDB.H`/
10 #include "encodedQuery.H"cxx . . $ `<file>/seagen/encodedQuery.H`/
11
12 // Define this to cut the space required for storing hits by 1/3 --
13 // from 12 byyes to 8 bytes -- at a slight computational expense --
14 // negligible on real hardware, I hope.
15 //
16 // The original definition of diagonalID was
17 // qsLen - qsPos - 1 + dsPos
18 // but qsLen is fixed for everyone, so we could reduce it to
19 // dsPos - qsPos
20 // but that's not unsigned.
21 //
22 // Results: on a human mapping, using chromosomes as the stream and
23 // the whole human as the table (so we need to actually store a large
24 // number of hits), we see a savings of 2GB and a small drop in
25 // runtime. Process size went from 20.7GB to 18.7GB, CPU time from
26 // 20578 to 20193 seconds (833MHz EV6.8AL (21264B)).
27 //
28 #define WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`!
29
30
31 struct diagonalLinecxx . . $ diagonalLine# {
32 uint32cxx . . $ uint32# _qsPoscxx . . $ diagonalLine#_qsPos.;
33 uint32cxx . . $ uint32# _dsPoscxx . . $ diagonalLine#_dsPos.;
34 #ifndef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`!
35 uint32 _diagonalID;
36 #endif
37 };
38
39 class trapMatchcxx . . $ trapMatch# {
40 public:
41 uint32cxx . . $ uint32# _qsLocxx . . $ trapMatch#_qsLo., _qsHicxx . . $ trapMatch#_qsHi.;
42 uint32cxx . . $ uint32# _dsLocxx . . $ trapMatch#_dsLo., _dsHicxx . . $ trapMatch#_dsHi.;
43 merCoveringcxx . . $ merCovering# *_ILcxx . . $ trapMatch#_IL.;
44 trapMatchcxx . . $ trapMatch# *_nextcxx . . $ trapMatch#_next.;
45
46 trapMatchcxx . . $ trapMatch#trapMatch(be234fe48972ff86).(uint32cxx . . $ uint32# qsLo,
47 uint32cxx . . $ uint32# qsHi,
48 uint32cxx . . $ uint32# dsLo,
49 uint32cxx . . $ uint32# dsHi,
50 merCoveringcxx . . $ merCovering# *IL) {
51 _qsLocxx . . $ trapMatch#_qsLo. = qsLo;
52 _qsHicxx . . $ trapMatch#_qsHi. = qsHi;
53 _dsLocxx . . $ trapMatch#_dsLo. = dsLo;
54 _dsHicxx . . $ trapMatch#_dsHi. = dsHi;
55 _ILcxx . . $ trapMatch#_IL. = IL;
56 _nextcxx . . $ trapMatch#_next. = 0L;
57 };
58 };
59
60 class hitMatrixcxx . . $ hitMatrix# {
61 public:
62 hitMatrixcxx . . $ hitMatrix#hitMatrix(6df00707c193238d).(uint32cxx . . $ uint32# qsLen,
63 uint32cxx . . $ uint32# qsMers,
64 uint32cxx . . $ uint32# qsIdx);
65 ~cxx . . $ hitMatrix#`~hitMatrix`(49f6e7a06ebc5aa8).hitMatrixcxx . . $ hitMatrix#();
66
67 void addHitscxx . . $ hitMatrix#addHits(19fbb4f67f92d147).(uint32cxx . . $ uint32# qi,
68 uint64cxx . . $ uint64# *ps,
69 uint64cxx . . $ uint64# cn);
70
71 void sort_diagonalcxx . . $ hitMatrix#sort_diagonal(49f6e7a06ebc5aa8).(void);
72 void sort_dsPoscxx . . $ hitMatrix#sort_dsPos(49f6e7a06ebc5aa8).(void);
73
74 void filtercxx . . $ hitMatrix#filter(ed2fd544d42a775a).(encodedQuerycxx . . $ encodedQuery# *query, bool isReverse);
75 private:
76 uint32cxx . . $ uint32# _qsLencxx . . $ hitMatrix#_qsLen.; // Seq Len of Q
77 uint32cxx . . $ uint32# _qsMerscxx . . $ hitMatrix#_qsMers.; // Valid mers in Q
78 uint32cxx . . $ uint32# _qsIdxcxx . . $ hitMatrix#_qsIdx.; // Index of Q in the FastA
79
80 // Instead of building the lines during add(), we store
81 // the information used to build lines, and then build them
82 // in chain(). This was done to reduce simultaneous memory
83 // usage, as the lineArrayMap and etc take up considerable space.
84 //
85 uint32cxx . . $ uint32# _hitsLencxx . . $ hitMatrix#_hitsLen.;
86 uint32cxx . . $ uint32# _hitsMaxcxx . . $ hitMatrix#_hitsMax.;
87 diagonalLinecxx . . $ diagonalLine# *_hitscxx . . $ hitMatrix#_hits.;
88
89
90 // Making sense of the raw output from the search is not a trivial
91 // task for perl. SMALL searches (dbEST vs 0.5MB sequence) used more
92 // than 4GB of memory in perl.
93 //
94 // So, we bite the bullet and do it here.
95 //
96 // _matches is a sorted linked list of the regions we have found.
97 // The list is kept in REVERSE order, as we usually add regions
98 // in the correct order (correct reverse order), occasionally
99 // we need to swap the last two.
100 //
101 // The list is deleted in filter()
102 //
103 trapMatchcxx . . $ trapMatch# *_matchescxx . . $ hitMatrix#_matches.;
104
105 void addMatchcxx . . $ hitMatrix#addMatch(be234fe48972ff86).(uint32cxx . . $ uint32# qsLo,
106 uint32cxx . . $ uint32# qsHi,
107 uint32cxx . . $ uint32# dsLo,
108 uint32cxx . . $ uint32# dsHi,
109 merCoveringcxx . . $ merCovering# *IL);
110
111 };
112
113
114 inline
115 void
116 hitMatrixcxx . . $ hitMatrix#::addHitscxx . . $ hitMatrix#addHits(19fbb4f67f92d147).(uint32cxx . . $ uint32# qi,
117 uint64cxx . . $ uint64# *ps,
118 uint64cxx . . $ uint64# cn) {
119
120 if ((_hitsLencxx . . $ hitMatrix#_hitsLen. + cn) >= _hitsMaxcxx . . $ hitMatrix#_hitsMax.) {
121 _hitsMaxcxx . . $ hitMatrix#_hitsMax. = _hitsMaxcxx . . $ hitMatrix#_hitsMax. + _hitsMaxcxx . . $ hitMatrix#_hitsMax. + (uint32cxx . . $ uint32#)cn;
122
123 diagonalLinecxx . . $ diagonalLine# *h;
124 try {
125 h = new diagonalLinecxx . . $ diagonalLine# [_hitsMaxcxx . . $ hitMatrix#_hitsMax.];
126 } catch (stdcxx . . $ std/::bad_alloccxx . . $ std/bad_alloc#)cxx . . $ std/bad_alloc#bad_alloc(f0898f11383ce75e). {
127 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "hitMatrix::addHits()-- caught std::bad_alloc in %s at line %d.\n", __FILE__, __LINE__);
128 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "hitMatrix::addHits()-- have "uint32FMTcxx . . $ `libutil/util.h:65:10`!" hits, tried to add "uint64FMTcxx . . $ `libutil/util.h:55:10`!" more\n", _hitsLencxx . . $ hitMatrix#_hitsLen., cn);
129 exitcxx . . $ exit(44ed87f96534fad7).(1);
130 }
131
132 for (uint32cxx . . $ uint32# z=_hitsLencxx . . $ hitMatrix#_hitsLen.; z--; ) {
133 h[z]._qsPoscxx . . $ diagonalLine#_qsPos. = _hitscxx . . $ hitMatrix#_hits.[z]._qsPoscxx . . $ diagonalLine#_qsPos.;
134 h[z]._dsPoscxx . . $ diagonalLine#_dsPos. = _hitscxx . . $ hitMatrix#_hits.[z]._dsPoscxx . . $ diagonalLine#_dsPos.;
135 #ifndef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`!
136 h[z]._diagonalID = _hits[z]._diagonalID;
137 #endif
138 }
139
140 delete [] _hitscxx . . $ hitMatrix#_hits.;
141
142 _hitscxx . . $ hitMatrix#_hits. = h;
143 }
144
145 for (uint64cxx . . $ uint64# i=0; i<cn; i++) {
146 _hitscxx . . $ hitMatrix#_hits.[_hitsLencxx . . $ hitMatrix#_hitsLen.]._qsPoscxx . . $ diagonalLine#_qsPos. = (uint32cxx . . $ uint32#)(qi);
147 _hitscxx . . $ hitMatrix#_hits.[_hitsLencxx . . $ hitMatrix#_hitsLen.]._dsPoscxx . . $ diagonalLine#_dsPos. = (uint32cxx . . $ uint32#)(ps[i]);
148 #ifndef WITHOUT_DIAGONALIDcxx . . $ `seagen/hitMatrix.H:28:9`!
149 _hits[_hitsLen]._diagonalID = (uint32)(_qsLen - qi - 1 + ps[i]);
150 #endif
151 _hitsLencxx . . $ hitMatrix#_hitsLen.++;
152 }
153 }
154
155
156 #endif // HITMATRIX_H