| 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 |
|
| 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 |
|
| 33 |
+ if ((fn = hts_open(cfilename, "r")) == 0) { |
| 34 |
cerr << "[tabix++] fail to open the data file." << endl; |
| 35 |
exit(1); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
+ if ((tbx = tbx_index_load(cfilename)) == NULL) { |
| 40 |
cerr << "[tabix++] failed to load the index file." << endl; |
| 41 |
exit(1); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 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 |
|
| 56 |
+ current_chrom = chroms.begin(); |
| 57 |
+ iter = tbx_itr_querys(tbx, current_chrom->c_str()); |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
Tabix::~Tabix(void) { |
| 62 |
|
| 63 |
|
| 64 |
+ tbx_itr_destroy(iter); |
| 65 |
+ tbx_destroy(tbx); |
| 66 |
} |
| 67 |
|
| 68 |
void Tabix::getHeader(string& header) { |
| 69 |
header.clear(); |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 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 |
|
| 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 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 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 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 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 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 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 |
|
| 177 |
|
| 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 |
|
| 191 |
|
| 192 |
|
| 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 |