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