htslib 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +68 -17
- data/lib/hts/bam/cigar.rb +9 -6
- data/lib/hts/bam/flag.rb +93 -0
- data/lib/hts/bam/header.rb +12 -6
- data/lib/hts/bam/record.rb +195 -0
- data/lib/hts/bam.rb +67 -32
- data/lib/hts/bcf/format.rb +52 -0
- data/lib/hts/bcf/header.rb +19 -0
- data/lib/hts/bcf/info.rb +93 -0
- data/lib/hts/bcf/record.rb +110 -0
- data/lib/hts/bcf.rb +73 -0
- data/lib/hts/faidx.rb +59 -0
- data/lib/hts/ffi_ext/README.md +8 -0
- data/lib/hts/ffi_ext/struct.rb +45 -0
- data/lib/hts/{ffi → libhts}/bgzf.rb +2 -2
- data/lib/hts/{ffi → libhts}/constants.rb +144 -76
- data/lib/hts/{ffi → libhts}/faidx.rb +1 -1
- data/lib/hts/{ffi → libhts}/hfile.rb +2 -2
- data/lib/hts/{ffi → libhts}/hts.rb +9 -3
- data/lib/hts/{ffi → libhts}/kfunc.rb +1 -1
- data/lib/hts/{ffi → libhts}/sam.rb +60 -30
- data/lib/hts/{ffi → libhts}/tbx.rb +1 -1
- data/lib/hts/{ffi → libhts}/vcf.rb +215 -12
- data/lib/hts/libhts.rb +33 -0
- data/lib/hts/tabix.rb +28 -0
- data/lib/hts/version.rb +1 -1
- data/lib/htslib.rb +32 -17
- metadata +49 -28
- data/lib/hts/bam/alignment.rb +0 -156
- data/lib/hts/fai.rb +0 -18
- data/lib/hts/ffi.rb +0 -43
- data/lib/hts/tbx.rb +0 -16
- data/lib/hts/vcf.rb +0 -32
@@ -1,24 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTS
|
4
|
-
module
|
4
|
+
module LibHTS
|
5
5
|
typedef :pointer, :HFILE
|
6
6
|
typedef :int64, :hts_pos_t
|
7
7
|
typedef :pointer, :bam_plp_auto_f
|
8
8
|
|
9
9
|
# kstring
|
10
10
|
|
11
|
-
class
|
11
|
+
class KString < FFI::Struct
|
12
12
|
layout \
|
13
13
|
:l, :size_t,
|
14
14
|
:m, :size_t,
|
15
15
|
:s, :string
|
16
16
|
end
|
17
17
|
|
18
|
+
class KSeq < FFI::Struct
|
19
|
+
layout \
|
20
|
+
:name, KString,
|
21
|
+
:comment, KString,
|
22
|
+
:seq, KString,
|
23
|
+
:qual, KString,
|
24
|
+
:last_char, :int,
|
25
|
+
:f, :pointer # kstream_t
|
26
|
+
end
|
27
|
+
|
18
28
|
# BGZF
|
19
|
-
class BGZF <
|
29
|
+
class BGZF < FFI::BitStruct
|
20
30
|
layout \
|
21
|
-
:
|
31
|
+
:_flags, :uint, # bit_fields
|
22
32
|
:cache_size, :int,
|
23
33
|
:block_length, :int,
|
24
34
|
:block_clength, :int,
|
@@ -34,9 +44,29 @@ module HTS
|
|
34
44
|
:idx_build_otf, :int,
|
35
45
|
:gz_stream, :pointer,
|
36
46
|
:seeked, :int64
|
47
|
+
|
48
|
+
bit_fields :_flags,
|
49
|
+
:errcode, 16,
|
50
|
+
:_reserved, 1,
|
51
|
+
:is_write, 1,
|
52
|
+
:no_eof_block, 1,
|
53
|
+
:is_be, 1,
|
54
|
+
:compress_level, 9,
|
55
|
+
:last_block_eof, 1,
|
56
|
+
:is_compressed, 1,
|
57
|
+
:is_gzip, 1
|
37
58
|
end
|
38
59
|
|
39
60
|
# hts
|
61
|
+
HtsLogLevel = enum(
|
62
|
+
:off, # All logging disabled.
|
63
|
+
:error, # Logging of errors only.
|
64
|
+
:warning, 3, # Logging of errors and warnings.
|
65
|
+
:info, # Logging of errors, warnings, and normal but significant events.
|
66
|
+
:debug, # Logging of all except the most detailed debug events.
|
67
|
+
:trace # All logging enabled.
|
68
|
+
)
|
69
|
+
|
40
70
|
HtsFormatCategory = enum(
|
41
71
|
:unknown_category,
|
42
72
|
:sequence_data, # Sequence data -- SAM, BAM, CRAM, etc
|
@@ -95,7 +125,7 @@ module HTS
|
|
95
125
|
:HTS_OPT_BLOCK_SIZE
|
96
126
|
)
|
97
127
|
|
98
|
-
class HtsFormat <
|
128
|
+
class HtsFormat < FFI::Struct
|
99
129
|
layout \
|
100
130
|
:category, HtsFormatCategory,
|
101
131
|
:format, HtsExactFormat,
|
@@ -109,7 +139,7 @@ module HTS
|
|
109
139
|
:specific, :pointer
|
110
140
|
end
|
111
141
|
|
112
|
-
class HtsIdx <
|
142
|
+
class HtsIdx < FFI::Struct
|
113
143
|
layout \
|
114
144
|
:fmt, :int,
|
115
145
|
:min_shift, :int,
|
@@ -142,7 +172,7 @@ module HTS
|
|
142
172
|
end
|
143
173
|
|
144
174
|
# HtsFile
|
145
|
-
class SamHdr <
|
175
|
+
class SamHdr < FFI::Struct
|
146
176
|
layout \
|
147
177
|
:n_targets, :int32,
|
148
178
|
:ignore_sam_err, :int32,
|
@@ -158,11 +188,11 @@ module HTS
|
|
158
188
|
|
159
189
|
BamHdr = SamHdr
|
160
190
|
|
161
|
-
class HtsFile <
|
191
|
+
class HtsFile < FFI::BitStruct
|
162
192
|
layout \
|
163
|
-
:
|
193
|
+
:_flags, :uint32, # bit_fields
|
164
194
|
:lineno, :int64,
|
165
|
-
:line,
|
195
|
+
:line, KString,
|
166
196
|
:fn, :string,
|
167
197
|
:fn_aux, :string,
|
168
198
|
:fp,
|
@@ -176,17 +206,25 @@ module HTS
|
|
176
206
|
:idx, HtsIdx.ptr,
|
177
207
|
:fnidx, :string,
|
178
208
|
:bam_header, SamHdr.ptr
|
209
|
+
|
210
|
+
bit_fields :_flags,
|
211
|
+
:is_bin, 1,
|
212
|
+
:is_write, 1,
|
213
|
+
:is_be, 1,
|
214
|
+
:is_cram, 1,
|
215
|
+
:is_bgzf, 1,
|
216
|
+
:dummy, 27
|
179
217
|
end
|
180
218
|
|
181
219
|
SamFile = HtsFile
|
182
220
|
|
183
|
-
class HtsThreadPool <
|
221
|
+
class HtsThreadPool < FFI::Struct
|
184
222
|
layout \
|
185
223
|
:pool, :pointer,
|
186
224
|
:qsize, :int
|
187
225
|
end
|
188
226
|
|
189
|
-
class HtsOpt <
|
227
|
+
class HtsOpt < FFI::Struct
|
190
228
|
layout \
|
191
229
|
:arg, :string,
|
192
230
|
:opt, HtsFmtOption,
|
@@ -198,9 +236,9 @@ module HTS
|
|
198
236
|
:next, HtsOpt.ptr
|
199
237
|
end
|
200
238
|
|
201
|
-
class HtsItr <
|
239
|
+
class HtsItr < FFI::BitStruct
|
202
240
|
layout \
|
203
|
-
:
|
241
|
+
:_flags, :uint32, # bit_fields
|
204
242
|
:tid, :int,
|
205
243
|
:n_off, :int,
|
206
244
|
:i, :int,
|
@@ -225,9 +263,17 @@ module HTS
|
|
225
263
|
:m, :int,
|
226
264
|
:a, :pointer
|
227
265
|
)
|
266
|
+
|
267
|
+
bit_fields :_flags,
|
268
|
+
:read_rest, 1,
|
269
|
+
:finished, 1,
|
270
|
+
:is_cram, 1,
|
271
|
+
:nocoor, 1,
|
272
|
+
:multi, 1,
|
273
|
+
:dummy, 27
|
228
274
|
end
|
229
275
|
|
230
|
-
class Bam1Core <
|
276
|
+
class Bam1Core < FFI::Struct
|
231
277
|
layout \
|
232
278
|
:pos, :hts_pos_t,
|
233
279
|
:tid, :int32,
|
@@ -243,53 +289,54 @@ module HTS
|
|
243
289
|
:isize, :hts_pos_t
|
244
290
|
end
|
245
291
|
|
246
|
-
class Bam1 <
|
292
|
+
class Bam1 < FFI::ManagedStruct
|
247
293
|
layout \
|
248
294
|
:core, Bam1Core,
|
249
295
|
:id, :uint64,
|
250
296
|
:data, :pointer, # uint8_t
|
251
297
|
:l_data, :int,
|
252
298
|
:m_data, :uint32,
|
253
|
-
:
|
299
|
+
:_mempolicy, :uint32 # bit_fields
|
300
|
+
|
301
|
+
# bit_fields :_mempolicy,
|
302
|
+
# :mempolicy, 2,
|
303
|
+
# :_reserved, 30
|
304
|
+
|
305
|
+
def self.release(ptr)
|
306
|
+
LibHTS.bam_destroy1(ptr) unless ptr.null?
|
307
|
+
end
|
254
308
|
end
|
255
309
|
|
256
|
-
|
310
|
+
typedef :pointer, :bam_plp
|
311
|
+
typedef :pointer, :bam_mplp
|
312
|
+
|
313
|
+
class BamPileupCd < FFI::Union
|
314
|
+
layout \
|
315
|
+
:p, :pointer,
|
316
|
+
:i, :int64_t,
|
317
|
+
:f, :double
|
257
318
|
end
|
258
319
|
|
259
|
-
class
|
320
|
+
class BamPileup1 < FFI::BitStruct
|
321
|
+
layout \
|
322
|
+
:b, Bam1.ptr,
|
323
|
+
:qpos, :int32_t,
|
324
|
+
:indel, :int,
|
325
|
+
:level, :int,
|
326
|
+
:_flags, :uint32_t, # bit_fields
|
327
|
+
:cd, BamPileupCd,
|
328
|
+
:cigar_ind, :int
|
329
|
+
|
330
|
+
bit_fields :_flags,
|
331
|
+
:is_del, 1,
|
332
|
+
:is_head, 1,
|
333
|
+
:is_tail, 1,
|
334
|
+
:is_refskip, 1,
|
335
|
+
:_reserved, 1,
|
336
|
+
:aux, 27
|
260
337
|
end
|
261
338
|
|
262
|
-
|
263
|
-
BAM_CINS = 1
|
264
|
-
BAM_CDEL = 2
|
265
|
-
BAM_CREF_SKIP = 3
|
266
|
-
BAM_CSOFT_CLIP = 4
|
267
|
-
BAM_CHARD_CLIP = 5
|
268
|
-
BAM_CPAD = 6
|
269
|
-
BAM_CEQUAL = 7
|
270
|
-
BAM_CDIFF = 8
|
271
|
-
BAM_CBACK = 9
|
272
|
-
|
273
|
-
BAM_CIGAR_STR = 'MIDNSHP=XB'
|
274
|
-
BAM_CIGAR_STR_PADDED = 'MIDNSHP=XB??????'
|
275
|
-
BAM_CIGAR_SHIFT = 4
|
276
|
-
BAM_CIGAR_MASK = 0xf
|
277
|
-
BAM_CIGAR_TYPE = 0x3C1A7
|
278
|
-
|
279
|
-
BAM_FPAIRED = 1
|
280
|
-
BAM_FPROPER_PAIR = 2
|
281
|
-
BAM_FUNMAP = 4
|
282
|
-
BAM_FMUNMAP = 8
|
283
|
-
BAM_FREVERSE = 16
|
284
|
-
BAM_FMREVERSE = 32
|
285
|
-
BAM_FREAD1 = 64
|
286
|
-
BAM_FREAD2 = 128
|
287
|
-
BAM_FSECONDARY = 256
|
288
|
-
BAM_FQCFAIL = 512
|
289
|
-
BAM_FDUP = 1024
|
290
|
-
BAM_FSUPPLEMENTARY = 2048
|
291
|
-
|
292
|
-
class TbxConf < ::FFI::Struct
|
339
|
+
class TbxConf < FFI::Struct
|
293
340
|
layout \
|
294
341
|
:preset, :int32,
|
295
342
|
:sc, :int32,
|
@@ -299,7 +346,7 @@ module HTS
|
|
299
346
|
:line_skip, :int32
|
300
347
|
end
|
301
348
|
|
302
|
-
class Tbx <
|
349
|
+
class Tbx < FFI::Struct
|
303
350
|
layout \
|
304
351
|
:conf, TbxConf.ptr,
|
305
352
|
:idx, HtsIdx.ptr,
|
@@ -310,7 +357,7 @@ module HTS
|
|
310
357
|
|
311
358
|
FaiFormatOptions = enum(:FAI_NONE, :FAI_FASTA, :FAI_FASTQ)
|
312
359
|
|
313
|
-
class Faidx <
|
360
|
+
class Faidx < FFI::Struct
|
314
361
|
layout :bgzf, BGZF,
|
315
362
|
:n, :int,
|
316
363
|
:m, :int,
|
@@ -319,15 +366,15 @@ module HTS
|
|
319
366
|
:format, FaiFormatOptions
|
320
367
|
end
|
321
368
|
|
322
|
-
#
|
369
|
+
# bcf
|
323
370
|
|
324
|
-
class
|
371
|
+
class BcfVariant < FFI::Struct
|
325
372
|
layout \
|
326
373
|
:type, :int,
|
327
374
|
:n, :int
|
328
375
|
end
|
329
376
|
|
330
|
-
class BcfHrec <
|
377
|
+
class BcfHrec < FFI::Struct
|
331
378
|
layout \
|
332
379
|
:type, :int,
|
333
380
|
:key, :string,
|
@@ -337,7 +384,7 @@ module HTS
|
|
337
384
|
:vals, :pointer
|
338
385
|
end
|
339
386
|
|
340
|
-
class BcfFmt <
|
387
|
+
class BcfFmt < FFI::BitStruct
|
341
388
|
layout \
|
342
389
|
:id, :int,
|
343
390
|
:n, :int,
|
@@ -345,10 +392,14 @@ module HTS
|
|
345
392
|
:type, :int,
|
346
393
|
:p, :pointer, # uint8_t
|
347
394
|
:p_len, :uint32,
|
348
|
-
:
|
395
|
+
:_p_off_free, :uint32 # bit_fields
|
396
|
+
|
397
|
+
bit_fields :_p_off_free,
|
398
|
+
:p_off, 31,
|
399
|
+
:p_free, 1
|
349
400
|
end
|
350
401
|
|
351
|
-
class BcfInfo <
|
402
|
+
class BcfInfo < FFI::BitStruct
|
352
403
|
layout \
|
353
404
|
:key, :int,
|
354
405
|
:type, :int,
|
@@ -359,41 +410,45 @@ module HTS
|
|
359
410
|
),
|
360
411
|
:vptr, :pointer,
|
361
412
|
:vptr_len, :uint32,
|
362
|
-
:
|
413
|
+
:_vptr_off_free, :uint32, # bit_fields
|
363
414
|
:len, :int
|
415
|
+
|
416
|
+
bit_fields :_vptr_off_free,
|
417
|
+
:vptr_off, 31,
|
418
|
+
:vptr_free, 1
|
364
419
|
end
|
365
420
|
|
366
|
-
class BcfIdinfo <
|
421
|
+
class BcfIdinfo < FFI::Struct
|
367
422
|
layout \
|
368
|
-
:info, [:
|
423
|
+
:info, [:uint64_t, 3],
|
369
424
|
:hrec, [BcfHrec.ptr, 3],
|
370
425
|
:id, :int
|
371
426
|
end
|
372
427
|
|
373
|
-
class BcfIdpair <
|
428
|
+
class BcfIdpair < FFI::Struct
|
374
429
|
layout \
|
375
430
|
:key, :string,
|
376
431
|
:val, BcfIdinfo.ptr
|
377
432
|
end
|
378
433
|
|
379
|
-
class BcfHdr <
|
434
|
+
class BcfHdr < FFI::Struct
|
380
435
|
layout \
|
381
436
|
:n, [:int, 3],
|
382
|
-
:id, [
|
437
|
+
:id, [:pointer, 3], # BcfIdpair.ptr
|
383
438
|
:dict, [:pointer, 3],
|
384
439
|
:samples, :pointer,
|
385
440
|
:hrec, :pointer,
|
386
441
|
:nhrec, :int,
|
387
442
|
:dirty, :int,
|
388
443
|
:ntransl, :int,
|
389
|
-
:transl, :pointer,
|
444
|
+
:transl, [:pointer, 2],
|
390
445
|
:nsamples_ori, :int,
|
391
446
|
:keep_samples, :pointer,
|
392
|
-
:mem,
|
447
|
+
:mem, KString,
|
393
448
|
:m, [:int, 3]
|
394
449
|
end
|
395
450
|
|
396
|
-
class BcfDec <
|
451
|
+
class BcfDec < FFI::Struct
|
397
452
|
layout \
|
398
453
|
:m_fmt, :int,
|
399
454
|
:m_info, :int,
|
@@ -401,34 +456,47 @@ module HTS
|
|
401
456
|
:m_als, :int,
|
402
457
|
:m_allele, :int,
|
403
458
|
:m_flt, :int,
|
459
|
+
:n_flt, :int,
|
404
460
|
:flt, :pointer,
|
405
461
|
:id, :string,
|
406
|
-
:als, :string
|
462
|
+
:als, :pointer, # (\\0-separated string)
|
407
463
|
:allele, :pointer,
|
408
|
-
:info, BcfInfo.ptr,
|
464
|
+
:info, :pointer, # BcfInfo.ptr,
|
409
465
|
:fmt, BcfFmt.ptr,
|
410
|
-
:var,
|
466
|
+
:var, BcfVariant.ptr,
|
411
467
|
:n_var, :int,
|
412
468
|
:var_type, :int,
|
413
469
|
:shared_dirty, :int,
|
414
470
|
:indiv_dirty, :int
|
415
471
|
end
|
416
472
|
|
417
|
-
class Bcf1 <
|
473
|
+
class Bcf1 < FFI::ManagedBitStruct
|
418
474
|
layout \
|
419
475
|
:pos, :hts_pos_t,
|
420
476
|
:rlen, :hts_pos_t,
|
421
|
-
:rid, :
|
477
|
+
:rid, :int32_t,
|
422
478
|
:qual, :float,
|
423
|
-
:
|
424
|
-
:
|
425
|
-
:shared,
|
426
|
-
:indiv,
|
479
|
+
:_n_info_allele, :uint32_t,
|
480
|
+
:_n_fmt_sample, :uint32_t,
|
481
|
+
:shared, KString,
|
482
|
+
:indiv, KString,
|
427
483
|
:d, BcfDec,
|
428
484
|
:max_unpack, :int,
|
429
485
|
:unpacked, :int,
|
430
486
|
:unpack_size, [:int, 3],
|
431
487
|
:errcode, :int
|
488
|
+
|
489
|
+
bit_fields :_n_info_allele,
|
490
|
+
:n_info, 16,
|
491
|
+
:n_allele, 16
|
492
|
+
|
493
|
+
bit_fields :_n_fmt_sample,
|
494
|
+
:n_fmt, 8,
|
495
|
+
:n_sample, 24
|
496
|
+
|
497
|
+
def self.release(ptr)
|
498
|
+
LibHTS.bcf_destroy(ptr) unless ptr.null?
|
499
|
+
end
|
432
500
|
end
|
433
501
|
end
|
434
502
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTS
|
4
|
-
module
|
4
|
+
module LibHTS
|
5
5
|
# Open the named file or URL as a stream
|
6
6
|
attach_function \
|
7
7
|
:hopen,
|
@@ -23,7 +23,7 @@ module HTS
|
|
23
23
|
# Append an extension or replace an existing extension
|
24
24
|
attach_function \
|
25
25
|
:haddextension,
|
26
|
-
[
|
26
|
+
[KString, :string, :int, :string],
|
27
27
|
:string
|
28
28
|
|
29
29
|
# Flush (for output streams) and close the stream
|
@@ -1,14 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module HTS
|
4
|
-
module
|
4
|
+
module LibHTS
|
5
5
|
# hts_expand
|
6
6
|
# hts_expand3
|
7
7
|
# hts_resize
|
8
8
|
|
9
|
+
# hts_log.h
|
10
|
+
attach_function \
|
11
|
+
:hts_get_log_level,
|
12
|
+
[],
|
13
|
+
HtsLogLevel
|
14
|
+
|
9
15
|
attach_function \
|
10
16
|
:hts_lib_shutdown,
|
11
|
-
[
|
17
|
+
[],
|
12
18
|
:void
|
13
19
|
|
14
20
|
attach_function \
|
@@ -110,7 +116,7 @@ module HTS
|
|
110
116
|
# Read a line (and its \n or \r\n terminator) from a file
|
111
117
|
attach_function \
|
112
118
|
:hts_getline,
|
113
|
-
[HtsFile, :int,
|
119
|
+
[HtsFile, :int, KString],
|
114
120
|
:int
|
115
121
|
|
116
122
|
attach_function \
|