htslib 0.1.0 → 0.2.2

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.
@@ -1,240 +1,466 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "vcf_funcs"
4
-
5
3
  module HTS
6
4
  module LibHTS
7
- # constants
8
- BCF_HL_FLT = 0 # header line
9
- BCF_HL_INFO = 1
10
- BCF_HL_FMT = 2
11
- BCF_HL_CTG = 3
12
- BCF_HL_STR = 4 # structured header line TAG=<A=..,B=..>
13
- BCF_HL_GEN = 5 # generic header line
14
-
15
- BCF_HT_FLAG = 0 # header type
16
- BCF_HT_INT = 1
17
- BCF_HT_REAL = 2
18
- BCF_HT_STR = 3
19
- BCF_HT_LONG = (BCF_HT_INT | 0x100) # BCF_HT_INT, but for int64_t values; VCF only!
20
-
21
- BCF_VL_FIXED = 0 # variable length
22
- BCF_VL_VAR = 1
23
- BCF_VL_A = 2
24
- BCF_VL_G = 3
25
- BCF_VL_R = 4
26
-
27
- BCF_DT_ID = 0 # dictionary type
28
- BCF_DT_CTG = 1
29
- BCF_DT_SAMPLE = 2
30
-
31
- BCF_BT_NULL = 0
32
- BCF_BT_INT8 = 1
33
- BCF_BT_INT16 = 2
34
- BCF_BT_INT32 = 3
35
- BCF_BT_INT64 = 4 # Unofficial, for internal use only.
36
- BCF_BT_FLOAT = 5
37
- BCF_BT_CHAR = 7
38
-
39
- VCF_REF = 0
40
- VCF_SNP = 1
41
- VCF_MNP = 2
42
- VCF_INDEL = 4
43
- VCF_OTHER = 8
44
- VCF_BND = 16 # breakend
45
- VCF_OVERLAP = 32 # overlapping deletion, ALT=*
46
-
47
- BCF1_DIRTY_ID = 1
48
- BCF1_DIRTY_ALS = 2
49
- BCF1_DIRTY_FLT = 4
50
- BCF1_DIRTY_INF = 8
51
-
52
- BCF_ERR_CTG_UNDEF = 1
53
- BCF_ERR_TAG_UNDEF = 2
54
- BCF_ERR_NCOLS = 4
55
- BCF_ERR_LIMITS = 8
56
- BCF_ERR_CHAR = 16
57
- BCF_ERR_CTG_INVALID = 32
58
- BCF_ERR_TAG_INVALID = 64
59
-
60
- # macros
61
- class << self
62
- alias bcf_init1 bcf_init
63
- alias bcf_read1 bcf_read
64
- alias vcf_read1 vcf_read
65
- alias bcf_write1 bcf_write
66
- alias vcf_write1 vcf_write
67
- alias bcf_destroy1 bcf_destroy
68
- alias bcf_empty1 bcf_empty
69
- alias vcf_parse1 vcf_parse
70
- alias bcf_clear1 bcf_clear
71
- alias vcf_format1 vcf_format
72
-
73
- alias bcf_open hts_open
74
- alias vcf_open hts_open
75
- if respond_to?(:hts_flush)
76
- alias bcf_flush hts_flush
77
- alias vcf_flush hts_flush
78
- end
79
- alias bcf_close hts_close
80
- alias vcf_close hts_close
81
- end
82
-
83
- BCF_UN_STR = 1 # up to ALT inclusive
84
- BCF_UN_FLT = 2 # up to FILTER
85
- BCF_UN_INFO = 4 # up to INFO
86
- BCF_UN_SHR = (BCF_UN_STR | BCF_UN_FLT | BCF_UN_INFO) # all shared information
87
- BCF_UN_FMT = 8 # unpack format and each sample
88
- BCF_UN_IND = BCF_UN_FMT # a synonym of BCF_UN_FMT
89
- BCF_UN_ALL = (BCF_UN_SHR | BCF_UN_FMT) # everything
90
-
91
- class << self
92
- def bcf_hdr_nsamples(hdr)
93
- hdr[:n][BCF_DT_SAMPLE]
94
- end
95
-
96
- def bcf_update_info_int32(hdr, line, key, values, n)
97
- bcf_update_info(hdr, line, key, values, n, BCF_HT_INT)
98
- end
99
-
100
- def bcf_update_info_float(hdr, line, key, values, n)
101
- bcf_update_info(hdr, line, key, values, n, BCF_HT_REAL)
102
- end
103
-
104
- def bcf_update_info_flag(hdr, line, key, string, n)
105
- bcf_update_info(hdr, line, key, string, n, BCF_HT_FLAG)
106
- end
107
-
108
- def bcf_update_info_string(hdr, line, key, string)
109
- bcf_update_info(hdr, line, key, string, 1, BCF_HT_STR)
110
- end
111
-
112
- def bcf_update_format_int32(hdr, line, key, values, n)
113
- bcf_update_format(hdr, line, key, values, n,
114
- BCF_HT_INT)
115
- end
116
-
117
- def bcf_update_format_float(hdr, line, key, values, n)
118
- bcf_update_format(hdr, line, key, values, n,
119
- BCF_HT_REAL)
120
- end
121
-
122
- def bcf_update_format_char(hdr, line, key, values, n)
123
- bcf_update_format(hdr, line, key, values, n,
124
- BCF_HT_STR)
125
- end
126
-
127
- def bcf_update_genotypes(hdr, line, gts, n)
128
- bcf_update_format(hdr, line, "GT", gts, n, BCF_HT_INT)
129
- end
130
-
131
- def bcf_gt_phased(idx)
132
- ((idx + 1) << 1 | 1)
133
- end
134
-
135
- def bcf_gt_unphased(idx)
136
- ((idx + 1) << 1)
137
- end
138
-
139
- def bcf_gt_missing
140
- 0
141
- end
142
-
143
- def bcf_gt_is_missing(val)
144
- ((val) >> 1 ? 0 : 1)
145
- end
146
-
147
- def bcf_gt_is_phased(idx)
148
- ((idx) & 1)
149
- end
150
-
151
- def bcf_gt_allele(val)
152
- (((val) >> 1) - 1)
153
- end
154
-
155
- def bcf_alleles2gt(a, b)
156
- ((a) > (b) ? (a * (a + 1) / 2 + b) : (b * (b + 1) / 2 + a))
157
- end
158
-
159
- def bcf_get_info_int32(hdr, line, tag, dst, ndst)
160
- bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_INT)
161
- end
162
-
163
- def bcf_get_info_float(hdr, line, tag, dst, ndst)
164
- bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_REAL)
165
- end
166
-
167
- def bcf_get_info_string(hdr, line, tag, dst, ndst)
168
- bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_STR)
169
- end
170
-
171
- def bcf_get_info_flag(hdr, line, tag, dst, ndst)
172
- bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_FLAG)
173
- end
174
-
175
- def bcf_get_format_int32(hdr, line, tag, dst, ndst)
176
- bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_INT)
177
- end
178
-
179
- def bcf_get_format_float(hdr, line, tag, dst, ndst)
180
- bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_REAL)
181
- end
182
-
183
- def bcf_get_format_char(hdr, line, tag, dst, ndst)
184
- bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_STR)
185
- end
186
-
187
- def bcf_get_genotypes(hdr, line, dst, ndst)
188
- bcf_get_format_values(hdr, line, "GT", dst, ndst, BCF_HT_INT)
189
- end
190
-
191
- def bcf_hdr_int2id(hdr, type, int_id)
192
- LibHTS::BcfIdpair.new(
193
- hdr[:id][type].to_ptr +
194
- LibHTS::BcfIdpair.size * int_id # offsets
195
- )[:key]
196
- end
197
-
198
- def bcf_hdr_name2id(hdr, id)
199
- bcf_hdr_id2int(hdr, BCF_DT_CTG, id)
200
- end
201
-
202
- def bcf_hdr_id2name(hdr, rid)
203
- return nil if hdr.null? || rid < 0 || rid >= hdr[:n][LibHTS::BCF_DT_CTG]
204
-
205
- LibHTS::BcfIdpair.new(
206
- hdr[:id][LibHTS::BCF_DT_CTG].to_ptr +
207
- LibHTS::BcfIdpair.size * rid # offset
208
- )[:key]
209
- end
210
-
211
- def bcf_hdr_id2length(hdr, type, int_id)
212
- LibHTS::BcfIdpair.new(
213
- hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
214
- LibHTS::BcfIdpair.size * int_id # offset
215
- )[:val][:info][type] >> 8 & 0xf
216
- end
217
-
218
- def bcf_hdr_id2number(hdr, type, int_id)
219
- LibHTS::BcfIdpair.new(
220
- hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
221
- LibHTS::BcfIdpair.size * int_id # offset
222
- )[:val][:info][type] >> 12
223
- end
224
-
225
- def bcf_hdr_id2type(hdr, type, int_id)
226
- LibHTS::BcfIdpair.new(
227
- hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
228
- LibHTS::BcfIdpair.size * int_id # offset
229
- )[:val][:info][type] >> 4 & 0xf
230
- end
231
-
232
- def bcf_hdr_id2coltype(hdr, type, int_id)
233
- LibHTS::BcfIdpair.new(
234
- hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
235
- LibHTS::BcfIdpair.size * int_id # offset
236
- )[:val][:info][type] & 0xf
237
- end
238
- end
5
+ attach_function \
6
+ :bcf_hdr_init,
7
+ [:string],
8
+ BcfHdr.by_ref
9
+
10
+ attach_function \
11
+ :bcf_hdr_destroy,
12
+ [BcfHdr],
13
+ :void
14
+
15
+ attach_function \
16
+ :bcf_init,
17
+ [],
18
+ Bcf1.by_ref
19
+
20
+ attach_function \
21
+ :bcf_destroy,
22
+ [Bcf1],
23
+ :void
24
+
25
+ attach_function \
26
+ :bcf_empty,
27
+ [Bcf1],
28
+ :void
29
+
30
+ attach_function \
31
+ :bcf_clear,
32
+ [Bcf1],
33
+ :void
34
+
35
+ attach_function \
36
+ :bcf_hdr_read,
37
+ [HtsFile],
38
+ BcfHdr.by_ref
39
+
40
+ attach_function \
41
+ :bcf_hdr_set_samples,
42
+ [BcfHdr, :string, :int],
43
+ :int
44
+
45
+ attach_function \
46
+ :bcf_subset_format,
47
+ [BcfHdr, Bcf1],
48
+ :int
49
+
50
+ attach_function \
51
+ :bcf_hdr_write,
52
+ [HtsFile, BcfHdr],
53
+ :int
54
+
55
+ attach_function \
56
+ :vcf_parse,
57
+ [KString, BcfHdr, Bcf1],
58
+ :int
59
+
60
+ attach_function \
61
+ :vcf_open_mode,
62
+ %i[string string string],
63
+ :int
64
+
65
+ attach_function \
66
+ :vcf_format,
67
+ [BcfHdr, Bcf1, KString],
68
+ :int
69
+
70
+ attach_function \
71
+ :bcf_read,
72
+ [HtsFile, BcfHdr, Bcf1],
73
+ :int
74
+
75
+ attach_function \
76
+ :bcf_unpack,
77
+ [Bcf1, :int],
78
+ :int
79
+
80
+ attach_function \
81
+ :bcf_dup,
82
+ [Bcf1],
83
+ Bcf1.by_ref
84
+
85
+ attach_function \
86
+ :bcf_copy,
87
+ [Bcf1, Bcf1],
88
+ Bcf1.by_ref
89
+
90
+ attach_function \
91
+ :bcf_write,
92
+ [HtsFile, BcfHdr, Bcf1],
93
+ :int
94
+
95
+ attach_function \
96
+ :vcf_hdr_read,
97
+ [HtsFile],
98
+ BcfHdr.by_ref
99
+
100
+ attach_function \
101
+ :vcf_hdr_write,
102
+ [HtsFile, BcfHdr],
103
+ :int
104
+
105
+ attach_function \
106
+ :vcf_read,
107
+ [HtsFile, BcfHdr, Bcf1],
108
+ :int
109
+
110
+ attach_function \
111
+ :vcf_write,
112
+ [HtsFile, BcfHdr, Bcf1],
113
+ :int
114
+
115
+ attach_function \
116
+ :bcf_readrec,
117
+ [BGZF, :pointer, :pointer, :pointer, :hts_pos_t, :hts_pos_t],
118
+ :int
119
+
120
+ attach_function \
121
+ :vcf_write_line,
122
+ [HtsFile, KString],
123
+ :int
124
+
125
+ attach_function \
126
+ :bcf_hdr_dup,
127
+ [BcfHdr],
128
+ BcfHdr.by_ref
129
+
130
+ # DEPRECATED
131
+ #
132
+ # attach_function \
133
+ # :bcf_hdr_combine,
134
+ # [BcfHdr, BcfHdr],
135
+ # :int
136
+
137
+ attach_function \
138
+ :bcf_hdr_merge,
139
+ [BcfHdr, BcfHdr],
140
+ BcfHdr.by_ref
141
+
142
+ attach_function \
143
+ :bcf_hdr_add_sample,
144
+ [BcfHdr, :string],
145
+ :int
146
+
147
+ attach_function \
148
+ :bcf_hdr_set,
149
+ [BcfHdr, :string],
150
+ :int
151
+
152
+ attach_function \
153
+ :bcf_hdr_format,
154
+ [BcfHdr, :int, KString],
155
+ :int
156
+
157
+ # DEPRECATED
158
+ #
159
+ # attach_function \
160
+ # :bcf_hdr_fmt_text,
161
+ # [BcfHdr, :int, :pointer],
162
+ # :string
163
+
164
+ attach_function \
165
+ :bcf_hdr_append,
166
+ [BcfHdr, :string],
167
+ :int
168
+
169
+ attach_function \
170
+ :bcf_hdr_printf,
171
+ [BcfHdr, :string, :varargs],
172
+ :int
173
+
174
+ attach_function \
175
+ :bcf_hdr_get_version,
176
+ [BcfHdr],
177
+ :string
178
+
179
+ attach_function \
180
+ :bcf_hdr_set_version,
181
+ [BcfHdr, :string],
182
+ :int
183
+
184
+ attach_function \
185
+ :bcf_hdr_remove,
186
+ [BcfHdr, :int, :string],
187
+ :void
188
+
189
+ attach_function \
190
+ :bcf_hdr_subset,
191
+ [BcfHdr, :int, :pointer, :pointer],
192
+ BcfHdr.by_ref
193
+
194
+ attach_function \
195
+ :bcf_hdr_seqnames,
196
+ [BcfHdr, :pointer],
197
+ :pointer
198
+
199
+ attach_function \
200
+ :bcf_hdr_parse,
201
+ [BcfHdr, :string],
202
+ :int
203
+
204
+ attach_function \
205
+ :bcf_hdr_sync,
206
+ [BcfHdr],
207
+ :int
208
+
209
+ attach_function \
210
+ :bcf_hdr_parse_line,
211
+ [BcfHdr, :string, :pointer],
212
+ BcfHrec.by_ref
213
+
214
+ attach_function \
215
+ :bcf_hrec_format,
216
+ [BcfHrec, KString],
217
+ :int
218
+
219
+ attach_function \
220
+ :bcf_hdr_add_hrec,
221
+ [BcfHdr, BcfHrec],
222
+ :int
223
+
224
+ attach_function \
225
+ :bcf_hdr_get_hrec,
226
+ [BcfHdr, :int, :string, :string, :string],
227
+ BcfHrec.by_ref
228
+
229
+ attach_function \
230
+ :bcf_hrec_dup,
231
+ [BcfHrec],
232
+ BcfHrec.by_ref
233
+
234
+ attach_function \
235
+ :bcf_hrec_add_key,
236
+ [BcfHrec, :string, :size_t],
237
+ :int
238
+
239
+ attach_function \
240
+ :bcf_hrec_set_val,
241
+ [BcfHrec, :int, :string, :size_t, :int],
242
+ :int
243
+
244
+ attach_function \
245
+ :bcf_hrec_find_key,
246
+ [BcfHrec, :string],
247
+ :int
248
+
249
+ attach_function \
250
+ :hrec_add_idx,
251
+ [BcfHrec, :int],
252
+ :int
253
+
254
+ attach_function \
255
+ :bcf_hrec_destroy,
256
+ [BcfHrec],
257
+ :void
258
+
259
+ attach_function \
260
+ :bcf_subset,
261
+ [BcfHdr, Bcf1, :int, :pointer],
262
+ :int
263
+
264
+ attach_function \
265
+ :bcf_translate,
266
+ [BcfHdr, BcfHdr, Bcf1],
267
+ :int
268
+
269
+ attach_function \
270
+ :bcf_get_variant_types,
271
+ [Bcf1],
272
+ :int
273
+
274
+ attach_function \
275
+ :bcf_get_variant_type,
276
+ [Bcf1, :int],
277
+ :int
278
+
279
+ attach_function \
280
+ :bcf_has_variant_types,
281
+ [Bcf1, :uint32, :int],
282
+ :int
283
+
284
+ attach_function \
285
+ :bcf_has_variant_type,
286
+ [Bcf1, :int, :uint32],
287
+ :int
288
+
289
+ attach_function \
290
+ :bcf_variant_length,
291
+ [Bcf1, :int],
292
+ :int
293
+
294
+ attach_function \
295
+ :bcf_is_snp,
296
+ [Bcf1],
297
+ :int
298
+
299
+ attach_function \
300
+ :bcf_update_filter,
301
+ [BcfHdr, Bcf1, :pointer, :int],
302
+ :int
303
+
304
+ attach_function \
305
+ :bcf_add_filter,
306
+ [BcfHdr, Bcf1, :int],
307
+ :int
308
+
309
+ attach_function \
310
+ :bcf_remove_filter,
311
+ [BcfHdr, Bcf1, :int, :int],
312
+ :int
313
+
314
+ attach_function \
315
+ :bcf_has_filter,
316
+ [BcfHdr, Bcf1, :string],
317
+ :int
318
+
319
+ attach_function \
320
+ :bcf_update_alleles,
321
+ [BcfHdr, Bcf1, :pointer, :int],
322
+ :int
323
+
324
+ attach_function \
325
+ :bcf_update_alleles_str,
326
+ [BcfHdr, Bcf1, :string],
327
+ :int
328
+
329
+ attach_function \
330
+ :bcf_update_id,
331
+ [BcfHdr, Bcf1, :string],
332
+ :int
333
+
334
+ attach_function \
335
+ :bcf_add_id,
336
+ [BcfHdr, Bcf1, :string],
337
+ :int
338
+
339
+ attach_function \
340
+ :bcf_update_info,
341
+ [BcfHdr, Bcf1, :string, :pointer, :int, :int],
342
+ :int
343
+
344
+ attach_function \
345
+ :bcf_update_format_string,
346
+ [BcfHdr, Bcf1, :string, :pointer, :int],
347
+ :int
348
+
349
+ attach_function \
350
+ :bcf_update_format,
351
+ [BcfHdr, Bcf1, :string, :pointer, :int, :int],
352
+ :int
353
+
354
+ attach_function \
355
+ :bcf_get_fmt,
356
+ [BcfHdr, Bcf1, :string],
357
+ BcfFmt.by_ref
358
+
359
+ attach_function \
360
+ :bcf_get_info,
361
+ [BcfHdr, Bcf1, :string],
362
+ BcfInfo.by_ref
363
+
364
+ attach_function \
365
+ :bcf_get_fmt_id,
366
+ [Bcf1, :int],
367
+ BcfFmt.by_ref
368
+
369
+ attach_function \
370
+ :bcf_get_info_id,
371
+ [Bcf1, :int],
372
+ BcfInfo.by_ref
373
+
374
+ attach_function \
375
+ :bcf_get_info_values,
376
+ [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
377
+ :int
378
+
379
+ attach_function \
380
+ :bcf_get_format_string,
381
+ [BcfHdr, Bcf1, :string, :pointer, :pointer],
382
+ :int
383
+
384
+ attach_function \
385
+ :bcf_get_format_values,
386
+ [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
387
+ :int
388
+
389
+ attach_function \
390
+ :bcf_hdr_id2int,
391
+ [BcfHdr, :int, :string],
392
+ :int
393
+
394
+ attach_function \
395
+ :bcf_fmt_array,
396
+ [KString, :int, :int, :pointer],
397
+ :int
398
+
399
+ attach_function \
400
+ :bcf_fmt_sized_array,
401
+ [KString, :pointer],
402
+ :uint8_t
403
+
404
+ attach_function \
405
+ :bcf_enc_vchar,
406
+ [KString, :int, :string],
407
+ :int
408
+
409
+ attach_function \
410
+ :bcf_enc_vint,
411
+ [KString, :int, :pointer, :int],
412
+ :int
413
+
414
+ attach_function \
415
+ :bcf_enc_vfloat,
416
+ [KString, :int, :pointer],
417
+ :int
418
+
419
+ attach_function \
420
+ :bcf_index_load2,
421
+ %i[string string],
422
+ HtsIdx.by_ref
423
+
424
+ attach_function \
425
+ :bcf_index_load3,
426
+ %i[string string int],
427
+ HtsIdx.by_ref
428
+
429
+ attach_function \
430
+ :bcf_index_build,
431
+ %i[string int],
432
+ :int
433
+
434
+ attach_function \
435
+ :bcf_index_build2,
436
+ %i[string string int],
437
+ :int
438
+
439
+ attach_function \
440
+ :bcf_index_build3,
441
+ %i[string string int int],
442
+ :int
443
+
444
+ attach_function \
445
+ :bcf_idx_init,
446
+ [HtsFile, BcfHdr, :int, :string],
447
+ :int
448
+
449
+ attach_function \
450
+ :bcf_idx_save,
451
+ [HtsFile],
452
+ :int
453
+
454
+ attach_function \
455
+ :bcf_float_vector_end,
456
+ [],
457
+ :uint32
458
+
459
+ attach_function \
460
+ :bcf_float_missing,
461
+ [],
462
+ :uint32
239
463
  end
240
464
  end
465
+
466
+ require_relative "vcf_funcs"