htslib 0.0.4 → 0.0.8

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,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "vcf_funcs"
4
+
3
5
  module HTS
4
6
  module LibHTS
5
7
  # constants
@@ -9,8 +11,8 @@ module HTS
9
11
  BCF_HL_CTG = 3
10
12
  BCF_HL_STR = 4 # structured header line TAG=<A=..,B=..>
11
13
  BCF_HL_GEN = 5 # generic header line
12
- BCF_HT_FLAG = 0 # header type
13
14
 
15
+ BCF_HT_FLAG = 0 # header type
14
16
  BCF_HT_INT = 1
15
17
  BCF_HT_REAL = 2
16
18
  BCF_HT_STR = 3
@@ -57,11 +59,36 @@ module HTS
57
59
 
58
60
  # macros
59
61
  class << self
60
- alias bcf_open hts_open
61
- alias vcf_open hts_open
62
- alias bcf_close hts_close
63
- alias vcf_close hts_close
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
64
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
65
92
  def bcf_hdr_nsamples(hdr)
66
93
  hdr[:n][BCF_DT_SAMPLE]
67
94
  end
@@ -167,440 +194,33 @@ module HTS
167
194
  LibHTS::BcfIdpair.size * int_id # offsets
168
195
  )[:key]
169
196
  end
170
- end
171
197
 
172
- # constants
173
- BCF_UN_STR = 1 # up to ALT inclusive
174
- BCF_UN_FLT = 2 # up to FILTER
175
- BCF_UN_INFO = 4 # up to INFO
176
- BCF_UN_SHR = (BCF_UN_STR | BCF_UN_FLT | BCF_UN_INFO) # all shared information
177
- BCF_UN_FMT = 8 # unpack format and each sample
178
- BCF_UN_IND = BCF_UN_FMT # a synonym of BCF_UN_FMT
179
- BCF_UN_ALL = (BCF_UN_SHR | BCF_UN_FMT) # everything
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]
180
204
 
181
- attach_function \
182
- :bcf_hdr_init,
183
- [:string],
184
- BcfHdr.by_ref
185
-
186
- attach_function \
187
- :bcf_hdr_destroy,
188
- [BcfHdr],
189
- :void
190
-
191
- attach_function \
192
- :bcf_init,
193
- [],
194
- Bcf1.by_ref
195
-
196
- attach_function \
197
- :bcf_destroy,
198
- [Bcf1],
199
- :void
200
-
201
- attach_function \
202
- :bcf_empty,
203
- [Bcf1],
204
- :void
205
-
206
- attach_function \
207
- :bcf_clear,
208
- [Bcf1],
209
- :void
210
-
211
- attach_function \
212
- :bcf_hdr_read,
213
- [HtsFile],
214
- BcfHdr.by_ref
215
-
216
- attach_function \
217
- :bcf_hdr_set_samples,
218
- [BcfHdr, :string, :int],
219
- :int
220
-
221
- attach_function \
222
- :bcf_subset_format,
223
- [BcfHdr, Bcf1],
224
- :int
225
-
226
- attach_function \
227
- :bcf_hdr_write,
228
- [HtsFile, BcfHdr],
229
- :int
230
-
231
- attach_function \
232
- :vcf_parse,
233
- [KString, BcfHdr, Bcf1],
234
- :int
235
-
236
- attach_function \
237
- :vcf_open_mode,
238
- %i[string string string],
239
- :int
240
-
241
- attach_function \
242
- :vcf_format,
243
- [BcfHdr, Bcf1, KString],
244
- :int
245
-
246
- attach_function \
247
- :bcf_read,
248
- [HtsFile, BcfHdr, Bcf1],
249
- :int
250
-
251
- attach_function \
252
- :bcf_unpack,
253
- [Bcf1, :int],
254
- :int
255
-
256
- attach_function \
257
- :bcf_dup,
258
- [Bcf1],
259
- Bcf1.by_ref
260
-
261
- attach_function \
262
- :bcf_copy,
263
- [Bcf1, Bcf1],
264
- Bcf1.by_ref
265
-
266
- attach_function \
267
- :bcf_write,
268
- [HtsFile, BcfHdr, Bcf1],
269
- :int
270
-
271
- attach_function \
272
- :vcf_hdr_read,
273
- [HtsFile],
274
- BcfHdr.by_ref
275
-
276
- attach_function \
277
- :vcf_hdr_write,
278
- [HtsFile, BcfHdr],
279
- :int
280
-
281
- attach_function \
282
- :vcf_read,
283
- [HtsFile, BcfHdr, Bcf1],
284
- :int
285
-
286
- attach_function \
287
- :vcf_write,
288
- [HtsFile, BcfHdr, Bcf1],
289
- :int
290
-
291
- attach_function \
292
- :bcf_readrec,
293
- [BGZF, :pointer, :pointer, :pointer, :hts_pos_t, :hts_pos_t],
294
- :int
295
-
296
- attach_function \
297
- :vcf_write_line,
298
- [HtsFile, KString],
299
- :int
300
-
301
- attach_function \
302
- :bcf_hdr_dup,
303
- [BcfHdr],
304
- BcfHdr.by_ref
305
-
306
- attach_function \
307
- :bcf_hdr_merge,
308
- [BcfHdr, BcfHdr],
309
- BcfHdr.by_ref
310
-
311
- attach_function \
312
- :bcf_hdr_add_sample,
313
- [BcfHdr, :string],
314
- :int
315
-
316
- attach_function \
317
- :bcf_hdr_set,
318
- [BcfHdr, :string],
319
- :int
320
-
321
- attach_function \
322
- :bcf_hdr_format,
323
- [BcfHdr, :int, KString],
324
- :int
325
-
326
- attach_function \
327
- :bcf_hdr_fmt_text,
328
- [BcfHdr, :int, :pointer],
329
- :string
330
-
331
- attach_function \
332
- :bcf_hdr_append,
333
- [BcfHdr, :string],
334
- :int
335
-
336
- attach_function \
337
- :bcf_hdr_printf,
338
- [BcfHdr, :string, :varargs],
339
- :int
340
-
341
- attach_function \
342
- :bcf_hdr_get_version,
343
- [BcfHdr],
344
- :string
345
-
346
- attach_function \
347
- :bcf_hdr_set_version,
348
- [BcfHdr, :string],
349
- :int
350
-
351
- attach_function \
352
- :bcf_hdr_remove,
353
- [BcfHdr, :int, :string],
354
- :void
355
-
356
- attach_function \
357
- :bcf_hdr_subset,
358
- [BcfHdr, :int, :pointer, :pointer],
359
- BcfHdr.by_ref
360
-
361
- attach_function \
362
- :bcf_hdr_seqnames,
363
- [BcfHdr, :pointer],
364
- :pointer
365
-
366
- attach_function \
367
- :bcf_hdr_parse,
368
- [BcfHdr, :string],
369
- :int
370
-
371
- attach_function \
372
- :bcf_hdr_sync,
373
- [BcfHdr],
374
- :int
375
-
376
- attach_function \
377
- :bcf_hdr_parse_line,
378
- [BcfHdr, :string, :pointer],
379
- BcfHrec.by_ref
380
-
381
- attach_function \
382
- :bcf_hrec_format,
383
- [BcfHrec, KString],
384
- :int
385
-
386
- attach_function \
387
- :bcf_hdr_add_hrec,
388
- [BcfHdr, BcfHrec],
389
- :int
390
-
391
- attach_function \
392
- :bcf_hdr_get_hrec,
393
- [BcfHdr, :int, :string, :string, :string],
394
- BcfHrec.by_ref
395
-
396
- attach_function \
397
- :bcf_hrec_dup,
398
- [BcfHrec],
399
- BcfHrec.by_ref
400
-
401
- attach_function \
402
- :bcf_hrec_add_key,
403
- [BcfHrec, :string, :size_t],
404
- :int
405
-
406
- attach_function \
407
- :bcf_hrec_set_val,
408
- [BcfHrec, :int, :string, :size_t, :int],
409
- :int
410
-
411
- attach_function \
412
- :bcf_hrec_find_key,
413
- [BcfHrec, :string],
414
- :int
415
-
416
- attach_function \
417
- :hrec_add_idx,
418
- [BcfHrec, :int],
419
- :int
420
-
421
- attach_function \
422
- :bcf_hrec_destroy,
423
- [BcfHrec],
424
- :void
425
-
426
- attach_function \
427
- :bcf_subset,
428
- [BcfHdr, Bcf1, :int, :pointer],
429
- :int
430
-
431
- attach_function \
432
- :bcf_translate,
433
- [BcfHdr, BcfHdr, Bcf1],
434
- :int
435
-
436
- attach_function \
437
- :bcf_get_variant_types,
438
- [Bcf1],
439
- :int
440
-
441
- attach_function \
442
- :bcf_get_variant_type,
443
- [Bcf1, :int],
444
- :int
445
-
446
- attach_function \
447
- :bcf_is_snp,
448
- [Bcf1],
449
- :int
450
-
451
- attach_function \
452
- :bcf_update_filter,
453
- [BcfHdr, Bcf1, :pointer, :int],
454
- :int
455
-
456
- attach_function \
457
- :bcf_add_filter,
458
- [BcfHdr, Bcf1, :int],
459
- :int
460
-
461
- attach_function \
462
- :bcf_remove_filter,
463
- [BcfHdr, Bcf1, :int, :int],
464
- :int
465
-
466
- attach_function \
467
- :bcf_has_filter,
468
- [BcfHdr, Bcf1, :string],
469
- :int
470
-
471
- attach_function \
472
- :bcf_update_alleles,
473
- [BcfHdr, Bcf1, :pointer, :int],
474
- :int
475
-
476
- attach_function \
477
- :bcf_update_alleles_str,
478
- [BcfHdr, Bcf1, :string],
479
- :int
480
-
481
- attach_function \
482
- :bcf_update_id,
483
- [BcfHdr, Bcf1, :string],
484
- :int
485
-
486
- attach_function \
487
- :bcf_add_id,
488
- [BcfHdr, Bcf1, :string],
489
- :int
490
-
491
- attach_function \
492
- :bcf_update_info,
493
- [BcfHdr, Bcf1, :string, :pointer, :int, :int],
494
- :int
495
-
496
- attach_function \
497
- :bcf_update_format_string,
498
- [BcfHdr, Bcf1, :string, :pointer, :int],
499
- :int
500
-
501
- attach_function \
502
- :bcf_update_format,
503
- [BcfHdr, Bcf1, :string, :pointer, :int, :int],
504
- :int
505
-
506
- attach_function \
507
- :bcf_get_fmt,
508
- [BcfHdr, Bcf1, :string],
509
- BcfFmt.by_ref
510
-
511
- attach_function \
512
- :bcf_get_info,
513
- [BcfHdr, Bcf1, :string],
514
- BcfInfo.by_ref
515
-
516
- attach_function \
517
- :bcf_get_fmt_id,
518
- [Bcf1, :int],
519
- BcfFmt.by_ref
520
-
521
- attach_function \
522
- :bcf_get_info_id,
523
- [Bcf1, :int],
524
- BcfInfo.by_ref
525
-
526
- attach_function \
527
- :bcf_get_info_values,
528
- [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
529
- :int
530
-
531
- attach_function \
532
- :bcf_get_format_string,
533
- [BcfHdr, Bcf1, :string, :pointer, :pointer],
534
- :int
535
-
536
- attach_function \
537
- :bcf_get_format_values,
538
- [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
539
- :int
540
-
541
- attach_function \
542
- :bcf_hdr_id2int,
543
- [BcfHdr, :int, :string],
544
- :int
545
-
546
- attach_function \
547
- :bcf_fmt_array,
548
- [KString, :int, :int, :pointer],
549
- :int
550
-
551
- attach_function \
552
- :bcf_fmt_sized_array,
553
- [KString, :pointer],
554
- :uint8_t
555
-
556
- attach_function \
557
- :bcf_enc_vchar,
558
- [KString, :int, :string],
559
- :int
560
-
561
- attach_function \
562
- :bcf_enc_vint,
563
- [KString, :int, :pointer, :int],
564
- :int
565
-
566
- attach_function \
567
- :bcf_enc_vfloat,
568
- [KString, :int, :pointer],
569
- :int
570
-
571
- attach_function \
572
- :bcf_index_load2,
573
- %i[string string],
574
- HtsIdx.by_ref
575
-
576
- attach_function \
577
- :bcf_index_load3,
578
- %i[string string int],
579
- HtsIdx.by_ref
580
-
581
- attach_function \
582
- :bcf_index_build,
583
- %i[string int],
584
- :int
585
-
586
- attach_function \
587
- :bcf_index_build2,
588
- %i[string string int],
589
- :int
590
-
591
- attach_function \
592
- :bcf_index_build3,
593
- %i[string string int int],
594
- :int
595
-
596
- attach_function \
597
- :bcf_idx_init,
598
- [HtsFile, BcfHdr, :int, :string],
599
- :int
600
-
601
- attach_function \
602
- :bcf_idx_save,
603
- [HtsFile],
604
- :int
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
605
225
  end
606
226
  end