htslib 0.2.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93ee916dafed0ba04e486a59c81d2bd9befbceda3d679ef820e32d8817597afe
4
- data.tar.gz: 7dda13879d0c3707354ab69fe9967f60f0300c1971011218a5cf79e5e211ee25
3
+ metadata.gz: ea47a473d63b90fd2b1db4ecd65aa1ef38d47bbe5624e24ac583b5329301e5cb
4
+ data.tar.gz: aab96376972d7b0a587978484b22e41ee049ea742cba937cd57c66a9c0c42f2a
5
5
  SHA512:
6
- metadata.gz: 8cf68e9276f353bdea4389f5584066870a4887f07891387cf143408cf215c43232f2c390c08b80c57225a8d8b3722a9dcc5ba5cc3cc716079cf004bd34df0da0
7
- data.tar.gz: f30abf9c0d0dd07201e150dea5ec6976e7d968bc2f6bf2c347c1dec18cdfaaa5c141793208587f1629fa3cefeaaadd268083a105ab42dd450ce2ac8cfa0e2d7e
6
+ metadata.gz: 76d9aa699d0176557d8e44171018b132fc4df2c0e1f47a9784388693103799cf920c2ae437fb97f8429422a1edb5ebd43eae7b28a1f18452a5eeeac38244a981
7
+ data.tar.gz: f2f1d50099a66e71574c4019e66452dd100371cbdc7d08b144856bab8f59f04aac4e207585534f26e29a06342a7fafe5c3ea0fb0d0e2e8dd9ed1822ddbcbdfe8
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Q. Why is the file name auxi.rb and not aux.rb?
4
+ #
5
+ # A. This is for compatibility with Windows.
6
+ # In Windows, aux is a reserved word
7
+ # You cannot create a file named aux.
8
+
3
9
  module HTS
4
10
  class Bam < Hts
5
11
  # Auxiliary record data
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "flag"
4
4
  require_relative "cigar"
5
- require_relative "aux"
5
+ require_relative "auxi"
6
6
 
7
7
  module HTS
8
8
  class Bam < Hts
@@ -195,7 +195,7 @@ module HTS
195
195
  :reg, :string,
196
196
  :intervals, :pointer, # hts_pair_pos_t
197
197
  :tid, :int,
198
- :count, :uint32_t,
198
+ :count, :uint32,
199
199
  :min_beg, :hts_pos_t,
200
200
  :max_end, :hts_pos_t
201
201
  end
@@ -352,7 +352,7 @@ module HTS
352
352
  :qpos, :int32_t,
353
353
  :indel, :int,
354
354
  :level, :int,
355
- :_flags, :uint32_t, # bit_fields
355
+ :_flags, :uint32, # bit_fields
356
356
  :cd, BamPileupCd,
357
357
  :cigar_ind, :int
358
358
 
@@ -506,8 +506,8 @@ module HTS
506
506
  :rlen, :hts_pos_t,
507
507
  :rid, :int32_t,
508
508
  :qual, :float,
509
- :_n_info_allele, :uint32_t,
510
- :_n_fmt_sample, :uint32_t,
509
+ :_n_info_allele, :uint32,
510
+ :_n_fmt_sample, :uint32,
511
511
  :shared, KString,
512
512
  :indiv, KString,
513
513
  :d, BcfDec,
@@ -7,6 +7,8 @@ module HTS
7
7
  typedef :pointer, :cram_block
8
8
  typedef :pointer, :cram_metrics
9
9
 
10
+ # cram_fd
11
+
10
12
  attach_function \
11
13
  :cram_fd_get_header,
12
14
  [:cram_fd],
@@ -82,6 +84,8 @@ module HTS
82
84
  [:cram_fd],
83
85
  :int
84
86
 
87
+ # cram_block
88
+
85
89
  attach_function \
86
90
  :cram_block_get_content_id,
87
91
  [:cram_block],
@@ -157,71 +161,88 @@ module HTS
157
161
  %i[cram_block size_t],
158
162
  :void
159
163
 
164
+ # Computes the size of a cram block, including the block header itself.
160
165
  attach_function \
161
166
  :cram_block_size,
162
167
  [:cram_block],
163
168
  :uint32
164
169
 
170
+ # Renumbers RG numbers in a cram compression header.
165
171
  attach_function \
166
172
  :cram_transcode_rg,
167
173
  %i[cram_fd cram_fd cram_container int pointer pointer],
168
174
  :int
169
175
 
176
+ # Copies the blocks representing the next num_slice slices from a
177
+ # container from 'in' to 'out'.
170
178
  attach_function \
171
179
  :cram_copy_slice,
172
180
  %i[cram_fd cram_fd int32],
173
181
  :int
174
182
 
183
+ # Returns the number of cram blocks within this slice.
175
184
  attach_function \
176
185
  :cram_slice_hdr_get_num_blocks,
177
186
  [:pointer],
178
187
  :int32
179
188
 
189
+ # Returns the block content_id for the block containing an embedded
190
+ # reference sequence.
180
191
  attach_function \
181
192
  :cram_slice_hdr_get_embed_ref_id,
182
193
  [:pointer],
183
194
  :int
184
195
 
196
+ # Returns slice reference ID, start and span (length) coordinates.
185
197
  attach_function \
186
198
  :cram_slice_hdr_get_coords,
187
199
  %i[pointer pointer pointer pointer],
188
200
  :void
189
201
 
202
+ # Decodes a slice header from a cram block.
190
203
  attach_function \
191
204
  :cram_decode_slice_header,
192
205
  %i[pointer pointer],
193
206
  :pointer
194
207
 
208
+ # Frees a cram_block_slice_hdr structure.
195
209
  attach_function \
196
210
  :cram_free_slice_header,
197
211
  [:pointer],
198
212
  :void
199
213
 
214
+ # Allocates a new cram_block structure with a specified content_type
215
+ # and id.
200
216
  attach_function \
201
217
  :cram_new_block,
202
218
  [CramContentType, :int],
203
219
  :cram_block
204
220
 
221
+ # Reads a block from a cram file.
205
222
  attach_function \
206
223
  :cram_read_block,
207
224
  [:cram_fd],
208
225
  :cram_block
209
226
 
227
+ # Writes a CRAM block.
210
228
  attach_function \
211
229
  :cram_write_block,
212
230
  %i[cram_fd cram_block],
213
231
  :int
214
232
 
233
+ # Frees a CRAM block, deallocating internal data too.
215
234
  attach_function \
216
235
  :cram_free_block,
217
236
  [:cram_block],
218
237
  :void
219
238
 
239
+ # Uncompresses a CRAM block, if compressed.
220
240
  attach_function \
221
241
  :cram_uncompress_block,
222
242
  [:cram_block],
223
243
  :int
224
244
 
245
+ # Compresses a block.
225
246
  attach_function \
226
247
  :cram_compress_block,
227
248
  %i[cram_fd cram_block cram_metrics int int],
@@ -232,6 +253,8 @@ module HTS
232
253
  # %i[cram_fd cram_slice cram_block cram_metrics int int],
233
254
  # :int
234
255
 
256
+ # Creates a new container, specifying the maximum number of slices
257
+ # and records permitted.
235
258
  attach_function \
236
259
  :cram_new_container,
237
260
  %i[int int],
@@ -242,16 +265,20 @@ module HTS
242
265
  [:cram_container],
243
266
  :void
244
267
 
268
+ # Reads a container header.
245
269
  attach_function \
246
270
  :cram_read_container,
247
271
  [:cram_fd],
248
272
  :cram_container
249
273
 
274
+ # Writes a container structure.
250
275
  attach_function \
251
276
  :cram_write_container,
252
277
  %i[cram_fd cram_container],
253
278
  :int
254
279
 
280
+ # Stores the container structure in dat and returns *size as the
281
+ # number of bytes written to dat[].
255
282
  attach_function \
256
283
  :cram_store_container,
257
284
  %i[cram_fd cram_container string pointer],
@@ -262,61 +289,73 @@ module HTS
262
289
  [:cram_container],
263
290
  :int
264
291
 
292
+ # Opens a CRAM file for read (mode "rb") or write ("wb").
265
293
  attach_function \
266
294
  :cram_open,
267
295
  %i[string string],
268
296
  :cram_fd
269
297
 
298
+ # Opens an existing stream for reading or writing.
270
299
  attach_function \
271
300
  :cram_dopen,
272
301
  %i[pointer string string],
273
302
  :cram_fd
274
303
 
304
+ # Closes a CRAM file.
275
305
  attach_function \
276
306
  :cram_close,
277
307
  [:cram_fd],
278
308
  :int
279
309
 
310
+ # Seek within a CRAM file.
280
311
  attach_function \
281
312
  :cram_seek,
282
313
  %i[pointer off_t int],
283
314
  :int # FIXME: pointer should be :cram_fd
284
315
 
316
+ # Flushes a CRAM file.
285
317
  attach_function \
286
318
  :cram_flush,
287
319
  [:cram_fd],
288
320
  :int
289
321
 
322
+ # Checks for end of file on a cram_fd stream.
290
323
  attach_function \
291
324
  :cram_eof,
292
325
  [:cram_fd],
293
326
  :int
294
327
 
328
+ # Sets options on the cram_fd.
295
329
  attach_function \
296
330
  :cram_set_option,
297
331
  [:cram_fd, HtsFmtOption, :varargs],
298
332
  :int
299
333
 
334
+ # Sets options on the cram_fd.
300
335
  attach_function \
301
336
  :cram_set_voption,
302
337
  [:cram_fd, HtsFmtOption, :pointer], # va_list
303
338
  :int
304
339
 
340
+ # Attaches a header to a cram_fd.
305
341
  attach_function \
306
342
  :cram_set_header,
307
343
  [:cram_fd, SamHdr.by_ref],
308
344
  :int
309
345
 
346
+ # Check if this file has a proper EOF block
310
347
  attach_function \
311
348
  :cram_check_EOF,
312
349
  [:cram_fd],
313
350
  :int
314
351
 
352
+ # As int32_decoded/encode, but from/to blocks instead of cram_fd
315
353
  attach_function \
316
354
  :int32_put_blk,
317
355
  %i[cram_block int32_t],
318
356
  :int
319
357
 
358
+ # Returns the refs_t structure used by a cram file handle.
320
359
  attach_function \
321
360
  :cram_get_refs,
322
361
  [HtsFile.by_ref],
@@ -58,58 +58,72 @@ module HTS
58
58
  # macros
59
59
  # function-like macros
60
60
  class << self
61
+ # Get whether the query is on the reverse strand
61
62
  def bam_is_rev(b)
62
63
  b[:core][:flag] & BAM_FREVERSE != 0
63
64
  end
64
65
 
66
+ # Get whether the query's mate is on the reverse strand
65
67
  def bam_is_mrev(b)
66
68
  b[:core][:flag] & BAM_FMREVERSE != 0
67
69
  end
68
70
 
71
+ # Get the name of the query
69
72
  def bam_get_qname(b)
70
73
  b[:data]
71
74
  end
72
75
 
76
+ # Get the CIGAR array
73
77
  def bam_get_cigar(b)
74
78
  b[:data] + b[:core][:l_qname]
75
79
  end
76
80
 
81
+ # Get query sequence
77
82
  def bam_get_seq(b)
78
83
  b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname]
79
84
  end
80
85
 
86
+ # Get query quality
81
87
  def bam_get_qual(b)
82
88
  b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname] + ((b[:core][:l_qseq] + 1) >> 1)
83
89
  end
84
90
 
91
+ # Get auxiliary data
85
92
  def bam_get_aux(b)
86
93
  b[:data] + (b[:core][:n_cigar] << 2) + b[:core][:l_qname] + ((b[:core][:l_qseq] + 1) >> 1) + b[:core][:l_qseq]
87
94
  end
88
95
 
96
+ # Get length of auxiliary data
89
97
  def bam_get_l_aux(b)
90
98
  b[:l_data] - (b[:core][:n_cigar] << 2) - b[:core][:l_qname] - b[:core][:l_qseq] - ((b[:core][:l_qseq] + 1) >> 1)
91
99
  end
92
100
 
101
+ # Get a base on read
93
102
  def bam_seqi(s, i)
94
103
  (s[i >> 1].read_uint8 >> ((~i & 1) << 2)) & 0xf
95
104
  end
96
105
 
106
+ # Modifies a single base in the bam structure.
97
107
  def bam_set_seqi(s, i, b)
98
108
  s[i >> 1] = (s[i >> 1] & (0xf0 >> ((~i & 1) << 2))) | ((b) << ((~i & 1) << 2))
99
109
  end
100
110
 
111
+ # Returns the SAM formatted text of the \@HD header line
101
112
  def sam_hdr_find_hd(h, ks)
102
113
  sam_hdr_find_line_id(h, "HD", nil, nil, ks)
103
114
  end
104
115
 
116
+ # Returns the value associated with a given \@HD line tag
105
117
  def sam_hdr_find_tag_hd(h, key, ks)
106
118
  sam_hdr_find_tag_id(h, "HD", nil, nil, key, ks)
107
119
  end
108
120
 
121
+ # Adds or updates tags on the header \@HD line
109
122
  def sam_hdr_update_hd(h, *args)
110
123
  sam_hdr_update_line(h, "HD", nil, nil, *args, nil)
111
124
  end
112
125
 
126
+ # Removes the \@HD line tag with the given key
113
127
  def sam_hdr_remove_tag_hd(h, key)
114
128
  sam_hdr_remove_tag_id(h, "HD", nil, nil, key)
115
129
  end
@@ -122,6 +136,8 @@ module HTS
122
136
  alias bam_itr_querys sam_itr_querys
123
137
  alias bam_itr_next sam_itr_next
124
138
 
139
+ # Load/build .csi or .bai BAM index file. Does not work with CRAM.
140
+ # It is recommended to use the sam_index_* functions below instead.
125
141
  def bam_index_load(fn)
126
142
  hts_idx_load(fn, HTS_FMT_BAI)
127
143
  end
@@ -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,80 +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
- # DEPRECATED
187
+ # DEPRECATED use bcf_hdr_format() instead
158
188
  #
159
189
  # attach_function \
160
190
  # :bcf_hdr_fmt_text,
161
191
  # [BcfHdr, :int, :pointer],
162
192
  # :string
163
193
 
194
+ # Append new VCF header line
164
195
  attach_function \
165
196
  :bcf_hdr_append,
166
197
  [BcfHdr, :string],
@@ -171,26 +202,31 @@ module HTS
171
202
  [BcfHdr, :string, :varargs],
172
203
  :int
173
204
 
205
+ # VCF version, e.g. VCFv4.2
174
206
  attach_function \
175
207
  :bcf_hdr_get_version,
176
208
  [BcfHdr],
177
209
  :string
178
210
 
211
+ # Set version in bcf header
179
212
  attach_function \
180
213
  :bcf_hdr_set_version,
181
214
  [BcfHdr, :string],
182
215
  :int
183
216
 
217
+ # Remove VCF header tag
184
218
  attach_function \
185
219
  :bcf_hdr_remove,
186
220
  [BcfHdr, :int, :string],
187
221
  :void
188
222
 
223
+ # Creates a new copy of the header removing unwanted samples
189
224
  attach_function \
190
225
  :bcf_hdr_subset,
191
226
  [BcfHdr, :int, :pointer, :pointer],
192
227
  BcfHdr.by_ref
193
228
 
229
+ # Creates a list of sequence names.
194
230
  attach_function \
195
231
  :bcf_hdr_seqnames,
196
232
  [BcfHdr, :pointer],
@@ -201,16 +237,19 @@ module HTS
201
237
  [BcfHdr, :string],
202
238
  :int
203
239
 
240
+ # Synchronize internal header structures
204
241
  attach_function \
205
242
  :bcf_hdr_sync,
206
243
  [BcfHdr],
207
244
  :int
208
245
 
246
+ # parse a single line of VCF textual header
209
247
  attach_function \
210
248
  :bcf_hdr_parse_line,
211
249
  [BcfHdr, :string, :pointer],
212
250
  BcfHrec.by_ref
213
251
 
252
+ # Convert a bcf header record to string form
214
253
  attach_function \
215
254
  :bcf_hrec_format,
216
255
  [BcfHrec, KString],
@@ -221,21 +260,25 @@ module HTS
221
260
  [BcfHdr, BcfHrec],
222
261
  :int
223
262
 
263
+ # Get header line info
224
264
  attach_function \
225
265
  :bcf_hdr_get_hrec,
226
266
  [BcfHdr, :int, :string, :string, :string],
227
267
  BcfHrec.by_ref
228
268
 
269
+ # Duplicate a header record
229
270
  attach_function \
230
271
  :bcf_hrec_dup,
231
272
  [BcfHrec],
232
273
  BcfHrec.by_ref
233
274
 
275
+ # Add a new header record key
234
276
  attach_function \
235
277
  :bcf_hrec_add_key,
236
278
  [BcfHrec, :string, :size_t],
237
279
  :int
238
280
 
281
+ # Set a header record value
239
282
  attach_function \
240
283
  :bcf_hrec_set_val,
241
284
  [BcfHrec, :int, :string, :size_t, :int],
@@ -246,46 +289,57 @@ module HTS
246
289
  [BcfHrec, :string],
247
290
  :int
248
291
 
292
+ # Add an IDX header record
249
293
  attach_function \
250
294
  :hrec_add_idx,
251
295
  [BcfHrec, :int],
252
296
  :int
253
297
 
298
+ # Free up a header record and associated structures
254
299
  attach_function \
255
300
  :bcf_hrec_destroy,
256
301
  [BcfHrec],
257
302
  :void
258
303
 
304
+ # Individual record querying and manipulation routines
305
+
306
+ # See the description of bcf_hdr_subset()
259
307
  attach_function \
260
308
  :bcf_subset,
261
309
  [BcfHdr, Bcf1, :int, :pointer],
262
310
  :int
263
311
 
312
+ # Translate tags ids to be consistent with different header.
264
313
  attach_function \
265
314
  :bcf_translate,
266
315
  [BcfHdr, BcfHdr, Bcf1],
267
316
  :int
268
317
 
318
+ # Get variant types in a BCF record
269
319
  attach_function \
270
320
  :bcf_get_variant_types,
271
321
  [Bcf1],
272
322
  :int
273
323
 
324
+ # Get variant type in a BCF record, for a given allele
274
325
  attach_function \
275
326
  :bcf_get_variant_type,
276
327
  [Bcf1, :int],
277
328
  :int
278
329
 
330
+ # Check for presence of variant types in a BCF record
279
331
  attach_function \
280
332
  :bcf_has_variant_types,
281
333
  [Bcf1, :uint32, :int],
282
334
  :int
283
335
 
336
+ # Check for presence of variant types in a BCF record, for a given allele
284
337
  attach_function \
285
338
  :bcf_has_variant_type,
286
339
  [Bcf1, :int, :uint32],
287
340
  :int
288
341
 
342
+ # Return the number of bases affected by a variant, for a given allele
289
343
  attach_function \
290
344
  :bcf_variant_length,
291
345
  [Bcf1, :int],
@@ -296,26 +350,32 @@ module HTS
296
350
  [Bcf1],
297
351
  :int
298
352
 
353
+ # Sets the FILTER column
299
354
  attach_function \
300
355
  :bcf_update_filter,
301
356
  [BcfHdr, Bcf1, :pointer, :int],
302
357
  :int
303
358
 
359
+ # Adds to the FILTER column
304
360
  attach_function \
305
361
  :bcf_add_filter,
306
362
  [BcfHdr, Bcf1, :int],
307
363
  :int
308
364
 
365
+ # Removes from the FILTER column
309
366
  attach_function \
310
367
  :bcf_remove_filter,
311
368
  [BcfHdr, Bcf1, :int, :int],
312
369
  :int
313
370
 
371
+ # Returns 1 if present, 0 if absent, or -1 if filter does not exist.
372
+ # "PASS" and "." can be used interchangeably.
314
373
  attach_function \
315
374
  :bcf_has_filter,
316
375
  [BcfHdr, Bcf1, :string],
317
376
  :int
318
377
 
378
+ # Update REF and ALT column
319
379
  attach_function \
320
380
  :bcf_update_alleles,
321
381
  [BcfHdr, Bcf1, :pointer, :int],
@@ -326,6 +386,7 @@ module HTS
326
386
  [BcfHdr, Bcf1, :string],
327
387
  :int
328
388
 
389
+ # Sets new ID string
329
390
  attach_function \
330
391
  :bcf_update_id,
331
392
  [BcfHdr, Bcf1, :string],
@@ -336,6 +397,7 @@ module HTS
336
397
  [BcfHdr, Bcf1, :string],
337
398
  :int
338
399
 
400
+ # Functions for updating INFO fields
339
401
  attach_function \
340
402
  :bcf_update_info,
341
403
  [BcfHdr, Bcf1, :string, :pointer, :int, :int],
@@ -346,11 +408,13 @@ module HTS
346
408
  [BcfHdr, Bcf1, :string, :pointer, :int],
347
409
  :int
348
410
 
411
+ # Functions for updating FORMAT fields
349
412
  attach_function \
350
413
  :bcf_update_format,
351
414
  [BcfHdr, Bcf1, :string, :pointer, :int, :int],
352
415
  :int
353
416
 
417
+ # Returns pointer to FORMAT's field data
354
418
  attach_function \
355
419
  :bcf_get_fmt,
356
420
  [BcfHdr, Bcf1, :string],
@@ -361,6 +425,7 @@ module HTS
361
425
  [BcfHdr, Bcf1, :string],
362
426
  BcfInfo.by_ref
363
427
 
428
+ # Returns pointer to FORMAT/INFO field data given the header index instead of the string ID
364
429
  attach_function \
365
430
  :bcf_get_fmt_id,
366
431
  [Bcf1, :int],
@@ -371,6 +436,7 @@ module HTS
371
436
  [Bcf1, :int],
372
437
  BcfInfo.by_ref
373
438
 
439
+ # get INFO values
374
440
  attach_function \
375
441
  :bcf_get_info_values,
376
442
  [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
@@ -386,11 +452,15 @@ module HTS
386
452
  [BcfHdr, Bcf1, :string, :pointer, :pointer, :int],
387
453
  :int
388
454
 
455
+ # Helper functions
456
+
457
+ # Translates string into numeric ID
389
458
  attach_function \
390
459
  :bcf_hdr_id2int,
391
460
  [BcfHdr, :int, :string],
392
461
  :int
393
462
 
463
+ # Convert BCF FORMAT data to string form
394
464
  attach_function \
395
465
  :bcf_fmt_array,
396
466
  [KString, :int, :int, :pointer],
@@ -401,51 +471,63 @@ module HTS
401
471
  [KString, :pointer],
402
472
  :uint8_t
403
473
 
474
+ # Encode a variable-length char array in BCF format
404
475
  attach_function \
405
476
  :bcf_enc_vchar,
406
477
  [KString, :int, :string],
407
478
  :int
408
479
 
480
+ # Encode a variable-length integer array in BCF format
409
481
  attach_function \
410
482
  :bcf_enc_vint,
411
483
  [KString, :int, :pointer, :int],
412
484
  :int
413
485
 
486
+ # Encode a variable-length float array in BCF format
414
487
  attach_function \
415
488
  :bcf_enc_vfloat,
416
489
  [KString, :int, :pointer],
417
490
  :int
418
491
 
492
+ # BCF index
493
+
494
+ # Load a BCF index from a given index file name
419
495
  attach_function \
420
496
  :bcf_index_load2,
421
497
  %i[string string],
422
498
  HtsIdx.by_ref
423
499
 
500
+ # Load a BCF index from a given index file name
424
501
  attach_function \
425
502
  :bcf_index_load3,
426
503
  %i[string string int],
427
504
  HtsIdx.by_ref
428
505
 
506
+ # Generate and save an index file
429
507
  attach_function \
430
508
  :bcf_index_build,
431
509
  %i[string int],
432
510
  :int
433
511
 
512
+ # Generate and save an index to a specific file
434
513
  attach_function \
435
514
  :bcf_index_build2,
436
515
  %i[string string int],
437
516
  :int
438
517
 
518
+ # Generate and save an index to a specific file
439
519
  attach_function \
440
520
  :bcf_index_build3,
441
521
  %i[string string int int],
442
522
  :int
443
523
 
524
+ # Initialise fp->idx for the current format type, for VCF and BCF files.
444
525
  attach_function \
445
526
  :bcf_idx_init,
446
527
  [HtsFile, BcfHdr, :int, :string],
447
528
  :int
448
529
 
530
+ # Writes the index initialised with bcf_idx_init to disk.
449
531
  attach_function \
450
532
  :bcf_idx_save,
451
533
  [HtsFile],
@@ -87,105 +87,130 @@ module HTS
87
87
  BCF_UN_ALL = (BCF_UN_SHR | BCF_UN_FMT) # everything
88
88
 
89
89
  class << self
90
+ # Get number of samples
90
91
  def bcf_hdr_nsamples(hdr)
91
92
  hdr[:n][BCF_DT_SAMPLE]
92
93
  end
93
94
 
95
+ # Function for updating INFO fields
94
96
  def bcf_update_info_int32(hdr, line, key, values, n)
95
97
  bcf_update_info(hdr, line, key, values, n, BCF_HT_INT)
96
98
  end
97
99
 
100
+ # Function for updating INFO fields
98
101
  def bcf_update_info_float(hdr, line, key, values, n)
99
102
  bcf_update_info(hdr, line, key, values, n, BCF_HT_REAL)
100
103
  end
101
104
 
105
+ # Function for updating INFO fields
102
106
  def bcf_update_info_flag(hdr, line, key, string, n)
103
107
  bcf_update_info(hdr, line, key, string, n, BCF_HT_FLAG)
104
108
  end
105
109
 
110
+ # Function for updating INFO fields
106
111
  def bcf_update_info_string(hdr, line, key, string)
107
112
  bcf_update_info(hdr, line, key, string, 1, BCF_HT_STR)
108
113
  end
109
114
 
115
+ # Function for updating FORMAT fields
110
116
  def bcf_update_format_int32(hdr, line, key, values, n)
111
117
  bcf_update_format(hdr, line, key, values, n,
112
118
  BCF_HT_INT)
113
119
  end
114
120
 
121
+ # Function for updating FORMAT fields
115
122
  def bcf_update_format_float(hdr, line, key, values, n)
116
123
  bcf_update_format(hdr, line, key, values, n,
117
124
  BCF_HT_REAL)
118
125
  end
119
126
 
127
+ # Function for updating FORMAT fields
120
128
  def bcf_update_format_char(hdr, line, key, values, n)
121
129
  bcf_update_format(hdr, line, key, values, n,
122
130
  BCF_HT_STR)
123
131
  end
124
132
 
133
+ # Function for updating FORMAT fields
125
134
  def bcf_update_genotypes(hdr, line, gts, n)
126
135
  bcf_update_format(hdr, line, "GT", gts, n, BCF_HT_INT)
127
136
  end
128
137
 
138
+ # Macro for setting genotypes correctly
129
139
  def bcf_gt_phased(idx)
130
140
  ((idx + 1) << 1 | 1)
131
141
  end
132
142
 
143
+ # Macro for setting genotypes correctly
133
144
  def bcf_gt_unphased(idx)
134
145
  ((idx + 1) << 1)
135
146
  end
136
147
 
148
+ # Macro for setting genotypes correctly
137
149
  def bcf_gt_missing
138
150
  0
139
151
  end
140
152
 
153
+ # Macro for setting genotypes correctly
141
154
  def bcf_gt_is_missing(val)
142
155
  (val >> 1 ? 0 : 1)
143
156
  end
144
157
 
158
+ # Macro for setting genotypes correctly
145
159
  def bcf_gt_is_phased(idx)
146
160
  (idx & 1)
147
161
  end
148
162
 
163
+ # Macro for setting genotypes correctly
149
164
  def bcf_gt_allele(val)
150
165
  ((val >> 1) - 1)
151
166
  end
152
167
 
168
+ # Conversion between alleles indexes to Number=G genotype index (assuming diploid, all 0-based)
153
169
  def bcf_alleles2gt(a, b)
154
170
  ((a) > (b) ? (a * (a + 1) / 2 + b) : (b * (b + 1) / 2 + a))
155
171
  end
156
172
 
173
+ # Get INFO values
157
174
  def bcf_get_info_int32(hdr, line, tag, dst, ndst)
158
175
  bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_INT)
159
176
  end
160
177
 
178
+ # Get INFO values
161
179
  def bcf_get_info_float(hdr, line, tag, dst, ndst)
162
180
  bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_REAL)
163
181
  end
164
182
 
183
+ # Get INFO values
165
184
  def bcf_get_info_string(hdr, line, tag, dst, ndst)
166
185
  bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_STR)
167
186
  end
168
187
 
188
+ # Get INFO values
169
189
  def bcf_get_info_flag(hdr, line, tag, dst, ndst)
170
190
  bcf_get_info_values(hdr, line, tag, dst, ndst, BCF_HT_FLAG)
171
191
  end
172
192
 
193
+ # Get FORMAT values
173
194
  def bcf_get_format_int32(hdr, line, tag, dst, ndst)
174
195
  bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_INT)
175
196
  end
176
197
 
198
+ # Get FORMAT values
177
199
  def bcf_get_format_float(hdr, line, tag, dst, ndst)
178
200
  bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_REAL)
179
201
  end
180
202
 
203
+ # Get FORMAT values
181
204
  def bcf_get_format_char(hdr, line, tag, dst, ndst)
182
205
  bcf_get_format_values(hdr, line, tag, dst, ndst, BCF_HT_STR)
183
206
  end
184
207
 
208
+ # Get FORMAT values
185
209
  def bcf_get_genotypes(hdr, line, dst, ndst)
186
210
  bcf_get_format_values(hdr, line, "GT", dst, ndst, BCF_HT_INT)
187
211
  end
188
212
 
213
+ # Translates numeric ID into string
189
214
  def bcf_hdr_int2id(hdr, type, int_id)
190
215
  LibHTS::BcfIdpair.new(
191
216
  hdr[:id][type].to_ptr +
@@ -193,10 +218,12 @@ module HTS
193
218
  )[:key]
194
219
  end
195
220
 
221
+ # Translates sequence names (chromosomes) into numeric ID
196
222
  def bcf_hdr_name2id(hdr, id)
197
223
  bcf_hdr_id2int(hdr, BCF_DT_CTG, id)
198
224
  end
199
225
 
226
+ # Translates numeric ID to sequence name
200
227
  def bcf_hdr_id2name(hdr, rid)
201
228
  return nil if hdr.null? || rid < 0 || rid >= hdr[:n][LibHTS::BCF_DT_CTG]
202
229
 
@@ -206,6 +233,7 @@ module HTS
206
233
  )[:key]
207
234
  end
208
235
 
236
+ # Macro for accessing bcf_idinfo_t
209
237
  def bcf_hdr_id2length(hdr, type, int_id)
210
238
  LibHTS::BcfIdpair.new(
211
239
  hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
@@ -213,6 +241,7 @@ module HTS
213
241
  )[:val][:info][type] >> 8 & 0xf
214
242
  end
215
243
 
244
+ # Macro for accessing bcf_idinfo_t
216
245
  def bcf_hdr_id2number(hdr, type, int_id)
217
246
  LibHTS::BcfIdpair.new(
218
247
  hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
@@ -220,6 +249,7 @@ module HTS
220
249
  )[:val][:info][type] >> 12
221
250
  end
222
251
 
252
+ # Macro for accessing bcf_idinfo_t
223
253
  def bcf_hdr_id2type(hdr, type, int_id)
224
254
  LibHTS::BcfIdpair.new(
225
255
  hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
@@ -227,6 +257,7 @@ module HTS
227
257
  )[:val][:info][type] >> 4 & 0xf
228
258
  end
229
259
 
260
+ # Macro for accessing bcf_idinfo_t
230
261
  def bcf_hdr_id2coltype(hdr, type, int_id)
231
262
  LibHTS::BcfIdpair.new(
232
263
  hdr[:id][LibHTS::BCF_DT_ID].to_ptr +
@@ -252,10 +283,12 @@ module HTS
252
283
  hts_itr_querys(idx, s, @@bcf_hdr_name2id, hdr, @@hts_itr_query, @@bcf_readrec)
253
284
  end
254
285
 
286
+ # Load a BCF index
255
287
  def bcf_index_load(fn)
256
288
  hts_idx_load(fn, HTS_FMT_CSI)
257
289
  end
258
290
 
291
+ # Load a BCF index
259
292
  def bcf_index_seqnames(idx, hdr, nptr)
260
293
  hts_idx_seqnames(idx, nptr, @@bcf_hdr_id2name, hdr)
261
294
  end
data/lib/hts/libhts.rb CHANGED
@@ -15,12 +15,13 @@ module HTS
15
15
  end
16
16
 
17
17
  # @!macro attach_function
18
+ # @!scope class
18
19
  # @!method $1(${2--2})
19
20
  # @return [${-1}] the return value of $0
20
21
  def self.attach_function(*)
21
22
  super
22
23
  rescue FFI::NotFoundError => e
23
- warn e.message
24
+ warn e.message if $VERBOSE
24
25
  end
25
26
  end
26
27
  end
data/lib/hts/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
data/lib/htslib.rb CHANGED
@@ -30,9 +30,23 @@ module HTS
30
30
 
31
31
  warn "htslib shared library '#{name}' not found."
32
32
  end
33
+
34
+ def search_htslib_windows
35
+ ENV["HTSLIBDIR"] ||= [
36
+ RubyInstaller::Runtime.msys2_installation.msys_path,
37
+ RubyInstaller::Runtime.msys2_installation.mingwarch
38
+ ].join(File::ALT_SEPARATOR)
39
+ path = File.expand_path("bin/hts-3.dll", ENV["HTSLIBDIR"])
40
+ RubyInstaller::Runtime.add_dll_directory(File.dirname(path))
41
+ path
42
+ end
33
43
  end
34
44
 
35
- self.lib_path = search_htslib
45
+ self.lib_path = if Object.const_defined?(:RubyInstaller)
46
+ search_htslib_windows
47
+ else
48
+ search_htslib
49
+ end
36
50
 
37
51
  # You can change the path of the shared library with `HTS.lib_path=`
38
52
  # before calling the LibHTS module.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htslib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-19 00:00:00.000000000 Z
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -132,7 +132,7 @@ files:
132
132
  - LICENSE.txt
133
133
  - README.md
134
134
  - lib/hts/bam.rb
135
- - lib/hts/bam/aux.rb
135
+ - lib/hts/bam/auxi.rb
136
136
  - lib/hts/bam/cigar.rb
137
137
  - lib/hts/bam/flag.rb
138
138
  - lib/hts/bam/header.rb
@@ -169,7 +169,8 @@ files:
169
169
  homepage: https://github.com/kojix2/ruby-htslib
170
170
  licenses:
171
171
  - MIT
172
- metadata: {}
172
+ metadata:
173
+ msys2_mingw_dependencies: htslib
173
174
  post_install_message:
174
175
  rdoc_options: []
175
176
  require_paths: