htslib 0.0.2 → 0.0.6

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.
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.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2022-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffi-bitfield
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pkg-config
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +67,7 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: minitest
70
+ name: irb
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -67,7 +81,7 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rake
84
+ name: minitest
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
@@ -81,7 +95,7 @@ dependencies:
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: rubocop
98
+ name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -108,7 +122,7 @@ dependencies:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
- description:
125
+ description:
112
126
  email:
113
127
  - 2xijok@gmail.com
114
128
  executables: []
@@ -118,31 +132,38 @@ files:
118
132
  - LICENSE.txt
119
133
  - README.md
120
134
  - lib/hts/bam.rb
121
- - lib/hts/bam/alignment.rb
122
135
  - lib/hts/bam/cigar.rb
136
+ - lib/hts/bam/flag.rb
123
137
  - lib/hts/bam/header.rb
124
- - lib/hts/fai.rb
125
- - lib/hts/ffi.rb
126
- - lib/hts/ffi/bgzf.rb
127
- - lib/hts/ffi/constants.rb
128
- - lib/hts/ffi/faidx.rb
129
- - lib/hts/ffi/hfile.rb
130
- - lib/hts/ffi/hts.rb
131
- - lib/hts/ffi/kfunc.rb
132
- - lib/hts/ffi/sam.rb
133
- - lib/hts/ffi/tbx.rb
134
- - lib/hts/ffi/vcf.rb
135
- - lib/hts/tbx.rb
136
- - lib/hts/vcf.rb
137
- - lib/hts/vcf/header.rb
138
- - lib/hts/vcf/variant.rb
138
+ - lib/hts/bam/record.rb
139
+ - lib/hts/bcf.rb
140
+ - lib/hts/bcf/format.rb
141
+ - lib/hts/bcf/header.rb
142
+ - lib/hts/bcf/info.rb
143
+ - lib/hts/bcf/record.rb
144
+ - lib/hts/faidx.rb
145
+ - lib/hts/ffi_ext/README.md
146
+ - lib/hts/ffi_ext/struct.rb
147
+ - lib/hts/libhts.rb
148
+ - lib/hts/libhts/bgzf.rb
149
+ - lib/hts/libhts/constants.rb
150
+ - lib/hts/libhts/faidx.rb
151
+ - lib/hts/libhts/hfile.rb
152
+ - lib/hts/libhts/hts.rb
153
+ - lib/hts/libhts/kfunc.rb
154
+ - lib/hts/libhts/sam.rb
155
+ - lib/hts/libhts/sam_funcs.rb
156
+ - lib/hts/libhts/tbx.rb
157
+ - lib/hts/libhts/vcf.rb
158
+ - lib/hts/libhts/vcf_funcs.rb
159
+ - lib/hts/tabix.rb
139
160
  - lib/hts/version.rb
140
161
  - lib/htslib.rb
141
162
  homepage: https://github.com/kojix2/ruby-htslib
142
163
  licenses:
143
164
  - MIT
144
165
  metadata: {}
145
- post_install_message:
166
+ post_install_message:
146
167
  rdoc_options: []
147
168
  require_paths:
148
169
  - lib
@@ -150,15 +171,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
171
  requirements:
151
172
  - - ">="
152
173
  - !ruby/object:Gem::Version
153
- version: '2.4'
174
+ version: '2.7'
154
175
  required_rubygems_version: !ruby/object:Gem::Requirement
155
176
  requirements:
156
177
  - - ">="
157
178
  - !ruby/object:Gem::Version
158
179
  version: '0'
159
180
  requirements: []
160
- rubygems_version: 3.2.15
161
- signing_key:
181
+ rubygems_version: 3.3.3
182
+ signing_key:
162
183
  specification_version: 4
163
184
  summary: HTSlib bindings for Ruby
164
185
  test_files: []
@@ -1,155 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Based on hts-python
4
- # https://github.com/quinlan-lab/hts-python
5
-
6
- module HTS
7
- class Bam
8
- class Alignment
9
- def initialize(bam1_t, bam_hdr_t)
10
- @b = bam1_t
11
- @h = bam_hdr_t
12
- end
13
-
14
- # def initialize_copy
15
- # super
16
- # end
17
-
18
- def self.rom_sam_str; end
19
-
20
- def tags; end
21
-
22
- # Read (query) name.
23
- def qname
24
- FFI.bam_get_qname(@b).read_string
25
- end
26
-
27
- # Set (query) name.
28
- # def qname=(name)
29
- # raise 'Not Implemented'
30
- # end
31
-
32
- # returns the chromosome of the mate or '' if not mapped.
33
- def mate_chrom
34
- tid = @b[:core][:mtid]
35
- return '' if tid == -1
36
-
37
- FFI.sam_hdr_tid2name(@h, tid)
38
- end
39
-
40
- # returns the tid of the mate or -1 if not mapped.
41
- def mate_tid
42
- @b[:core][:mtid]
43
- end
44
-
45
- # returns the tid of the alignment or -1 if not mapped.
46
- def tid
47
- @b[:core][:tid]
48
- end
49
-
50
- # mate position
51
- def mate_pos
52
- @b[:core][:mpos]
53
- end
54
-
55
- # returns 0-based start position.
56
- def start
57
- @b[:core][:pos]
58
- end
59
-
60
- # returns end position of the read.
61
- def stop
62
- FFI.bam_endpos @b
63
- end
64
-
65
- # returns the chromosome or '' if not mapped.
66
- def chrom
67
- tid = @b[:core][:tid]
68
- return '' if tid == -1
69
-
70
- FFI.sam_hdr_tid2name(@h, tid)
71
- end
72
-
73
- def strand
74
- FFI.bam_is_rev(@b) ? '-' : '+'
75
- end
76
-
77
- # def start=(v)
78
- # raise 'Not Implemented'
79
- # end
80
-
81
- # insert size
82
- def isize
83
- @b[:core][:isize]
84
- end
85
-
86
- # mapping quality
87
- def mapping_quality
88
- @b[:core][:qual]
89
- end
90
-
91
- # returns a `Cigar` object.
92
- def cigar
93
- Cigar.new(FFI.bam_get_cigar(@b), @b[:core][:n_cigar])
94
- end
95
-
96
- def qlen
97
- FFI.bam_cigar2qlen(
98
- @b[:core][:n_cigar],
99
- FFI.bam_get_cigar(@b)
100
- )
101
- end
102
-
103
- def rlen
104
- FFI.bam_cigar2rlen(
105
- @b[:core][:n_cigar],
106
- FFI.bam_get_cigar(@b)
107
- )
108
- end
109
-
110
- # return the read sequence
111
- def sequence
112
- seq_nt16_str = '=ACMGRSVTWYHKDBN'
113
- r = FFI.bam_get_seq(@b)
114
- Array.new(@b[:core][:l_qseq]) do |i|
115
- seq_nt16_str[FFI.bam_seqi(r, i)]
116
- end.join
117
- end
118
-
119
- def base_at(n)
120
- n += @b[:core][:l_qseq] if n < 0
121
- seq_nt16_str = '=ACMGRSVTWYHKDBN'
122
- return '.' if (n >= @b[:core][:l_qseq]) || (n < 0) # eg. base_at(-1000)
123
-
124
- r = FFI.bam_get_seq(@b)
125
- seq_nt16_str[FFI.bam_seqi(r, n)]
126
- end
127
-
128
- def base_qualities
129
- q_ptr = FFI.bam_get_qual(@b)
130
- q_ptr.read_array_of_uint8(@b[:core][:l_qseq])
131
- end
132
-
133
- def base_quality_at(n)
134
- n += @b[:core][:l_qseq] if n < 0 # eg. base_quality_at(-1000)
135
- return 0 if (n >= @b[:core][:l_qseq]) || (n < 0)
136
-
137
- q_ptr = FFI.bam_get_qual(@b)
138
- q_ptr.get_uint8(n)
139
- end
140
-
141
- def flag_str
142
- FFI.bam_flag2str(flag)
143
- end
144
-
145
- # returns a `Flag` object.
146
- def flag
147
- @b[:core][:flag]
148
- end
149
-
150
- # TODO:
151
- # def eql?
152
- # def hash
153
- end
154
- end
155
- end
data/lib/hts/fai.rb DELETED
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Based on hts-python
4
- # https://github.com/quinlan-lab/hts-python
5
-
6
- module HTS
7
- class Fai
8
- # FIXME: API
9
- def self.open(path)
10
- fai = new(path)
11
- if block_given?
12
- yield(fai)
13
- fai.close
14
- else
15
- fai
16
- end
17
- end
18
-
19
- def initialize(path)
20
- @path = File.expand_path(path)
21
- @path.delete_suffix!('.fai')
22
- FFI.fai_build(@path) unless File.exist?("#{@path}.fai")
23
- @fai = FFI.fai_load(@path)
24
- raise if @fai.null?
25
-
26
- # at_exit{FFI.fai_destroy(@fai)}
27
- end
28
-
29
- def close
30
- FFI.fai_destroy(@fai)
31
- end
32
-
33
- # the number of sequences in the index.
34
- def size
35
- FFI.faidx_nseq(@fai)
36
- end
37
- alias length size
38
-
39
- # return the length of the requested chromosome.
40
- def chrom_size(chrom)
41
- raise ArgumentError, 'Expect chrom to be String or Symbol' unless chrom.is_a?(String) || chrom.is_a?(Symbol)
42
-
43
- chrom = chrom.to_s
44
- result = FFI.faidx_seq_len(@fai, chrom)
45
- result == -1 ? nil : result
46
- end
47
- alias chrom_length chrom_size
48
-
49
- # FIXME: naming and syntax
50
- def cget; end
51
-
52
- # FIXME: naming and syntax
53
- def get; end
54
-
55
- # __iter__
56
- end
57
- end
data/lib/hts/ffi.rb DELETED
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- module FFI
5
- extend ::FFI::Library
6
-
7
- begin
8
- ffi_lib HTS.ffi_lib
9
- rescue LoadError => e
10
- raise LoadError, "#{e}\nCould not find #{HTS.ffi_lib}"
11
- end
12
-
13
- def self.attach_function(*)
14
- super
15
- rescue ::FFI::NotFoundError => e
16
- warn e.message
17
- end
18
- end
19
- end
20
-
21
- module FFI
22
- class Struct
23
- class << self
24
- def union_layout(*args)
25
- Class.new(FFI::Union) { layout(*args) }
26
- end
27
-
28
- def struct_layout(*args)
29
- Class.new(FFI::Struct) { layout(*args) }
30
- end
31
- end
32
- end
33
-
34
- class BitStruct < Struct
35
- class << self
36
- module BitFieldsModule
37
- def [](name)
38
- bit_fields = self.class.bit_fields_hash_table
39
- parent, start, width = bit_fields[name]
40
- if parent
41
- (super(parent) >> start) & ((1 << width) - 1)
42
- else
43
- super(name)
44
- end
45
- end
46
- end
47
- private_constant :BitFieldsModule
48
-
49
- attr_reader :bit_fields_hash_table
50
-
51
- def bitfields(*args)
52
- unless instance_variable_defined?(:@bit_fields_hash_table)
53
- @bit_fields_hash_table = {}
54
- prepend BitFieldsModule
55
- end
56
-
57
- parent = args.shift
58
- labels = []
59
- widths = []
60
- args.each_slice(2) do |l, w|
61
- labels << l
62
- widths << w
63
- end
64
- starts = widths.inject([0]) do |result, w|
65
- result << (result.last + w)
66
- end
67
- labels.zip(starts, widths).each do |l, s, w|
68
- @bit_fields_hash_table[l] = [parent, s, w]
69
- end
70
- end
71
- end
72
- end
73
- end
74
-
75
- require_relative 'ffi/constants'
76
-
77
- # alphabetical order
78
- require_relative 'ffi/bgzf'
79
- require_relative 'ffi/faidx'
80
- require_relative 'ffi/hfile'
81
- require_relative 'ffi/hts'
82
- require_relative 'ffi/sam'
83
- require_relative 'ffi/kfunc'
84
- require_relative 'ffi/tbx'
85
- require_relative 'ffi/vcf'
data/lib/hts/tbx.rb DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Based on hts-python
4
- # https://github.com/quinlan-lab/hts-python
5
-
6
- module HTS
7
- class Tbx
8
- def initialize; end
9
-
10
- def build; end
11
-
12
- def sequences; end
13
-
14
- # def __call__\
15
- end
16
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- class VCF
5
- class Header
6
- attr_reader :h
7
-
8
- def initialize(h)
9
- @h = h
10
- end
11
-
12
- # FIXME: better name?
13
- def seqs
14
- Array.new(@h[:n_targets]) do |i|
15
- FFI.sam_hdr_tid2name(@h, i)
16
- end
17
- end
18
-
19
- def text
20
- FFI.sam_hdr_str(@h)
21
- end
22
- end
23
- end
24
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module HTS
4
- class VCF
5
- class Variant
6
- def initialize(bcf_t, vcf)
7
- @c = bcf_t
8
- FFI.bcf_unpack(@c, HTS::FFI::BCF_UN_ALL) # FIXME
9
- @vcf = vcf
10
- end
11
-
12
- # def inspect; end
13
-
14
- def formats; end
15
-
16
- def genotypes; end
17
-
18
- def pos
19
- @c[:pos] + 1 # FIXME
20
- end
21
-
22
- def start
23
- @c[:pos]
24
- end
25
-
26
- def stop
27
- @c[:pos] + @c[:rlen]
28
- end
29
-
30
- def id
31
- @c[:d][:id]
32
- end
33
-
34
- def qual
35
- @c[:qual]
36
- end
37
-
38
- def ref
39
- @c[:d][:allele].get_pointer(0).read_string
40
- end
41
- end
42
- end
43
- end
data/lib/hts/vcf.rb DELETED
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Based on hts-python
4
- # https://github.com/quinlan-lab/hts-python
5
-
6
- require_relative 'vcf/header'
7
- require_relative 'vcf/variant'
8
-
9
- module HTS
10
- class VCF
11
- include Enumerable
12
- attr_reader :file_path, :mode, :header, :htf
13
-
14
- def initialize(file_path, mode = 'r')
15
- @file_path = File.expand_path(file_path)
16
- File.exist?(@file_path) || raise("No such VCF/BCF file - #{@file_path}")
17
-
18
- @mode = mode
19
- @htf = FFI.hts_open(@file_path, mode)
20
-
21
- @header = VCF::Header.new(FFI.bcf_hdr_read(@htf))
22
-
23
- @c = FFI.bcf_init
24
- end
25
-
26
- # def inspect; end
27
-
28
- def each(&block)
29
- block.call(Variant.new(@c, self)) while FFI.bcf_read(@htf, @header.h, @c) != -1
30
- end
31
-
32
- def seq(tid); end
33
-
34
- def n_samples
35
- FFI.bcf_hdr_nsamples(header.h)
36
- end
37
- end
38
-
39
- class Format
40
- def initialize; end
41
- end
42
- end