Debian Codegraph @

debian/patches/02_Replace_libtabix_by_libhts.patch

raw symbols SCIP
1 Authorscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/patches/`02_Replace_libtabix_by_libhts.patch`#Author.: Dylan Aïssi <[email protected]scip-debian . . . identity/`[email protected]`.>
2 Descriptionscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/patches/`02_Replace_libtabix_by_libhts.patch`#Description.: Merge src/utils/tabix.*pp with upstream (libtabixpp 1.0.0) in order to use libhts instead libtabix.
3 Last-Updatescip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/patches/`02_Replace_libtabix_by_libhts.patch`#Last-Update.: 2016-04-29
4 Forwardedscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/patches/`02_Replace_libtabix_by_libhts.patch`#Forwarded.: no
5
6
7 --- a/Makefilescip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/upstream/Makefile:
8 +++ b/Makefilescip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/upstream/Makefile:
9 @@ -52,7 +52,7 @@
10 LIB_TABX=$(PATH_TABX)/libtabix.a
11 else
12 LIB_MATH=-lRmath
13 - LIB_TABX=-ltabix
14 + LIB_TABX=-lhts
15 endif
16 LIB_MACX=-L/usr/local/lib/
17
18 --- a/src/utils/tabix.cppscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/upstream/`src/utils/tabix.cpp`:
19 +++ b/src/utils/tabix.cppscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/upstream/`src/utils/tabix.cpp`:
20 @@ -8,6 +8,7 @@
21 Tabix::Tabix(void) { }
22
23 Tabix::Tabix(string& file) {
24 + has_jumped = false;
25 filename = file;
26 const char* cfilename = file.c_str();
27 struct stat stat_tbi,stat_vcf;
28 @@ -30,78 +31,99 @@
29 }
30 free(fnidx);
31
32 - if ((t = ti_open(cfilename, 0)) == 0) {
33 + if ((fn = hts_open(cfilename, "r")) == 0) {
34 cerr << "[tabix++] fail to open the data file." << endl;
35 exit(1);
36 }
37
38 - if (ti_lazy_index_load(t) < 0) {
39 + if ((tbx = tbx_index_load(cfilename)) == NULL) {
40 cerr << "[tabix++] failed to load the index file." << endl;
41 exit(1);
42 }
43
44 - idxconf = ti_get_conf(t->idx);
45 + int nseq;
46 + const char** seq = tbx_seqnames(tbx, &nseq);
47 + for (int i=0; i<nseq; i++) {
48 + chroms.push_back(seq[i]);
49 + }
50 + free(seq);
51 +
52 + idxconf = &tbx_conf_vcf;
53
54 // set up the iterator, defaults to the beginning
55 - iter = ti_query(t, 0, 0, 0);
56 + current_chrom = chroms.begin();
57 + iter = tbx_itr_querys(tbx, current_chrom->c_str());
58
59 }
60
61 Tabix::~Tabix(void) {
62 - ti_iter_destroy(iter);
63 - ti_close(t);
64 + tbx_itr_destroy(iter);
65 + tbx_destroy(tbx);
66 }
67
68 void Tabix::getHeader(string& header) {
69 header.clear();
70 - ti_iter_destroy(iter);
71 - iter = ti_query(t, 0, 0, 0);
72 - const char* s;
73 - int len;
74 - while ((s = ti_read(t, iter, &len)) != 0) {
75 - if ((int)(*s) != idxconf->meta_char) {
76 - firstline = string(s); // stash this line
77 + kstring_t str = {0,0,0};
78 + while ( hts_getline(fn, KS_SEP_LINE, &str) >= 0 ) {
79 + if ( !str.l || str.s[0]!=tbx->conf.meta_char ) {
80 break;
81 } else {
82 - header += string(s);
83 + header += string(str.s);
84 header += "\n";
85 }
86 }
87 + // set back to start
88 + current_chrom = chroms.begin();
89 + if (iter) tbx_itr_destroy(iter);
90 + iter = tbx_itr_querys(tbx, current_chrom->c_str());
91 }
92
93 void Tabix::getLastHeader(string & header) {
94 - header.clear();
95 - ti_iter_destroy(iter);
96 - iter = ti_query(t, 0, 0, 0);
97 - const char* s;
98 - int len;
99 - while ((s = ti_read(t, iter, &len)) != 0) {
100 - if ((int)(*s) != idxconf->meta_char) {
101 - firstline = string(s); // stash this line
102 - break;
103 - } else header = string(s);
104 - }
105 + header.clear();
106 + kstring_t str = {0,0,0};
107 + while ( hts_getline(fn, KS_SEP_LINE, &str) >= 0 ) {
108 + if ( !str.l || str.s[0]!=tbx->conf.meta_char ) {
109 + break;
110 + } else header = string(str.s);
111 + }
112 + // set back to start
113 + current_chrom = chroms.begin();
114 + if (iter) tbx_itr_destroy(iter);
115 + iter = tbx_itr_querys(tbx, current_chrom->c_str());
116 }
117
118 bool Tabix::setRegion(string region) {
119 - if (ti_parse_region(t->idx, region.c_str(), &tid, &beg, &end) == 0) {
120 - firstline.clear();
121 - ti_iter_destroy(iter);
122 - iter = ti_queryi(t, tid, beg, end);
123 - return true;
124 - } else return false;
125 + tbx_itr_destroy(iter);
126 + iter = tbx_itr_querys(tbx, region.c_str());
127 + has_jumped = true;
128 + return true;
129 }
130
131 bool Tabix::getNextLine(string & line) {
132 - const char* s;
133 - int len;
134 - if (!firstline.empty()) {
135 - line = firstline; // recovers line read if header is parsed
136 - firstline.clear();
137 - return true;
138 - }
139 - if ((s = ti_read(t, iter, &len)) != 0) {
140 - line = string(s);
141 - return true;
142 - } else return false;
143 + kstring_t str = {0,0,0};
144 + if (has_jumped) {
145 + if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
146 + line = string(str.s);
147 + return true;
148 + } else return false;
149 + } else { // step through all sequences in the file
150 + // we've never jumped, so read everything
151 + if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
152 + line = string(str.s);
153 + return true;
154 + } else {
155 + ++current_chrom;
156 + while (current_chrom != chroms.end()) {
157 + tbx_itr_destroy(iter);
158 + iter = tbx_itr_querys(tbx, current_chrom->c_str());
159 + if (iter && tbx_itr_next(fn, tbx, iter, &str) >= 0) {
160 + line = string(str.s);
161 + return true;
162 + } else {
163 + ++current_chrom;
164 + }
165 + }
166 + return false;
167 + }
168 + }
169 }
170 --- a/src/utils/tabix.hppscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/upstream/`src/utils/tabix.hpp`:
171 +++ b/src/utils/tabix.hppscip-debian debian fastqtl 2.184+v7+dfsg-5 fastqtl/upstream/`src/utils/tabix.hpp`:
172 @@ -9,24 +9,31 @@
173 #include <string>
174 #include <stdlib.h>
175 #include <sys/stat.h>
176 -#include <bgzf.h>
177 -#include <tabix.h>
178 +#include <htslib/bgzf.h>
179 +#include <htslib/tbx.h>
180 +#include <htslib/kseq.h>
181 #include <iostream>
182 +#include <cstring>
183 +#include <vector>
184
185
186 using namespace std;
187
188 class Tabix {
189
190 - tabix_t *t;
191 - ti_iter_t iter;
192 - const ti_conf_t *idxconf;
193 + htsFile* fn;
194 + tbx_t* tbx;
195 + hts_itr_t* iter;
196 + const tbx_conf_t *idxconf;
197 int tid, beg, end;
198 string firstline;
199 + bool has_jumped;
200 + vector<string>::iterator current_chrom;
201
202 public:
203
204 string filename;
205 + vector<string> chroms;
206
207 Tabix(void);
208 Tabix(string& file);
209 @@ -36,6 +43,7 @@
210 void getLastHeader(string & header);
211 bool setRegion(string region);
212 bool getNextLine(string& line);
213 +
214 };
215
216 #endif