htslib 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/hts/bam/cigar.rb +2 -0
- data/lib/hts/bam/flag.rb +6 -2
- data/lib/hts/bam/header.rb +5 -1
- data/lib/hts/bam/record.rb +10 -6
- data/lib/hts/bcf/format.rb +2 -1
- data/lib/hts/bcf/header.rb +11 -4
- data/lib/hts/bcf/info.rb +1 -0
- data/lib/hts/bcf/record.rb +6 -3
- data/lib/hts/bcf.rb +1 -1
- data/lib/hts/ffi_ext/struct.rb +1 -1
- data/lib/hts/libhts/hts.rb +6 -0
- data/lib/hts/libhts/sam.rb +2 -590
- data/lib/hts/libhts/sam_funcs.rb +595 -0
- data/lib/hts/libhts/vcf.rb +32 -439
- data/lib/hts/libhts/vcf_funcs.rb +430 -0
- data/lib/hts/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f05bc93a621f3d5fb8d06e44c20ac4a3a95c5f6e243df2aebc97e10125fcb779
|
4
|
+
data.tar.gz: 73e747aa0999e54b3c8f01b981b91c4e293167265276a24eac85ea0fd6b85c13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d0f3f8bb9f7a9c063222fd2dc6463f58bdfd784aff39757921dda1c8d417023b024ca9f6c92d7f0eecd30b8064adb1b94966cf962cf9e0e56d67303de0a903b
|
7
|
+
data.tar.gz: 8ef35b7aef04bf2f51ae0ba110d9ffc81c26d7a0c97a821aa1274c04b31ec29515b33c278391494f6a0d8efc5e2d965060ccd190ee0f92a2ec3562fb59c49169
|
data/README.md
CHANGED
@@ -9,11 +9,12 @@
|
|
9
9
|
:dna: [HTSlib](https://github.com/samtools/htslib) - for Ruby
|
10
10
|
|
11
11
|
Ruby-htslib is the Ruby bindings to HTSlib, a C library for processing high throughput sequencing (HTS) data.
|
12
|
-
It will provide APIs to read and write file formats such as SAM, BAM, VCF, and BCF.
|
12
|
+
It will provide APIs to read and write file formats such as [SAM, BAM, VCF, and BCF](http://samtools.github.io/hts-specs/).
|
13
13
|
|
14
14
|
:apple: Feel free to fork it out if you can develop it!
|
15
15
|
|
16
16
|
:bowtie: alpha stage.
|
17
|
+
|
17
18
|
## Requirements
|
18
19
|
|
19
20
|
* [Ruby](https://github.com/ruby/ruby) 2.7 or above.
|
@@ -92,8 +93,8 @@ bundle exec rake htslib:build
|
|
92
93
|
bundle exec rake test
|
93
94
|
```
|
94
95
|
|
95
|
-
|
96
|
-
|
96
|
+
* Actively use the advanced features of Ruby.
|
97
|
+
* Consider compatibility with [htslib.cr](https://github.com/bio-crystal/htslib.cr) to some extent.
|
97
98
|
|
98
99
|
#### FFI Extensions
|
99
100
|
|
data/lib/hts/bam/cigar.rb
CHANGED
data/lib/hts/bam/flag.rb
CHANGED
@@ -85,8 +85,12 @@ module HTS
|
|
85
85
|
has_flag? LibHTS::BAM_FSUPPLEMENTARY
|
86
86
|
end
|
87
87
|
|
88
|
-
def has_flag?(
|
89
|
-
@value
|
88
|
+
def has_flag?(m)
|
89
|
+
(@value & m) != 0
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_s
|
93
|
+
"0x#{format('%x', @value)}\t#{@value}\t#{LibHTS.bam_flag2str(@value)}"
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|
data/lib/hts/bam/header.rb
CHANGED
@@ -18,6 +18,10 @@ module HTS
|
|
18
18
|
@sam_hdr.to_ptr
|
19
19
|
end
|
20
20
|
|
21
|
+
def target_count
|
22
|
+
@sam_hdr[:n_targets]
|
23
|
+
end
|
24
|
+
|
21
25
|
# FIXME: better name?
|
22
26
|
def seqs
|
23
27
|
Array.new(@sam_hdr[:n_targets]) do |i|
|
@@ -25,7 +29,7 @@ module HTS
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
32
|
+
def to_s
|
29
33
|
LibHTS.sam_hdr_str(@sam_hdr)
|
30
34
|
end
|
31
35
|
end
|
data/lib/hts/bam/record.rb
CHANGED
@@ -69,7 +69,6 @@ module HTS
|
|
69
69
|
|
70
70
|
# returns the chromosome or '' if not mapped.
|
71
71
|
def chrom
|
72
|
-
tid = @bam1[:core][:tid]
|
73
72
|
return "" if tid == -1
|
74
73
|
|
75
74
|
LibHTS.sam_hdr_tid2name(@header, tid)
|
@@ -77,10 +76,10 @@ module HTS
|
|
77
76
|
|
78
77
|
# returns the chromosome of the mate or '' if not mapped.
|
79
78
|
def mate_chrom
|
80
|
-
|
81
|
-
return "" if
|
79
|
+
mtid = mate_tid
|
80
|
+
return "" if mtid == -1
|
82
81
|
|
83
|
-
LibHTS.sam_hdr_tid2name(@header,
|
82
|
+
LibHTS.sam_hdr_tid2name(@header, mtid)
|
84
83
|
end
|
85
84
|
|
86
85
|
def strand
|
@@ -168,6 +167,11 @@ module HTS
|
|
168
167
|
return nil if aux.null?
|
169
168
|
|
170
169
|
t = aux.read_string(1)
|
170
|
+
|
171
|
+
# A (character), B (general array),
|
172
|
+
# f (real number), H (hexadecimal array),
|
173
|
+
# i (integer), or Z (string).
|
174
|
+
|
171
175
|
case t
|
172
176
|
when "i", "I", "c", "C", "s", "S"
|
173
177
|
LibHTS.bam_aux2i(aux)
|
@@ -175,8 +179,8 @@ module HTS
|
|
175
179
|
LibHTS.bam_aux2f(aux)
|
176
180
|
when "Z", "H"
|
177
181
|
LibHTS.bam_aux2Z(aux)
|
178
|
-
when "A"
|
179
|
-
LibHTS.bam_aux2A(aux)
|
182
|
+
when "A" # char
|
183
|
+
LibHTS.bam_aux2A(aux).chr
|
180
184
|
end
|
181
185
|
end
|
182
186
|
|
data/lib/hts/bcf/format.rb
CHANGED
@@ -36,8 +36,9 @@ module HTS
|
|
36
36
|
format_values.call(LibHTS::BCF_HT_FLAG)
|
37
37
|
.read_int == 1
|
38
38
|
when :string, :str
|
39
|
+
raise NotImplementedError, "String type not implemented yet."
|
39
40
|
format_values.call(LibHTS::BCF_HT_STR)
|
40
|
-
.
|
41
|
+
.read_string
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
data/lib/hts/bcf/header.rb
CHANGED
@@ -3,16 +3,23 @@
|
|
3
3
|
module HTS
|
4
4
|
class Bcf
|
5
5
|
class Header
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(bcf_hdr)
|
7
|
+
@bcf_hdr = bcf_hdr
|
8
8
|
end
|
9
9
|
|
10
10
|
def struct
|
11
|
-
@
|
11
|
+
@bcf_hdr
|
12
12
|
end
|
13
13
|
|
14
14
|
def to_ptr
|
15
|
-
@
|
15
|
+
@bcf_hdr.to_ptr
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
kstr = LibHTS::KString.new
|
20
|
+
raise "Failed to get header string" unless LibHTS.bcf_hdr_format(@bcf_hdr, 0, kstr)
|
21
|
+
|
22
|
+
kstr[:s]
|
16
23
|
end
|
17
24
|
end
|
18
25
|
end
|
data/lib/hts/bcf/info.rb
CHANGED
data/lib/hts/bcf/record.rb
CHANGED
@@ -16,7 +16,7 @@ module HTS
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def to_ptr
|
19
|
-
@
|
19
|
+
@bcf1.to_ptr
|
20
20
|
end
|
21
21
|
|
22
22
|
# def inspect; end
|
@@ -64,6 +64,8 @@ module HTS
|
|
64
64
|
d[:flt].get_array_of_int(0, n_flt).map do |i|
|
65
65
|
LibHTS.bcf_hdr_int2id(@bcf.header.struct, LibHTS::BCF_DT_ID, i)
|
66
66
|
end
|
67
|
+
else
|
68
|
+
raise "Unexpected number of filters. n_flt: #{n_flt}"
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -80,13 +82,14 @@ module HTS
|
|
80
82
|
LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_STR)
|
81
83
|
@bcf1[:d][:allele].get_array_of_pointer(
|
82
84
|
FFI::TYPE_POINTER.size, @bcf1[:n_allele] - 1
|
83
|
-
).map
|
85
|
+
).map(&:read_string)
|
84
86
|
end
|
85
87
|
|
86
88
|
def alleles
|
89
|
+
LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_STR)
|
87
90
|
@bcf1[:d][:allele].get_array_of_pointer(
|
88
91
|
0, @bcf1[:n_allele]
|
89
|
-
).map
|
92
|
+
).map(&:read_string)
|
90
93
|
end
|
91
94
|
|
92
95
|
def info
|
data/lib/hts/bcf.rb
CHANGED
data/lib/hts/ffi_ext/struct.rb
CHANGED
data/lib/hts/libhts/hts.rb
CHANGED
@@ -89,6 +89,12 @@ module HTS
|
|
89
89
|
%i[HFILE string string],
|
90
90
|
HtsFile.by_ref
|
91
91
|
|
92
|
+
# For output streams, flush any buffered data
|
93
|
+
attach_function \
|
94
|
+
:hts_flush,
|
95
|
+
[HtsFile],
|
96
|
+
:int
|
97
|
+
|
92
98
|
# Close a file handle, flushing buffered data for output streams
|
93
99
|
attach_function \
|
94
100
|
:hts_close,
|