htslib 0.2.2 → 0.2.5
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 +42 -22
- data/lib/hts/bam/{aux.rb → auxi.rb} +6 -0
- data/lib/hts/bam/header.rb +53 -2
- data/lib/hts/bam/header_record.rb +11 -0
- data/lib/hts/bam/record.rb +65 -24
- data/lib/hts/bam.rb +73 -66
- data/lib/hts/bcf/format.rb +4 -4
- data/lib/hts/bcf/header.rb +79 -2
- data/lib/hts/bcf/header_record.rb +35 -1
- data/lib/hts/bcf/info.rb +4 -4
- data/lib/hts/bcf.rb +85 -76
- data/lib/hts/hts.rb +2 -2
- data/lib/hts/libhts/constants.rb +36 -4
- data/lib/hts/libhts/cram.rb +39 -0
- data/lib/hts/libhts/sam_funcs.rb +16 -0
- data/lib/hts/libhts/tbx_funcs.rb +2 -0
- data/lib/hts/libhts/vcf.rb +84 -2
- data/lib/hts/libhts/vcf_funcs.rb +49 -8
- data/lib/hts/libhts.rb +2 -1
- data/lib/hts/tbx.rb +1 -5
- data/lib/hts/version.rb +1 -1
- data/lib/htslib.rb +16 -1
- metadata +6 -4
data/lib/hts/libhts/constants.rb
CHANGED
@@ -188,6 +188,10 @@ module HTS
|
|
188
188
|
:n_mapped, :uint64,
|
189
189
|
:n_unmapped, :uint64
|
190
190
|
)
|
191
|
+
|
192
|
+
def self.release(ptr)
|
193
|
+
LibHTS.hts_idx_destroy(ptr) unless ptr.null?
|
194
|
+
end
|
191
195
|
end
|
192
196
|
|
193
197
|
class HtsReglist < FFI::Struct
|
@@ -195,7 +199,7 @@ module HTS
|
|
195
199
|
:reg, :string,
|
196
200
|
:intervals, :pointer, # hts_pair_pos_t
|
197
201
|
:tid, :int,
|
198
|
-
:count, :
|
202
|
+
:count, :uint32,
|
199
203
|
:min_beg, :hts_pos_t,
|
200
204
|
:max_end, :hts_pos_t
|
201
205
|
end
|
@@ -213,6 +217,10 @@ module HTS
|
|
213
217
|
:sdict, :pointer,
|
214
218
|
:hrecs, :pointer,
|
215
219
|
:ref_count, :uint32
|
220
|
+
|
221
|
+
def self.release(ptr)
|
222
|
+
LibHTS.sam_hdr_destroy(ptr) unless ptr.null?
|
223
|
+
end
|
216
224
|
end
|
217
225
|
|
218
226
|
BamHdr = SamHdr
|
@@ -251,6 +259,10 @@ module HTS
|
|
251
259
|
layout \
|
252
260
|
:pool, :pointer,
|
253
261
|
:qsize, :int
|
262
|
+
|
263
|
+
def self.release(ptr)
|
264
|
+
LibHTS.hts_tpool_destroy(ptr) unless ptr.null?
|
265
|
+
end
|
254
266
|
end
|
255
267
|
|
256
268
|
class HtsOpt < FFI::Struct
|
@@ -300,6 +312,10 @@ module HTS
|
|
300
312
|
:nocoor, 1,
|
301
313
|
:multi, 1,
|
302
314
|
:dummy, 27
|
315
|
+
|
316
|
+
def self.release(ptr)
|
317
|
+
LibHTS.hts_itr_destroy(ptr) unless ptr.null?
|
318
|
+
end
|
303
319
|
end
|
304
320
|
|
305
321
|
class Bam1Core < FFI::Struct
|
@@ -352,7 +368,7 @@ module HTS
|
|
352
368
|
:qpos, :int32_t,
|
353
369
|
:indel, :int,
|
354
370
|
:level, :int,
|
355
|
-
:_flags, :
|
371
|
+
:_flags, :uint32, # bit_fields
|
356
372
|
:cd, BamPileupCd,
|
357
373
|
:cigar_ind, :int
|
358
374
|
|
@@ -380,6 +396,10 @@ module HTS
|
|
380
396
|
:conf, TbxConf.ptr,
|
381
397
|
:idx, HtsIdx.ptr,
|
382
398
|
:dict, :pointer
|
399
|
+
|
400
|
+
def self.release(ptr)
|
401
|
+
LibHTS.tbx_destroy(ptr) unless ptr.null?
|
402
|
+
end
|
383
403
|
end
|
384
404
|
|
385
405
|
# faidx
|
@@ -393,6 +413,10 @@ module HTS
|
|
393
413
|
:name, :pointer,
|
394
414
|
:hash, :pointer,
|
395
415
|
:format, FaiFormatOptions
|
416
|
+
|
417
|
+
def self.release(ptr)
|
418
|
+
LibHTS.fai_destroy(ptr) unless ptr.null?
|
419
|
+
end
|
396
420
|
end
|
397
421
|
|
398
422
|
# bcf
|
@@ -412,6 +436,10 @@ module HTS
|
|
412
436
|
:nkeys, :int,
|
413
437
|
:keys, :pointer,
|
414
438
|
:vals, :pointer
|
439
|
+
|
440
|
+
def self.release(ptr)
|
441
|
+
LibHTS.bcf_hrec_destroy(ptr) unless ptr.null?
|
442
|
+
end
|
415
443
|
end
|
416
444
|
|
417
445
|
class BcfInfo < FFI::BitStruct
|
@@ -461,6 +489,10 @@ module HTS
|
|
461
489
|
:keep_samples, :pointer,
|
462
490
|
:mem, KString,
|
463
491
|
:m, [:int, 3]
|
492
|
+
|
493
|
+
def self.release(ptr)
|
494
|
+
LibHTS.bcf_hdr_destroy(ptr) unless ptr.null?
|
495
|
+
end
|
464
496
|
end
|
465
497
|
|
466
498
|
class BcfFmt < FFI::BitStruct
|
@@ -506,8 +538,8 @@ module HTS
|
|
506
538
|
:rlen, :hts_pos_t,
|
507
539
|
:rid, :int32_t,
|
508
540
|
:qual, :float,
|
509
|
-
:_n_info_allele, :
|
510
|
-
:_n_fmt_sample, :
|
541
|
+
:_n_info_allele, :uint32,
|
542
|
+
:_n_fmt_sample, :uint32,
|
511
543
|
:shared, KString,
|
512
544
|
:indiv, KString,
|
513
545
|
:d, BcfDec,
|
data/lib/hts/libhts/cram.rb
CHANGED
@@ -7,6 +7,8 @@ module HTS
|
|
7
7
|
typedef :pointer, :cram_block
|
8
8
|
typedef :pointer, :cram_metrics
|
9
9
|
|
10
|
+
# cram_fd
|
11
|
+
|
10
12
|
attach_function \
|
11
13
|
:cram_fd_get_header,
|
12
14
|
[:cram_fd],
|
@@ -82,6 +84,8 @@ module HTS
|
|
82
84
|
[:cram_fd],
|
83
85
|
:int
|
84
86
|
|
87
|
+
# cram_block
|
88
|
+
|
85
89
|
attach_function \
|
86
90
|
:cram_block_get_content_id,
|
87
91
|
[:cram_block],
|
@@ -157,71 +161,88 @@ module HTS
|
|
157
161
|
%i[cram_block size_t],
|
158
162
|
:void
|
159
163
|
|
164
|
+
# Computes the size of a cram block, including the block header itself.
|
160
165
|
attach_function \
|
161
166
|
:cram_block_size,
|
162
167
|
[:cram_block],
|
163
168
|
:uint32
|
164
169
|
|
170
|
+
# Renumbers RG numbers in a cram compression header.
|
165
171
|
attach_function \
|
166
172
|
:cram_transcode_rg,
|
167
173
|
%i[cram_fd cram_fd cram_container int pointer pointer],
|
168
174
|
:int
|
169
175
|
|
176
|
+
# Copies the blocks representing the next num_slice slices from a
|
177
|
+
# container from 'in' to 'out'.
|
170
178
|
attach_function \
|
171
179
|
:cram_copy_slice,
|
172
180
|
%i[cram_fd cram_fd int32],
|
173
181
|
:int
|
174
182
|
|
183
|
+
# Returns the number of cram blocks within this slice.
|
175
184
|
attach_function \
|
176
185
|
:cram_slice_hdr_get_num_blocks,
|
177
186
|
[:pointer],
|
178
187
|
:int32
|
179
188
|
|
189
|
+
# Returns the block content_id for the block containing an embedded
|
190
|
+
# reference sequence.
|
180
191
|
attach_function \
|
181
192
|
:cram_slice_hdr_get_embed_ref_id,
|
182
193
|
[:pointer],
|
183
194
|
:int
|
184
195
|
|
196
|
+
# Returns slice reference ID, start and span (length) coordinates.
|
185
197
|
attach_function \
|
186
198
|
:cram_slice_hdr_get_coords,
|
187
199
|
%i[pointer pointer pointer pointer],
|
188
200
|
:void
|
189
201
|
|
202
|
+
# Decodes a slice header from a cram block.
|
190
203
|
attach_function \
|
191
204
|
:cram_decode_slice_header,
|
192
205
|
%i[pointer pointer],
|
193
206
|
:pointer
|
194
207
|
|
208
|
+
# Frees a cram_block_slice_hdr structure.
|
195
209
|
attach_function \
|
196
210
|
:cram_free_slice_header,
|
197
211
|
[:pointer],
|
198
212
|
:void
|
199
213
|
|
214
|
+
# Allocates a new cram_block structure with a specified content_type
|
215
|
+
# and id.
|
200
216
|
attach_function \
|
201
217
|
:cram_new_block,
|
202
218
|
[CramContentType, :int],
|
203
219
|
:cram_block
|
204
220
|
|
221
|
+
# Reads a block from a cram file.
|
205
222
|
attach_function \
|
206
223
|
:cram_read_block,
|
207
224
|
[:cram_fd],
|
208
225
|
:cram_block
|
209
226
|
|
227
|
+
# Writes a CRAM block.
|
210
228
|
attach_function \
|
211
229
|
:cram_write_block,
|
212
230
|
%i[cram_fd cram_block],
|
213
231
|
:int
|
214
232
|
|
233
|
+
# Frees a CRAM block, deallocating internal data too.
|
215
234
|
attach_function \
|
216
235
|
:cram_free_block,
|
217
236
|
[:cram_block],
|
218
237
|
:void
|
219
238
|
|
239
|
+
# Uncompresses a CRAM block, if compressed.
|
220
240
|
attach_function \
|
221
241
|
:cram_uncompress_block,
|
222
242
|
[:cram_block],
|
223
243
|
:int
|
224
244
|
|
245
|
+
# Compresses a block.
|
225
246
|
attach_function \
|
226
247
|
:cram_compress_block,
|
227
248
|
%i[cram_fd cram_block cram_metrics int int],
|
@@ -232,6 +253,8 @@ module HTS
|
|
232
253
|
# %i[cram_fd cram_slice cram_block cram_metrics int int],
|
233
254
|
# :int
|
234
255
|
|
256
|
+
# Creates a new container, specifying the maximum number of slices
|
257
|
+
# and records permitted.
|
235
258
|
attach_function \
|
236
259
|
:cram_new_container,
|
237
260
|
%i[int int],
|
@@ -242,16 +265,20 @@ module HTS
|
|
242
265
|
[:cram_container],
|
243
266
|
:void
|
244
267
|
|
268
|
+
# Reads a container header.
|
245
269
|
attach_function \
|
246
270
|
:cram_read_container,
|
247
271
|
[:cram_fd],
|
248
272
|
:cram_container
|
249
273
|
|
274
|
+
# Writes a container structure.
|
250
275
|
attach_function \
|
251
276
|
:cram_write_container,
|
252
277
|
%i[cram_fd cram_container],
|
253
278
|
:int
|
254
279
|
|
280
|
+
# Stores the container structure in dat and returns *size as the
|
281
|
+
# number of bytes written to dat[].
|
255
282
|
attach_function \
|
256
283
|
:cram_store_container,
|
257
284
|
%i[cram_fd cram_container string pointer],
|
@@ -262,61 +289,73 @@ module HTS
|
|
262
289
|
[:cram_container],
|
263
290
|
:int
|
264
291
|
|
292
|
+
# Opens a CRAM file for read (mode "rb") or write ("wb").
|
265
293
|
attach_function \
|
266
294
|
:cram_open,
|
267
295
|
%i[string string],
|
268
296
|
:cram_fd
|
269
297
|
|
298
|
+
# Opens an existing stream for reading or writing.
|
270
299
|
attach_function \
|
271
300
|
:cram_dopen,
|
272
301
|
%i[pointer string string],
|
273
302
|
:cram_fd
|
274
303
|
|
304
|
+
# Closes a CRAM file.
|
275
305
|
attach_function \
|
276
306
|
:cram_close,
|
277
307
|
[:cram_fd],
|
278
308
|
:int
|
279
309
|
|
310
|
+
# Seek within a CRAM file.
|
280
311
|
attach_function \
|
281
312
|
:cram_seek,
|
282
313
|
%i[pointer off_t int],
|
283
314
|
:int # FIXME: pointer should be :cram_fd
|
284
315
|
|
316
|
+
# Flushes a CRAM file.
|
285
317
|
attach_function \
|
286
318
|
:cram_flush,
|
287
319
|
[:cram_fd],
|
288
320
|
:int
|
289
321
|
|
322
|
+
# Checks for end of file on a cram_fd stream.
|
290
323
|
attach_function \
|
291
324
|
:cram_eof,
|
292
325
|
[:cram_fd],
|
293
326
|
:int
|
294
327
|
|
328
|
+
# Sets options on the cram_fd.
|
295
329
|
attach_function \
|
296
330
|
:cram_set_option,
|
297
331
|
[:cram_fd, HtsFmtOption, :varargs],
|
298
332
|
:int
|
299
333
|
|
334
|
+
# Sets options on the cram_fd.
|
300
335
|
attach_function \
|
301
336
|
:cram_set_voption,
|
302
337
|
[:cram_fd, HtsFmtOption, :pointer], # va_list
|
303
338
|
:int
|
304
339
|
|
340
|
+
# Attaches a header to a cram_fd.
|
305
341
|
attach_function \
|
306
342
|
:cram_set_header,
|
307
343
|
[:cram_fd, SamHdr.by_ref],
|
308
344
|
:int
|
309
345
|
|
346
|
+
# Check if this file has a proper EOF block
|
310
347
|
attach_function \
|
311
348
|
:cram_check_EOF,
|
312
349
|
[:cram_fd],
|
313
350
|
:int
|
314
351
|
|
352
|
+
# As int32_decoded/encode, but from/to blocks instead of cram_fd
|
315
353
|
attach_function \
|
316
354
|
:int32_put_blk,
|
317
355
|
%i[cram_block int32_t],
|
318
356
|
:int
|
319
357
|
|
358
|
+
# Returns the refs_t structure used by a cram file handle.
|
320
359
|
attach_function \
|
321
360
|
:cram_get_refs,
|
322
361
|
[HtsFile.by_ref],
|
data/lib/hts/libhts/sam_funcs.rb
CHANGED
@@ -58,58 +58,72 @@ module HTS
|
|
58
58
|
# macros
|
59
59
|
# function-like macros
|
60
60
|
class << self
|
61
|
+
# Get whether the query is on the reverse strand
|
61
62
|
def bam_is_rev(b)
|
62
63
|
b[:core][:flag] & BAM_FREVERSE != 0
|
63
64
|
end
|
64
65
|
|
66
|
+
# Get whether the query's mate is on the reverse strand
|
65
67
|
def bam_is_mrev(b)
|
66
68
|
b[:core][:flag] & BAM_FMREVERSE != 0
|
67
69
|
end
|
68
70
|
|
71
|
+
# Get the name of the query
|
69
72
|
def bam_get_qname(b)
|
70
73
|
b[:data]
|
71
74
|
end
|
72
75
|
|
76
|
+
# Get the CIGAR array
|
73
77
|
def bam_get_cigar(b)
|
74
78
|
b[:data] + b[:core][:l_qname]
|
75
79
|
end
|
76
80
|
|
81
|
+
# Get query sequence
|
77
82
|
def bam_get_seq(b)
|
78
83
|
b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname]
|
79
84
|
end
|
80
85
|
|
86
|
+
# Get query quality
|
81
87
|
def bam_get_qual(b)
|
82
88
|
b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname] + ((b[:core][:l_qseq] + 1) >> 1)
|
83
89
|
end
|
84
90
|
|
91
|
+
# Get auxiliary data
|
85
92
|
def bam_get_aux(b)
|
86
93
|
b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname] + ((b[:core][:l_qseq] + 1) >> 1) + b[:core][:l_qseq]
|
87
94
|
end
|
88
95
|
|
96
|
+
# Get length of auxiliary data
|
89
97
|
def bam_get_l_aux(b)
|
90
98
|
b[:l_data] - (b[:core][:n_cigar] << 2) - b[:core][:l_qname] - b[:core][:l_qseq] - ((b[:core][:l_qseq] + 1) >> 1)
|
91
99
|
end
|
92
100
|
|
101
|
+
# Get a base on read
|
93
102
|
def bam_seqi(s, i)
|
94
103
|
(s[i >> 1].read_uint8 >> ((~i & 1) << 2)) & 0xf
|
95
104
|
end
|
96
105
|
|
106
|
+
# Modifies a single base in the bam structure.
|
97
107
|
def bam_set_seqi(s, i, b)
|
98
108
|
s[i >> 1] = (s[i >> 1] & (0xf0 >> ((~i & 1) << 2))) | ((b) << ((~i & 1) << 2))
|
99
109
|
end
|
100
110
|
|
111
|
+
# Returns the SAM formatted text of the \@HD header line
|
101
112
|
def sam_hdr_find_hd(h, ks)
|
102
113
|
sam_hdr_find_line_id(h, "HD", nil, nil, ks)
|
103
114
|
end
|
104
115
|
|
116
|
+
# Returns the value associated with a given \@HD line tag
|
105
117
|
def sam_hdr_find_tag_hd(h, key, ks)
|
106
118
|
sam_hdr_find_tag_id(h, "HD", nil, nil, key, ks)
|
107
119
|
end
|
108
120
|
|
121
|
+
# Adds or updates tags on the header \@HD line
|
109
122
|
def sam_hdr_update_hd(h, *args)
|
110
123
|
sam_hdr_update_line(h, "HD", nil, nil, *args, nil)
|
111
124
|
end
|
112
125
|
|
126
|
+
# Removes the \@HD line tag with the given key
|
113
127
|
def sam_hdr_remove_tag_hd(h, key)
|
114
128
|
sam_hdr_remove_tag_id(h, "HD", nil, nil, key)
|
115
129
|
end
|
@@ -122,6 +136,8 @@ module HTS
|
|
122
136
|
alias bam_itr_querys sam_itr_querys
|
123
137
|
alias bam_itr_next sam_itr_next
|
124
138
|
|
139
|
+
# Load/build .csi or .bai BAM index file. Does not work with CRAM.
|
140
|
+
# It is recommended to use the sam_index_* functions below instead.
|
125
141
|
def bam_index_load(fn)
|
126
142
|
hts_idx_load(fn, HTS_FMT_BAI)
|
127
143
|
end
|