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.
@@ -1,226 +1,439 @@
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
- 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
+ attach_function \
158
+ :bcf_hdr_fmt_text,
159
+ [BcfHdr, :int, :pointer],
160
+ :string
161
+
162
+ attach_function \
163
+ :bcf_hdr_append,
164
+ [BcfHdr, :string],
165
+ :int
166
+
167
+ attach_function \
168
+ :bcf_hdr_printf,
169
+ [BcfHdr, :string, :varargs],
170
+ :int
171
+
172
+ attach_function \
173
+ :bcf_hdr_get_version,
174
+ [BcfHdr],
175
+ :string
176
+
177
+ attach_function \
178
+ :bcf_hdr_set_version,
179
+ [BcfHdr, :string],
180
+ :int
181
+
182
+ attach_function \
183
+ :bcf_hdr_remove,
184
+ [BcfHdr, :int, :string],
185
+ :void
186
+
187
+ attach_function \
188
+ :bcf_hdr_subset,
189
+ [BcfHdr, :int, :pointer, :pointer],
190
+ BcfHdr.by_ref
191
+
192
+ attach_function \
193
+ :bcf_hdr_seqnames,
194
+ [BcfHdr, :pointer],
195
+ :pointer
196
+
197
+ attach_function \
198
+ :bcf_hdr_parse,
199
+ [BcfHdr, :string],
200
+ :int
201
+
202
+ attach_function \
203
+ :bcf_hdr_sync,
204
+ [BcfHdr],
205
+ :int
206
+
207
+ attach_function \
208
+ :bcf_hdr_parse_line,
209
+ [BcfHdr, :string, :pointer],
210
+ BcfHrec.by_ref
211
+
212
+ attach_function \
213
+ :bcf_hrec_format,
214
+ [BcfHrec, KString],
215
+ :int
216
+
217
+ attach_function \
218
+ :bcf_hdr_add_hrec,
219
+ [BcfHdr, BcfHrec],
220
+ :int
221
+
222
+ attach_function \
223
+ :bcf_hdr_get_hrec,
224
+ [BcfHdr, :int, :string, :string, :string],
225
+ BcfHrec.by_ref
226
+
227
+ attach_function \
228
+ :bcf_hrec_dup,
229
+ [BcfHrec],
230
+ BcfHrec.by_ref
231
+
232
+ attach_function \
233
+ :bcf_hrec_add_key,
234
+ [BcfHrec, :string, :size_t],
235
+ :int
236
+
237
+ attach_function \
238
+ :bcf_hrec_set_val,
239
+ [BcfHrec, :int, :string, :size_t, :int],
240
+ :int
241
+
242
+ attach_function \
243
+ :bcf_hrec_find_key,
244
+ [BcfHrec, :string],
245
+ :int
246
+
247
+ attach_function \
248
+ :hrec_add_idx,
249
+ [BcfHrec, :int],
250
+ :int
251
+
252
+ attach_function \
253
+ :bcf_hrec_destroy,
254
+ [BcfHrec],
255
+ :void
256
+
257
+ attach_function \
258
+ :bcf_subset,
259
+ [BcfHdr, Bcf1, :int, :pointer],
260
+ :int
261
+
262
+ attach_function \
263
+ :bcf_translate,
264
+ [BcfHdr, BcfHdr, Bcf1],
265
+ :int
266
+
267
+ attach_function \
268
+ :bcf_get_variant_types,
269
+ [Bcf1],
270
+ :int
271
+
272
+ attach_function \
273
+ :bcf_get_variant_type,
274
+ [Bcf1, :int],
275
+ :int
276
+
277
+ attach_function \
278
+ :bcf_is_snp,
279
+ [Bcf1],
280
+ :int
281
+
282
+ attach_function \
283
+ :bcf_update_filter,
284
+ [BcfHdr, Bcf1, :pointer, :int],
285
+ :int
286
+
287
+ attach_function \
288
+ :bcf_add_filter,
289
+ [BcfHdr, Bcf1, :int],
290
+ :int
291
+
292
+ attach_function \
293
+ :bcf_remove_filter,
294
+ [BcfHdr, Bcf1, :int, :int],
295
+ :int
296
+
297
+ attach_function \
298
+ :bcf_has_filter,
299
+ [BcfHdr, Bcf1, :string],
300
+ :int
301
+
302
+ attach_function \
303
+ :bcf_update_alleles,
304
+ [BcfHdr, Bcf1, :pointer, :int],
305
+ :int
306
+
307
+ attach_function \
308
+ :bcf_update_alleles_str,
309
+ [BcfHdr, Bcf1, :string],
310
+ :int
311
+
312
+ attach_function \
313
+ :bcf_update_id,
314
+ [BcfHdr, Bcf1, :string],
315
+ :int
316
+
317
+ attach_function \
318
+ :bcf_add_id,
319
+ [BcfHdr, Bcf1, :string],
320
+ :int
321
+
322
+ attach_function \
323
+ :bcf_update_info,
324
+ [BcfHdr, Bcf1, :string, :pointer, :int, :int],
325
+ :int
326
+
327
+ attach_function \
328
+ :bcf_update_format_string,
329
+ [BcfHdr, Bcf1, :string, :pointer, :int],
330
+ :int
331
+
332
+ attach_function \
333
+ :bcf_update_format,
334
+ [BcfHdr, Bcf1, :string, :pointer, :int, :int],
335
+ :int
336
+
337
+ attach_function \
338
+ :bcf_get_fmt,
339
+ [BcfHdr, Bcf1, :string],
340
+ BcfFmt.by_ref
341
+
342
+ attach_function \
343
+ :bcf_get_info,
344
+ [BcfHdr, Bcf1, :string],
345
+ BcfInfo.by_ref
346
+
347
+ attach_function \
348
+ :bcf_get_fmt_id,
349
+ [Bcf1, :int],
350
+ BcfFmt.by_ref
351
+
352
+ attach_function \
353
+ :bcf_get_info_id,
354
+ [Bcf1, :int],
355
+ BcfInfo.by_ref
356
+
357
+ attach_function \
358
+ :bcf_get_info_values,
359
+ [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
360
+ :int
361
+
362
+ attach_function \
363
+ :bcf_get_format_string,
364
+ [BcfHdr, Bcf1, :string, :pointer, :pointer],
365
+ :int
366
+
367
+ attach_function \
368
+ :bcf_get_format_values,
369
+ [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
370
+ :int
371
+
372
+ attach_function \
373
+ :bcf_hdr_id2int,
374
+ [BcfHdr, :int, :string],
375
+ :int
376
+
377
+ attach_function \
378
+ :bcf_fmt_array,
379
+ [KString, :int, :int, :pointer],
380
+ :int
381
+
382
+ attach_function \
383
+ :bcf_fmt_sized_array,
384
+ [KString, :pointer],
385
+ :uint8_t
386
+
387
+ attach_function \
388
+ :bcf_enc_vchar,
389
+ [KString, :int, :string],
390
+ :int
391
+
392
+ attach_function \
393
+ :bcf_enc_vint,
394
+ [KString, :int, :pointer, :int],
395
+ :int
396
+
397
+ attach_function \
398
+ :bcf_enc_vfloat,
399
+ [KString, :int, :pointer],
400
+ :int
401
+
402
+ attach_function \
403
+ :bcf_index_load2,
404
+ %i[string string],
405
+ HtsIdx.by_ref
406
+
407
+ attach_function \
408
+ :bcf_index_load3,
409
+ %i[string string int],
410
+ HtsIdx.by_ref
411
+
412
+ attach_function \
413
+ :bcf_index_build,
414
+ %i[string int],
415
+ :int
416
+
417
+ attach_function \
418
+ :bcf_index_build2,
419
+ %i[string string int],
420
+ :int
421
+
422
+ attach_function \
423
+ :bcf_index_build3,
424
+ %i[string string int int],
425
+ :int
426
+
427
+ attach_function \
428
+ :bcf_idx_init,
429
+ [HtsFile, BcfHdr, :int, :string],
430
+ :int
431
+
432
+ attach_function \
433
+ :bcf_idx_save,
434
+ [HtsFile],
435
+ :int
225
436
  end
226
437
  end
438
+
439
+ require_relative "vcf_funcs"