@@ -69,7 +69,7 @@ from cpython cimport PyErr_SetString, PyBytes_Check, \
69
69
cimport pysam.libctabixproxies as ctabixproxies
70
70
71
71
from pysam.libchtslib cimport htsFile, hts_open, hts_close, HTS_IDX_START,\
72
- BGZF, bgzf_open, bgzf_dopen, bgzf_close, bgzf_write, \
72
+ BGZF, bgzf_open, bgzf_dopen, bgzf_close, bgzf_getline, bgzf_write, \
73
73
tbx_index_build2, tbx_index_load2, tbx_itr_queryi, tbx_itr_querys, \
74
74
tbx_conf_t, tbx_seqnames, tbx_itr_next, tbx_itr_destroy, \
75
75
tbx_destroy, hisremote, region_list, hts_getline, \
@@ -79,22 +79,6 @@ from pysam.libchtslib cimport htsFile, hts_open, hts_close, HTS_IDX_START,\
79
79
from pysam.libcutils cimport force_bytes, force_str, charptr_to_str
80
80
from pysam.libcutils cimport encode_filename, from_string_and_size
81
81
82
- cdef extern from " htslib/kseq.h" nogil:
83
- """
84
- #undef __KS_TYPE
85
- #define __KS_TYPE(type_t)
86
- KSTREAM_INIT2(static, BGZF *, bgzf_read, 16384)
87
- """
88
- kstream_t * ks_init(BGZF * )
89
- void ks_destroy(kstream_t * )
90
-
91
- # Retrieve characters from stream until delimiter
92
- # is reached placing results in str.
93
- int ks_getuntil(kstream_t * ,
94
- int delimiter,
95
- kstring_t * str ,
96
- int * dret)
97
-
98
82
99
83
cdef class Parser:
100
84
@@ -749,7 +733,6 @@ cdef class GZIterator:
749
733
with nogil:
750
734
self .gzipfile = bgzf_open(cfilename, " r" )
751
735
self ._filename = filename
752
- self .kstream = ks_init(self .gzipfile)
753
736
self .encoding = encoding
754
737
755
738
self .buffer.l = 0
@@ -763,24 +746,15 @@ cdef class GZIterator:
763
746
self .gzipfile = NULL
764
747
if self .buffer.s != NULL :
765
748
free(self .buffer.s)
766
- if self .kstream != NULL :
767
- ks_destroy(self .kstream)
768
749
769
750
def __iter__ (self ):
770
751
return self
771
752
772
753
cdef int __cnext__(self ):
773
- cdef int dret = 0
774
- cdef int retval = 0
775
- while 1 :
776
- with nogil:
777
- retval = ks_getuntil(self .kstream, b' \n ' , & self .buffer, & dret)
778
-
779
- if retval < 0 :
780
- break
781
-
782
- return dret
783
- return - 1
754
+ cdef int retval
755
+ with nogil:
756
+ retval = bgzf_getline(self .gzipfile, b' \n ' , & self .buffer)
757
+ return retval
784
758
785
759
def __next__ (self ):
786
760
""" python version of next().
@@ -1144,8 +1118,6 @@ cdef class tabix_file_iterator:
1144
1118
if self .fh == NULL :
1145
1119
raise IOError (' %s ' % strerror(errno))
1146
1120
1147
- self .kstream = ks_init(self .fh)
1148
-
1149
1121
self .buffer.s = < char * > malloc(buffer_size)
1150
1122
# if self.buffer == NULL:
1151
1123
# raise MemoryError( "tabix_file_iterator: could not allocate %i bytes" % buffer_size)
@@ -1158,12 +1130,11 @@ cdef class tabix_file_iterator:
1158
1130
cdef __cnext__(self ):
1159
1131
1160
1132
cdef char * b
1161
- cdef int dret = 0
1162
1133
cdef int retval = 0
1163
1134
while 1 :
1164
1135
with nogil:
1165
- retval = ks_getuntil (self .kstream , b' \n ' , & self .buffer, & dret )
1166
-
1136
+ retval = bgzf_getline (self .fh , b' \n ' , & self .buffer)
1137
+
1167
1138
if retval < 0 :
1168
1139
break
1169
1140
# raise IOError('gzip error: %s' % buildGzipError( self.fh ))
@@ -1187,7 +1158,6 @@ cdef class tabix_file_iterator:
1187
1158
1188
1159
def __dealloc__ (self ):
1189
1160
free(self .buffer.s)
1190
- ks_destroy(self .kstream)
1191
1161
bgzf_close(self .fh)
1192
1162
1193
1163
def __next__ (self ):
0 commit comments