htslib 0.0.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +40 -33
- data/lib/hts/bam/aux.rb +40 -0
- data/lib/hts/bam/cigar.rb +10 -14
- data/lib/hts/bam/flag.rb +27 -58
- data/lib/hts/bam/header.rb +3 -5
- data/lib/hts/bam/record.rb +97 -56
- data/lib/hts/bam.rb +134 -64
- data/lib/hts/bcf/format.rb +85 -14
- data/lib/hts/bcf/header.rb +5 -4
- data/lib/hts/bcf/info.rb +58 -32
- data/lib/hts/bcf/record.rb +67 -38
- data/lib/hts/bcf.rb +155 -38
- data/lib/hts/faidx.rb +28 -19
- data/lib/hts/ffi_ext/pointer.rb +18 -0
- data/lib/hts/hts.rb +121 -0
- data/lib/hts/libhts/bgzf.rb +10 -5
- data/lib/hts/libhts/constants.rb +46 -7
- data/lib/hts/libhts/cram.rb +300 -0
- data/lib/hts/libhts/hfile.rb +37 -11
- data/lib/hts/libhts/hts.rb +158 -25
- data/lib/hts/libhts/sam.rb +683 -94
- data/lib/hts/libhts/sam_funcs.rb +92 -587
- data/lib/hts/libhts/vcf.rb +433 -220
- data/lib/hts/libhts/vcf_funcs.rb +232 -424
- data/lib/hts/libhts.rb +9 -3
- data/lib/hts/tbx.rb +45 -0
- data/lib/hts/version.rb +1 -1
- data/lib/htslib.rb +5 -5
- metadata +8 -4
- data/lib/hts/tabix.rb +0 -28
data/lib/hts/libhts/constants.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTS
|
4
|
+
# Module for working with C HTSlib.
|
4
5
|
module LibHTS
|
5
|
-
typedef :pointer, :HFILE
|
6
6
|
typedef :int64, :hts_pos_t
|
7
7
|
typedef :pointer, :bam_plp_auto_f
|
8
8
|
|
@@ -25,6 +25,25 @@ module HTS
|
|
25
25
|
:f, :pointer # kstream_t
|
26
26
|
end
|
27
27
|
|
28
|
+
# HFile
|
29
|
+
|
30
|
+
class HFile < FFI::BitStruct
|
31
|
+
layout \
|
32
|
+
:buffer, :string,
|
33
|
+
:begin, :string,
|
34
|
+
:end, :string,
|
35
|
+
:limit, :string,
|
36
|
+
:backend, :pointer,
|
37
|
+
:offset, :size_t,
|
38
|
+
:_flags, :uint,
|
39
|
+
:has_errno, :int
|
40
|
+
|
41
|
+
bit_fields :_flags,
|
42
|
+
:at_eof, 1,
|
43
|
+
:mobile, 1,
|
44
|
+
:readonly, 1
|
45
|
+
end
|
46
|
+
|
28
47
|
# BGZF
|
29
48
|
class BGZF < FFI::BitStruct
|
30
49
|
layout \
|
@@ -38,7 +57,7 @@ module HTS
|
|
38
57
|
:uncompressed_block, :pointer,
|
39
58
|
:compressed_block, :pointer,
|
40
59
|
:cache, :pointer,
|
41
|
-
:fp,
|
60
|
+
:fp, HFile.ptr,
|
42
61
|
:mt, :pointer,
|
43
62
|
:idx, :pointer,
|
44
63
|
:idx_build_otf, :int,
|
@@ -171,6 +190,16 @@ module HTS
|
|
171
190
|
)
|
172
191
|
end
|
173
192
|
|
193
|
+
class HtsReglist < FFI::Struct
|
194
|
+
layout \
|
195
|
+
:reg, :string,
|
196
|
+
:intervals, :pointer, # hts_pair_pos_t
|
197
|
+
:tid, :int,
|
198
|
+
:count, :uint32_t,
|
199
|
+
:min_beg, :hts_pos_t,
|
200
|
+
:max_end, :hts_pos_t
|
201
|
+
end
|
202
|
+
|
174
203
|
# HtsFile
|
175
204
|
class SamHdr < FFI::Struct
|
176
205
|
layout \
|
@@ -198,8 +227,8 @@ module HTS
|
|
198
227
|
:fp,
|
199
228
|
union_layout(
|
200
229
|
:bgzf, BGZF.ptr,
|
201
|
-
:cram, :pointer,
|
202
|
-
:hfile,
|
230
|
+
:cram, :pointer, # cram_fd
|
231
|
+
:hfile, HFile.ptr
|
203
232
|
),
|
204
233
|
:state, :pointer,
|
205
234
|
:format, HtsFormat,
|
@@ -245,7 +274,7 @@ module HTS
|
|
245
274
|
:n_reg, :int,
|
246
275
|
:beg, :int64,
|
247
276
|
:end, :int64,
|
248
|
-
:reg_list, :pointer,
|
277
|
+
:reg_list, :pointer, # HtsReglist.ptr,
|
249
278
|
:curr_tid, :int,
|
250
279
|
:curr_reg, :int,
|
251
280
|
:curr_intv, :int,
|
@@ -461,8 +490,8 @@ module HTS
|
|
461
490
|
:id, :string,
|
462
491
|
:als, :pointer, # (\\0-separated string)
|
463
492
|
:allele, :pointer,
|
464
|
-
:info, :pointer, # BcfInfo.ptr,
|
465
|
-
:fmt, BcfFmt.ptr,
|
493
|
+
:info, :pointer, # array of BcfInfo.ptr,
|
494
|
+
:fmt, :pointer, # array of BcfFmt.ptr,
|
466
495
|
:var, BcfVariant.ptr,
|
467
496
|
:n_var, :int,
|
468
497
|
:var_type, :int,
|
@@ -498,5 +527,15 @@ module HTS
|
|
498
527
|
LibHTS.bcf_destroy(ptr) unless ptr.null?
|
499
528
|
end
|
500
529
|
end
|
530
|
+
|
531
|
+
CramContentType = enum(
|
532
|
+
:ct_error, -1,
|
533
|
+
:file_header, 0,
|
534
|
+
:compression_header, 1,
|
535
|
+
:mapped_slice, 2,
|
536
|
+
:unmapped_slice, 3, # cram v1.0 only
|
537
|
+
:external, 4,
|
538
|
+
:core, 5
|
539
|
+
)
|
501
540
|
end
|
502
541
|
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HTS
|
4
|
+
module LibHTS
|
5
|
+
typedef :pointer, :cram_fd
|
6
|
+
typedef :pointer, :cram_container
|
7
|
+
typedef :pointer, :cram_block
|
8
|
+
typedef :pointer, :cram_metrics
|
9
|
+
|
10
|
+
attach_function \
|
11
|
+
:cram_fd_get_header,
|
12
|
+
[:cram_fd],
|
13
|
+
SamHdr.by_ref
|
14
|
+
|
15
|
+
attach_function \
|
16
|
+
:cram_fd_set_header,
|
17
|
+
[:cram_fd, SamHdr.by_ref],
|
18
|
+
:void
|
19
|
+
|
20
|
+
attach_function \
|
21
|
+
:cram_fd_get_version,
|
22
|
+
[:cram_fd],
|
23
|
+
:int
|
24
|
+
|
25
|
+
attach_function \
|
26
|
+
:cram_fd_set_version,
|
27
|
+
%i[cram_fd int],
|
28
|
+
:void
|
29
|
+
|
30
|
+
attach_function \
|
31
|
+
:cram_major_vers,
|
32
|
+
[:cram_fd],
|
33
|
+
:int
|
34
|
+
|
35
|
+
attach_function \
|
36
|
+
:cram_minor_vers,
|
37
|
+
[:cram_fd],
|
38
|
+
:int
|
39
|
+
|
40
|
+
attach_function \
|
41
|
+
:cram_fd_get_fp,
|
42
|
+
[:cram_fd],
|
43
|
+
HFile.by_ref
|
44
|
+
|
45
|
+
attach_function \
|
46
|
+
:cram_fd_set_fp,
|
47
|
+
[:cram_fd, HFile],
|
48
|
+
:void
|
49
|
+
|
50
|
+
attach_function \
|
51
|
+
:cram_container_get_length,
|
52
|
+
[:cram_container],
|
53
|
+
:int32
|
54
|
+
|
55
|
+
attach_function \
|
56
|
+
:cram_container_set_length,
|
57
|
+
%i[cram_container int32],
|
58
|
+
:void
|
59
|
+
|
60
|
+
attach_function \
|
61
|
+
:cram_container_get_num_blocks,
|
62
|
+
[:cram_container],
|
63
|
+
:int32
|
64
|
+
|
65
|
+
attach_function \
|
66
|
+
:cram_container_set_num_blocks,
|
67
|
+
%i[cram_container int32],
|
68
|
+
:void
|
69
|
+
|
70
|
+
attach_function \
|
71
|
+
:cram_container_get_landmarks,
|
72
|
+
%i[cram_container int32],
|
73
|
+
:pointer
|
74
|
+
|
75
|
+
attach_function \
|
76
|
+
:cram_container_set_landmarks,
|
77
|
+
%i[cram_container int32 pointer],
|
78
|
+
:void
|
79
|
+
|
80
|
+
attach_function \
|
81
|
+
:cram_container_is_empty,
|
82
|
+
[:cram_fd],
|
83
|
+
:int
|
84
|
+
|
85
|
+
attach_function \
|
86
|
+
:cram_block_get_content_id,
|
87
|
+
[:cram_block],
|
88
|
+
:int32
|
89
|
+
|
90
|
+
attach_function \
|
91
|
+
:cram_block_get_comp_size,
|
92
|
+
[:cram_block],
|
93
|
+
:int32
|
94
|
+
|
95
|
+
attach_function \
|
96
|
+
:cram_block_get_uncomp_size,
|
97
|
+
[:cram_block],
|
98
|
+
:int32
|
99
|
+
|
100
|
+
attach_function \
|
101
|
+
:cram_block_get_crc32,
|
102
|
+
[:cram_block],
|
103
|
+
:int32
|
104
|
+
|
105
|
+
attach_function \
|
106
|
+
:cram_block_get_data,
|
107
|
+
[:cram_block],
|
108
|
+
:pointer
|
109
|
+
|
110
|
+
attach_function \
|
111
|
+
:cram_block_get_content_type,
|
112
|
+
[:cram_block],
|
113
|
+
CramContentType
|
114
|
+
|
115
|
+
attach_function \
|
116
|
+
:cram_block_set_content_id,
|
117
|
+
%i[cram_block int32],
|
118
|
+
:void
|
119
|
+
|
120
|
+
attach_function \
|
121
|
+
:cram_block_set_comp_size,
|
122
|
+
%i[cram_block int32],
|
123
|
+
:void
|
124
|
+
|
125
|
+
attach_function \
|
126
|
+
:cram_block_set_uncomp_size,
|
127
|
+
%i[cram_block int32],
|
128
|
+
:void
|
129
|
+
|
130
|
+
attach_function \
|
131
|
+
:cram_block_set_crc32,
|
132
|
+
%i[cram_block int32],
|
133
|
+
:void
|
134
|
+
|
135
|
+
attach_function \
|
136
|
+
:cram_block_set_data,
|
137
|
+
%i[cram_block pointer],
|
138
|
+
:void
|
139
|
+
|
140
|
+
attach_function \
|
141
|
+
:cram_block_append,
|
142
|
+
%i[cram_block pointer int],
|
143
|
+
:int
|
144
|
+
|
145
|
+
attach_function \
|
146
|
+
:cram_block_update_size,
|
147
|
+
[:cram_block],
|
148
|
+
:void
|
149
|
+
|
150
|
+
attach_function \
|
151
|
+
:cram_block_get_offset,
|
152
|
+
[:cram_block],
|
153
|
+
:size_t
|
154
|
+
|
155
|
+
attach_function \
|
156
|
+
:cram_block_set_offset,
|
157
|
+
%i[cram_block size_t],
|
158
|
+
:void
|
159
|
+
|
160
|
+
attach_function \
|
161
|
+
:cram_block_size,
|
162
|
+
[:cram_block],
|
163
|
+
:uint32
|
164
|
+
|
165
|
+
attach_function \
|
166
|
+
:cram_transcode_rg,
|
167
|
+
%i[cram_fd cram_fd cram_container int pointer pointer],
|
168
|
+
:int
|
169
|
+
|
170
|
+
attach_function \
|
171
|
+
:cram_copy_slice,
|
172
|
+
%i[cram_fd cram_fd int32],
|
173
|
+
:int
|
174
|
+
|
175
|
+
attach_function \
|
176
|
+
:cram_new_block,
|
177
|
+
[CramContentType, :int],
|
178
|
+
:cram_block
|
179
|
+
|
180
|
+
attach_function \
|
181
|
+
:cram_read_block,
|
182
|
+
[:cram_fd],
|
183
|
+
:cram_block
|
184
|
+
|
185
|
+
attach_function \
|
186
|
+
:cram_write_block,
|
187
|
+
%i[cram_fd cram_block],
|
188
|
+
:int
|
189
|
+
|
190
|
+
attach_function \
|
191
|
+
:cram_free_block,
|
192
|
+
[:cram_block],
|
193
|
+
:void
|
194
|
+
|
195
|
+
attach_function \
|
196
|
+
:cram_uncompress_block,
|
197
|
+
[:cram_block],
|
198
|
+
:int
|
199
|
+
|
200
|
+
attach_function \
|
201
|
+
:cram_compress_block,
|
202
|
+
%i[cram_fd cram_block cram_metrics int int],
|
203
|
+
:int
|
204
|
+
|
205
|
+
# attach_function \
|
206
|
+
# :cram_compress_block2,
|
207
|
+
# %i[cram_fd cram_slice cram_block cram_metrics int int],
|
208
|
+
# :int
|
209
|
+
|
210
|
+
attach_function \
|
211
|
+
:cram_new_container,
|
212
|
+
%i[int int],
|
213
|
+
:cram_container
|
214
|
+
|
215
|
+
attach_function \
|
216
|
+
:cram_free_container,
|
217
|
+
[:cram_container],
|
218
|
+
:void
|
219
|
+
|
220
|
+
attach_function \
|
221
|
+
:cram_read_container,
|
222
|
+
[:cram_fd],
|
223
|
+
:cram_container
|
224
|
+
|
225
|
+
attach_function \
|
226
|
+
:cram_write_container,
|
227
|
+
%i[cram_fd cram_container],
|
228
|
+
:int
|
229
|
+
|
230
|
+
attach_function \
|
231
|
+
:cram_store_container,
|
232
|
+
%i[cram_fd cram_container string pointer],
|
233
|
+
:int
|
234
|
+
|
235
|
+
attach_function \
|
236
|
+
:cram_container_size,
|
237
|
+
[:cram_container],
|
238
|
+
:int
|
239
|
+
|
240
|
+
attach_function \
|
241
|
+
:cram_open,
|
242
|
+
%i[string string],
|
243
|
+
:cram_fd
|
244
|
+
|
245
|
+
attach_function \
|
246
|
+
:cram_dopen,
|
247
|
+
%i[pointer string string],
|
248
|
+
:cram_fd
|
249
|
+
|
250
|
+
attach_function \
|
251
|
+
:cram_close,
|
252
|
+
[:cram_fd],
|
253
|
+
:int
|
254
|
+
|
255
|
+
attach_function \
|
256
|
+
:cram_seek,
|
257
|
+
%i[pointer off_t int],
|
258
|
+
:int # FIXME: pointer should be :cram_fd
|
259
|
+
|
260
|
+
attach_function \
|
261
|
+
:cram_flush,
|
262
|
+
[:cram_fd],
|
263
|
+
:int
|
264
|
+
|
265
|
+
attach_function \
|
266
|
+
:cram_eof,
|
267
|
+
[:cram_fd],
|
268
|
+
:int
|
269
|
+
|
270
|
+
attach_function \
|
271
|
+
:cram_set_option,
|
272
|
+
[:cram_fd, HtsFmtOption, :varargs],
|
273
|
+
:int
|
274
|
+
|
275
|
+
attach_function \
|
276
|
+
:cram_set_voption,
|
277
|
+
[:cram_fd, HtsFmtOption, :pointer], # va_list
|
278
|
+
:int
|
279
|
+
|
280
|
+
attach_function \
|
281
|
+
:cram_set_header,
|
282
|
+
[:cram_fd, SamHdr.by_ref],
|
283
|
+
:int
|
284
|
+
|
285
|
+
attach_function \
|
286
|
+
:cram_check_EOF,
|
287
|
+
[:cram_fd],
|
288
|
+
:int
|
289
|
+
|
290
|
+
attach_function \
|
291
|
+
:int32_put_blk,
|
292
|
+
%i[cram_block int32_t],
|
293
|
+
:int
|
294
|
+
|
295
|
+
attach_function \
|
296
|
+
:cram_get_refs,
|
297
|
+
[HtsFile.by_ref],
|
298
|
+
:pointer # refs_t
|
299
|
+
end
|
300
|
+
end
|
data/lib/hts/libhts/hfile.rb
CHANGED
@@ -6,13 +6,13 @@ module HTS
|
|
6
6
|
attach_function \
|
7
7
|
:hopen,
|
8
8
|
%i[string string varargs],
|
9
|
-
|
9
|
+
HFile.by_ref
|
10
10
|
|
11
11
|
# Associate a stream with an existing open file descriptor
|
12
12
|
attach_function \
|
13
13
|
:hdopen,
|
14
14
|
%i[int string],
|
15
|
-
|
15
|
+
HFile.by_ref
|
16
16
|
|
17
17
|
# Report whether the file name or URL denotes remote storage
|
18
18
|
attach_function \
|
@@ -29,55 +29,81 @@ module HTS
|
|
29
29
|
# Flush (for output streams) and close the stream
|
30
30
|
attach_function \
|
31
31
|
:hclose,
|
32
|
-
[
|
32
|
+
[HFile],
|
33
33
|
:int
|
34
34
|
|
35
35
|
# Close the stream, without flushing or propagating errors
|
36
36
|
attach_function \
|
37
37
|
:hclose_abruptly,
|
38
|
-
[
|
38
|
+
[HFile],
|
39
39
|
:void
|
40
40
|
|
41
41
|
# Reposition the read/write stream offset
|
42
42
|
attach_function \
|
43
43
|
:hseek,
|
44
|
-
|
44
|
+
[HFile, :off_t, :int],
|
45
45
|
:off_t
|
46
46
|
|
47
|
+
# Report the current stream offset
|
48
|
+
def self.htell(fp)
|
49
|
+
# TODO: This is a hack. Is this OK?
|
50
|
+
bg = FFI::Pointer.new(:int, fp.pointer.address + fp.offset_of(:begin)).read_int
|
51
|
+
bf = FFI::Pointer.new(:int, fp.pointer.address + fp.offset_of(:buffer)).read_int
|
52
|
+
fp[:offset] + (bg - bf)
|
53
|
+
end
|
54
|
+
|
47
55
|
# Read from the stream until the delimiter, up to a maximum length
|
48
56
|
attach_function \
|
49
57
|
:hgetdelim,
|
50
|
-
|
58
|
+
[:string, :size_t, :int, HFile],
|
51
59
|
:ssize_t
|
52
60
|
|
53
61
|
# Read a line from the stream, up to a maximum length
|
54
62
|
attach_function \
|
55
63
|
:hgets,
|
56
|
-
|
64
|
+
[:string, :int, HFile],
|
57
65
|
:string
|
58
66
|
|
59
67
|
# Peek at characters to be read without removing them from buffers
|
60
68
|
attach_function \
|
61
69
|
:hpeek,
|
62
|
-
|
70
|
+
[HFile, :pointer, :size_t],
|
63
71
|
:ssize_t
|
64
72
|
|
65
73
|
# For writing streams, flush buffered output to the underlying stream
|
66
74
|
attach_function \
|
67
75
|
:hflush,
|
68
|
-
[
|
76
|
+
[HFile],
|
69
77
|
:int
|
70
78
|
|
71
79
|
# For hfile_mem: get the internal buffer and it's size from a hfile
|
72
80
|
attach_function \
|
73
81
|
:hfile_mem_get_buffer,
|
74
|
-
|
82
|
+
[HFile, :pointer],
|
75
83
|
:string
|
76
84
|
|
77
85
|
# For hfile_mem: get the internal buffer and it's size from a hfile.
|
78
86
|
attach_function \
|
79
87
|
:hfile_mem_steal_buffer,
|
80
|
-
|
88
|
+
[HFile, :pointer],
|
81
89
|
:string
|
90
|
+
|
91
|
+
# Fills out sc_list[] with the list of known URL schemes.
|
92
|
+
attach_function \
|
93
|
+
:hfile_list_schemes,
|
94
|
+
%i[string pointer pointer], # mutable string
|
95
|
+
:int
|
96
|
+
|
97
|
+
# Fills out plist[] with the list of known hFILE plugins.
|
98
|
+
attach_function \
|
99
|
+
:hfile_list_plugins,
|
100
|
+
%i[pointer pointer], # mutable string
|
101
|
+
:int
|
102
|
+
|
103
|
+
# Tests for the presence of a specific hFILE plugin.
|
104
|
+
attach_function \
|
105
|
+
:hfile_has_plugin,
|
106
|
+
[:string],
|
107
|
+
:int
|
82
108
|
end
|
83
109
|
end
|