htslib 0.4.2 → 0.5.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +79 -49
  3. data/TUTORIAL.md +9 -20
  4. data/ext/htslib_native/extconf.rb +41 -0
  5. data/ext/htslib_native/htslib_native.h +11 -0
  6. data/ext/htslib_native/htslib_native_ext.c +48 -0
  7. data/ext/htslib_native/native_bam.c +1108 -0
  8. data/ext/htslib_native/native_bcf.c +369 -0
  9. data/ext/htslib_native/native_faidx.c +155 -0
  10. data/ext/htslib_native/native_tabix.c +246 -0
  11. data/lib/hts/bam/auxi.rb +87 -342
  12. data/lib/hts/bam/base_mod.rb +37 -73
  13. data/lib/hts/bam/cigar.rb +9 -55
  14. data/lib/hts/bam/flag.rb +19 -27
  15. data/lib/hts/bam/header.rb +29 -56
  16. data/lib/hts/bam/mpileup.rb +158 -132
  17. data/lib/hts/bam/pileup.rb +120 -145
  18. data/lib/hts/bam/record.rb +233 -270
  19. data/lib/hts/bam.rb +102 -42
  20. data/lib/hts/bcf/errors.rb +1 -0
  21. data/lib/hts/bcf/format.rb +278 -379
  22. data/lib/hts/bcf/header.rb +38 -122
  23. data/lib/hts/bcf/header_record.rb +9 -35
  24. data/lib/hts/bcf/info.rb +72 -320
  25. data/lib/hts/bcf/record.rb +61 -102
  26. data/lib/hts/bcf.rb +149 -323
  27. data/lib/hts/faidx.rb +28 -87
  28. data/lib/hts/hts.rb +6 -94
  29. data/lib/hts/native.rb +13 -0
  30. data/lib/hts/tabix.rb +93 -48
  31. data/lib/hts/version.rb +1 -1
  32. data/lib/htslib.rb +6 -52
  33. metadata +13 -64
  34. data/lib/hts/ffi_ext/README.md +0 -8
  35. data/lib/hts/ffi_ext/pointer.rb +0 -18
  36. data/lib/hts/ffi_ext/struct.rb +0 -45
  37. data/lib/hts/libhts/bgzf.rb +0 -199
  38. data/lib/hts/libhts/constants.rb +0 -658
  39. data/lib/hts/libhts/cram.rb +0 -471
  40. data/lib/hts/libhts/fai.rb +0 -146
  41. data/lib/hts/libhts/hfile.rb +0 -121
  42. data/lib/hts/libhts/hts.rb +0 -477
  43. data/lib/hts/libhts/kfunc.rb +0 -38
  44. data/lib/hts/libhts/sam.rb +0 -760
  45. data/lib/hts/libhts/sam_funcs.rb +0 -155
  46. data/lib/hts/libhts/tbx.rb +0 -94
  47. data/lib/hts/libhts/tbx_funcs.rb +0 -36
  48. data/lib/hts/libhts/thread_pool.rb +0 -139
  49. data/lib/hts/libhts/vcf.rb +0 -567
  50. data/lib/hts/libhts/vcf_funcs.rb +0 -366
  51. data/lib/hts/libhts.rb +0 -47
@@ -1,567 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- module LibHTS
5
- # Get error description for bcf error code
6
- attach_function \
7
- :bcf_strerror,
8
- %i[int pointer size_t],
9
- :string
10
-
11
- # Create an empty BCF header.
12
- attach_function \
13
- :bcf_hdr_init,
14
- [:string],
15
- BcfHdr.by_ref
16
-
17
- # Destroy a BCF header struct
18
- attach_function \
19
- :bcf_hdr_destroy,
20
- [BcfHdr],
21
- :void
22
-
23
- # Allocate and initialize a bcf1_t object.
24
- attach_function \
25
- :bcf_init,
26
- [],
27
- Bcf1.by_ref
28
-
29
- # Deallocate a bcf1_t object
30
- attach_function \
31
- :bcf_destroy,
32
- [Bcf1],
33
- :void
34
-
35
- # Same as bcf_destroy() but frees only the memory allocated by bcf1_t,
36
- # not the bcf1_t object itself.
37
- attach_function \
38
- :bcf_empty,
39
- [Bcf1],
40
- :void
41
-
42
- # Make the bcf1_t object ready for next read.
43
- attach_function \
44
- :bcf_clear,
45
- [Bcf1],
46
- :void
47
-
48
- # Read a VCF or BCF header
49
- attach_function \
50
- :bcf_hdr_read,
51
- [HtsFile],
52
- BcfHdr.by_ref
53
-
54
- # for more efficient VCF parsing when only one/few samples are needed
55
- attach_function \
56
- :bcf_hdr_set_samples,
57
- [BcfHdr, :string, :int],
58
- :int
59
-
60
- attach_function \
61
- :bcf_subset_format,
62
- [BcfHdr, Bcf1],
63
- :int
64
-
65
- # Write a VCF or BCF header
66
- attach_function \
67
- :bcf_hdr_write,
68
- [HtsFile, BcfHdr],
69
- :int
70
-
71
- # Parse VCF line contained in kstring and populate the bcf1_t struct
72
- attach_function \
73
- :vcf_parse,
74
- [KString, BcfHdr, Bcf1],
75
- :int
76
-
77
- # Complete the file opening mode, according to its extension.
78
- attach_function \
79
- :vcf_open_mode,
80
- %i[string string string],
81
- :int
82
-
83
- # The opposite of vcf_parse.
84
- attach_function \
85
- :vcf_format,
86
- [BcfHdr, Bcf1, KString],
87
- :int
88
-
89
- # Read next VCF or BCF record
90
- attach_function \
91
- :bcf_read,
92
- [HtsFile, BcfHdr, Bcf1],
93
- :int
94
-
95
- # unpack/decode a BCF record (fills the bcf1_t::d field)
96
- attach_function \
97
- :bcf_unpack,
98
- [Bcf1, :int],
99
- :int
100
-
101
- # Create a copy of BCF record.
102
- attach_function \
103
- :bcf_dup,
104
- [Bcf1],
105
- Bcf1.by_ref
106
-
107
- attach_function \
108
- :bcf_copy,
109
- [Bcf1, Bcf1],
110
- Bcf1.by_ref
111
-
112
- # Write one VCF or BCF record.
113
- attach_function \
114
- :bcf_write,
115
- [HtsFile, BcfHdr, Bcf1],
116
- :int
117
-
118
- # Read a VCF format header
119
- attach_function \
120
- :vcf_hdr_read,
121
- [HtsFile],
122
- BcfHdr.by_ref
123
-
124
- # Write a VCF format header
125
- attach_function \
126
- :vcf_hdr_write,
127
- [HtsFile, BcfHdr],
128
- :int
129
-
130
- # Read a record from a VCF file
131
- attach_function \
132
- :vcf_read,
133
- [HtsFile, BcfHdr, Bcf1],
134
- :int
135
-
136
- # Write a record to a VCF file
137
- attach_function \
138
- :vcf_write,
139
- [HtsFile, BcfHdr, Bcf1],
140
- :int
141
-
142
- # Helper function for the bcf_itr_next() macro
143
- attach_function \
144
- :bcf_readrec,
145
- [BGZF, :pointer, :pointer, :pointer, :hts_pos_t, :hts_pos_t],
146
- :int
147
-
148
- attach_function \
149
- :bcf_itr_querys1,
150
- [HtsIdx, BcfHdr, :string],
151
- HtsItr.by_ref
152
-
153
- attach_function \
154
- :bcf_itr_regarray,
155
- [HtsIdx, BcfHdr, :pointer, :uint],
156
- HtsItr.by_ref
157
-
158
- # Write a line to a VCF file
159
- attach_function \
160
- :vcf_write_line,
161
- [HtsFile, KString],
162
- :int
163
-
164
- # Header querying and manipulation routines
165
-
166
- # Create a new header using the supplied template
167
- attach_function \
168
- :bcf_hdr_dup,
169
- [BcfHdr],
170
- BcfHdr.by_ref
171
-
172
- # DEPRECATED please use bcf_hdr_merge instead
173
- #
174
- # attach_function \
175
- # :bcf_hdr_combine,
176
- # [BcfHdr, BcfHdr],
177
- # :int
178
-
179
- # Copy header lines from src to dst, see also bcf_translate()
180
- attach_function \
181
- :bcf_hdr_merge,
182
- [BcfHdr, BcfHdr],
183
- BcfHdr.by_ref
184
-
185
- # Add a new sample.
186
- attach_function \
187
- :bcf_hdr_add_sample,
188
- [BcfHdr, :string],
189
- :int
190
-
191
- # Read VCF header from a file and update the header
192
- attach_function \
193
- :bcf_hdr_set,
194
- [BcfHdr, :string],
195
- :int
196
-
197
- # Appends formatted header text to _str_.
198
- attach_function \
199
- :bcf_hdr_format,
200
- [BcfHdr, :int, KString],
201
- :int
202
-
203
- # DEPRECATED use bcf_hdr_format() instead
204
- #
205
- # attach_function \
206
- # :bcf_hdr_fmt_text,
207
- # [BcfHdr, :int, :pointer],
208
- # :string
209
-
210
- # Append new VCF header line
211
- attach_function \
212
- :bcf_hdr_append,
213
- [BcfHdr, :string],
214
- :int
215
-
216
- attach_function \
217
- :bcf_hdr_printf,
218
- [BcfHdr, :string, :varargs],
219
- :int
220
-
221
- # VCF version, e.g. VCFv4.2
222
- attach_function \
223
- :bcf_hdr_get_version,
224
- [BcfHdr],
225
- :string
226
-
227
- # Set version in bcf header
228
- attach_function \
229
- :bcf_hdr_set_version,
230
- [BcfHdr, :string],
231
- :int
232
-
233
- # Remove VCF header tag
234
- attach_function \
235
- :bcf_hdr_remove,
236
- [BcfHdr, :int, :string],
237
- :void
238
-
239
- # Creates a new copy of the header removing unwanted samples
240
- attach_function \
241
- :bcf_hdr_subset,
242
- [BcfHdr, :int, :pointer, :pointer],
243
- BcfHdr.by_ref
244
-
245
- # Creates a list of sequence names.
246
- attach_function \
247
- :bcf_hdr_seqnames,
248
- [BcfHdr, :pointer],
249
- :pointer
250
-
251
- attach_function \
252
- :bcf_hdr_parse,
253
- [BcfHdr, :string],
254
- :int
255
-
256
- # Synchronize internal header structures
257
- attach_function \
258
- :bcf_hdr_sync,
259
- [BcfHdr],
260
- :int
261
-
262
- # parse a single line of VCF textual header
263
- attach_function \
264
- :bcf_hdr_parse_line,
265
- [BcfHdr, :string, :pointer],
266
- BcfHrec.by_ref
267
-
268
- # Convert a bcf header record to string form
269
- attach_function \
270
- :bcf_hrec_format,
271
- [BcfHrec, KString],
272
- :int
273
-
274
- attach_function \
275
- :bcf_hdr_add_hrec,
276
- [BcfHdr, BcfHrec],
277
- :int
278
-
279
- # Get header line info
280
- attach_function \
281
- :bcf_hdr_get_hrec,
282
- [BcfHdr, :int, :string, :string, :string],
283
- :pointer
284
-
285
- # Duplicate a header record
286
- attach_function \
287
- :bcf_hrec_dup,
288
- [:pointer],
289
- BcfHrec.by_ref
290
-
291
- # Add a new header record key
292
- attach_function \
293
- :bcf_hrec_add_key,
294
- [BcfHrec, :string, :size_t],
295
- :int
296
-
297
- # Set a header record value
298
- attach_function \
299
- :bcf_hrec_set_val,
300
- [BcfHrec, :int, :string, :size_t, :int],
301
- :int
302
-
303
- attach_function \
304
- :bcf_hrec_find_key,
305
- [BcfHrec, :string],
306
- :int
307
-
308
- # Add an IDX header record
309
- attach_function \
310
- :hrec_add_idx,
311
- [BcfHrec, :int],
312
- :int
313
-
314
- # Free up a header record and associated structures
315
- attach_function \
316
- :bcf_hrec_destroy,
317
- [:pointer],
318
- :void
319
-
320
- # Individual record querying and manipulation routines
321
-
322
- # See the description of bcf_hdr_subset()
323
- attach_function \
324
- :bcf_subset,
325
- [BcfHdr, Bcf1, :int, :pointer],
326
- :int
327
-
328
- # Translate tags ids to be consistent with different header.
329
- attach_function \
330
- :bcf_translate,
331
- [BcfHdr, BcfHdr, Bcf1],
332
- :int
333
-
334
- # Get variant types in a BCF record
335
- attach_function \
336
- :bcf_get_variant_types,
337
- [Bcf1],
338
- :int
339
-
340
- # Get variant type in a BCF record, for a given allele
341
- attach_function \
342
- :bcf_get_variant_type,
343
- [Bcf1, :int],
344
- :int
345
-
346
- # Check for presence of variant types in a BCF record
347
- attach_function \
348
- :bcf_has_variant_types,
349
- [Bcf1, :uint32, :int],
350
- :int
351
-
352
- # Check for presence of variant types in a BCF record, for a given allele
353
- attach_function \
354
- :bcf_has_variant_type,
355
- [Bcf1, :int, :uint32],
356
- :int
357
-
358
- # Return the number of bases affected by a variant, for a given allele
359
- attach_function \
360
- :bcf_variant_length,
361
- [Bcf1, :int],
362
- :int
363
-
364
- attach_function \
365
- :bcf_is_snp,
366
- [Bcf1],
367
- :int
368
-
369
- # Sets the FILTER column
370
- attach_function \
371
- :bcf_update_filter,
372
- [BcfHdr, Bcf1, :pointer, :int],
373
- :int
374
-
375
- # Adds to the FILTER column
376
- attach_function \
377
- :bcf_add_filter,
378
- [BcfHdr, Bcf1, :int],
379
- :int
380
-
381
- # Removes from the FILTER column
382
- attach_function \
383
- :bcf_remove_filter,
384
- [BcfHdr, Bcf1, :int, :int],
385
- :int
386
-
387
- # Returns 1 if present, 0 if absent, or -1 if filter does not exist.
388
- # "PASS" and "." can be used interchangeably.
389
- attach_function \
390
- :bcf_has_filter,
391
- [BcfHdr, Bcf1, :string],
392
- :int
393
-
394
- # Update REF and ALT column
395
- attach_function \
396
- :bcf_update_alleles,
397
- [BcfHdr, Bcf1, :pointer, :int],
398
- :int
399
-
400
- attach_function \
401
- :bcf_update_alleles_str,
402
- [BcfHdr, Bcf1, :string],
403
- :int
404
-
405
- # Sets new ID string
406
- attach_function \
407
- :bcf_update_id,
408
- [BcfHdr, Bcf1, :string],
409
- :int
410
-
411
- attach_function \
412
- :bcf_add_id,
413
- [BcfHdr, Bcf1, :string],
414
- :int
415
-
416
- # Functions for updating INFO fields
417
- attach_function \
418
- :bcf_update_info,
419
- [BcfHdr, Bcf1, :string, :pointer, :int, :int],
420
- :int
421
-
422
- attach_function \
423
- :bcf_update_format_string,
424
- [BcfHdr, Bcf1, :string, :pointer, :int],
425
- :int
426
-
427
- # Functions for updating FORMAT fields
428
- attach_function \
429
- :bcf_update_format,
430
- [BcfHdr, Bcf1, :string, :pointer, :int, :int],
431
- :int
432
-
433
- # Returns pointer to FORMAT's field data
434
- attach_function \
435
- :bcf_get_fmt,
436
- [BcfHdr, Bcf1, :string],
437
- BcfFmt.by_ref
438
-
439
- attach_function \
440
- :bcf_get_info,
441
- [BcfHdr, Bcf1, :string],
442
- BcfInfo.by_ref
443
-
444
- # Returns pointer to FORMAT/INFO field data given the header index instead of the string ID
445
- attach_function \
446
- :bcf_get_fmt_id,
447
- [Bcf1, :int],
448
- BcfFmt.by_ref
449
-
450
- attach_function \
451
- :bcf_get_info_id,
452
- [Bcf1, :int],
453
- BcfInfo.by_ref
454
-
455
- # get INFO values
456
- attach_function \
457
- :bcf_get_info_values,
458
- [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
459
- :int
460
-
461
- attach_function \
462
- :bcf_get_format_string,
463
- [BcfHdr, Bcf1, :string, :pointer, :pointer],
464
- :int
465
-
466
- attach_function \
467
- :bcf_get_format_values,
468
- [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
469
- :int
470
-
471
- # Helper functions
472
-
473
- # Translates string into numeric ID
474
- attach_function \
475
- :bcf_hdr_id2int,
476
- [BcfHdr, :int, :string],
477
- :int
478
-
479
- # Convert BCF FORMAT data to string form
480
- attach_function \
481
- :bcf_fmt_array,
482
- [KString, :int, :int, :pointer],
483
- :int
484
-
485
- attach_function \
486
- :bcf_fmt_sized_array,
487
- [KString, :pointer],
488
- :uint8
489
-
490
- # Encode a variable-length char array in BCF format
491
- attach_function \
492
- :bcf_enc_vchar,
493
- [KString, :int, :string],
494
- :int
495
-
496
- # Encode a variable-length integer array in BCF format
497
- attach_function \
498
- :bcf_enc_vint,
499
- [KString, :int, :pointer, :int],
500
- :int
501
-
502
- # Encode a variable-length float array in BCF format
503
- attach_function \
504
- :bcf_enc_vfloat,
505
- [KString, :int, :pointer],
506
- :int
507
-
508
- # BCF index
509
-
510
- # Load a BCF index from a given index file name
511
- attach_function \
512
- :bcf_index_load2,
513
- %i[string string],
514
- HtsIdx.by_ref
515
-
516
- # Load a BCF index from a given index file name
517
- attach_function \
518
- :bcf_index_load3,
519
- %i[string string int],
520
- HtsIdx.by_ref
521
-
522
- # Generate and save an index file
523
- attach_function \
524
- :bcf_index_build,
525
- %i[string int],
526
- :int
527
-
528
- # Generate and save an index to a specific file
529
- attach_function \
530
- :bcf_index_build2,
531
- %i[string string int],
532
- :int
533
-
534
- # Generate and save an index to a specific file
535
- attach_function \
536
- :bcf_index_build3,
537
- %i[string string int int],
538
- :int
539
-
540
- # Initialise fp->idx for the current format type, for VCF and BCF files.
541
- attach_function \
542
- :bcf_idx_init,
543
- [HtsFile, BcfHdr, :int, :string],
544
- :int
545
-
546
- # Writes the index initialised with bcf_idx_init to disk.
547
- attach_function \
548
- :bcf_idx_save,
549
- [HtsFile],
550
- :int
551
-
552
- attach_variable \
553
- :bcf_float_vector_end,
554
- :uint32
555
-
556
- attach_variable \
557
- :bcf_float_missing,
558
- :uint32
559
-
560
- attach_function \
561
- :bcf_format_gt_v2,
562
- [BcfHdr, BcfFmt, :int, KString],
563
- :int
564
- end
565
- end
566
-
567
- require_relative "vcf_funcs"