htslib 0.2.9 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c98f3937d65f091e9e834060f3a94578034d1bf55e7bc372e5ed388e618a6da4
4
- data.tar.gz: 8e180044fef210935695bc60c0352b747b570b705f3ce9318b7538d19ddaf645
3
+ metadata.gz: ea68a4c331c9a404cfce2bf86fea386985e96ee3b76ae25e9d9b701593294880
4
+ data.tar.gz: d826e59f66e20bc40bc47c2033295abe2b3aceab8cb9d5af3d4d41309e448732
5
5
  SHA512:
6
- metadata.gz: 5324913bdbe97580fee1e54b6268f22aed2a0b84d449c8a4f62529981c82a57d6ae5cea7cc77ff1be7332425eea259bfe5daa1107b6144e36ef40bb4997dd28f
7
- data.tar.gz: 7b230700951223aeda09d64fac7cca44d734d54ec03a7836c5a0fb036e552854db80b9ecaf57aa478e317c684e4712f2f03244e02474fd2ea53a4b93346d1371
6
+ metadata.gz: 646dca4eb44c96a67020f57a090c26715b003521c9c6afffad1becf031576c334ea03c99b61f795a35932935535c53a1899a960ab986480cb3f5eef5b9913b96
7
+ data.tar.gz: e1cc5d9357932e04cebae1aaa5a8dc7024e0755584ea21999b18004dba76726c10b23276ee6d98fc1580ffb5aad45aeb12fd3e1bf94cfc45fdee70aefda87f91
data/README.md CHANGED
@@ -6,6 +6,9 @@
6
6
  [![DOI](https://zenodo.org/badge/247078205.svg)](https://zenodo.org/badge/latestdoi/247078205)
7
7
  [![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/htslib)
8
8
 
9
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/kojix2/ruby-htslib)
10
+ [![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Fruby-htslib%2Flines)](https://tokei.kojix2.net/github/kojix2/ruby-htslib)
11
+
9
12
  Ruby-htslib is the [Ruby](https://www.ruby-lang.org) bindings to [HTSlib](https://github.com/samtools/htslib), a C library for high-throughput sequencing data formats. It allows you to read and write file formats commonly used in genomics, such as [SAM, BAM, VCF, and BCF](http://samtools.github.io/hts-specs/), in the Ruby language.
10
13
 
11
14
  :apple: Feel free to fork it!
@@ -162,6 +165,8 @@ Try Crystal. [HTS.cr](https://github.com/bio-cr/hts.cr) is implemented in Crysta
162
165
 
163
166
  ## Development
164
167
 
168
+ ![Diagram](diagram.svg)
169
+
165
170
  #### Compile from source code
166
171
 
167
172
  [GNU Autotools](https://en.wikipedia.org/wiki/GNU_Autotools) is required to compile htslib.
data/lib/hts/bam.rb CHANGED
@@ -7,6 +7,8 @@ require_relative "bam/header"
7
7
  require_relative "bam/cigar"
8
8
  require_relative "bam/flag"
9
9
  require_relative "bam/record"
10
+ # require_relative "bam/pileup"
11
+ # require_relative "bam/pileup_entry"
10
12
 
11
13
  module HTS
12
14
  # A class for working with SAM, BAM, CRAM files.
@@ -30,7 +32,7 @@ module HTS
30
32
  def initialize(file_name, mode = "r", index: nil, fai: nil, threads: nil,
31
33
  build_index: false)
32
34
  if block_given?
33
- message = "HTS::Bam.new() dose not take block; Please use HTS::Bam.open() instead"
35
+ message = "HTS::Bam.new() does not take block; Please use HTS::Bam.open() instead"
34
36
  raise message
35
37
  end
36
38
 
@@ -44,6 +46,17 @@ module HTS
44
46
 
45
47
  raise Errno::ENOENT, "Failed to open #{@file_name}" if @hts_file.null?
46
48
 
49
+ # Auto-detect and set reference for CRAM files
50
+ if fai.nil? && @file_name.end_with?(".cram")
51
+ # Try to find reference file in the same directory
52
+ base_name = File.basename(@file_name, ".cram")
53
+ dir_name = File.dirname(@file_name)
54
+ potential_ref = File.join(dir_name, "#{base_name}.fa")
55
+
56
+ # For remote URLs, assume reference exists; for local files, check existence
57
+ fai = potential_ref if @file_name.start_with?("http") || File.exist?(potential_ref)
58
+ end
59
+
47
60
  if fai
48
61
  r = LibHTS.hts_set_fai_filename(@hts_file, fai)
49
62
  raise "Failed to load fasta index: #{fai}" if r < 0
@@ -67,7 +80,7 @@ module HTS
67
80
  else
68
81
  warn "Create index for #{@file_name}"
69
82
  end
70
- case LibHTS.sam_index_build3(@file_name, index_name, min_shift, (@nthreads || threads))
83
+ case LibHTS.sam_index_build3(@file_name, index_name, min_shift, @nthreads || threads)
71
84
  when 0 # successful
72
85
  when -1 then raise "indexing failed"
73
86
  when -2 then raise "opening #{@file_name} failed"
@@ -95,7 +108,7 @@ module HTS
95
108
  end
96
109
 
97
110
  def close
98
- LibHTS.hts_idx_destroy(@idx) if @idx&.null?
111
+ LibHTS.hts_idx_destroy(@idx) if @idx && !@idx.null?
99
112
  @idx = nil
100
113
  super
101
114
  end
@@ -141,7 +154,7 @@ module HTS
141
154
  alias isize insert_size
142
155
  alias mpos mate_pos
143
156
 
144
- # FXIME: experimental
157
+ # FIXME: experimental
145
158
  def aux(tag)
146
159
  check_closed
147
160
 
@@ -203,6 +216,10 @@ module HTS
203
216
  end
204
217
  end
205
218
 
219
+ # def pileup
220
+ # Pileup.new(self)
221
+ # end
222
+
206
223
  private
207
224
 
208
225
  def queryi(tid, beg, end_, copy: false, &block)
data/lib/hts/bcf.rb CHANGED
@@ -30,7 +30,7 @@ module HTS
30
30
  def initialize(file_name, mode = "r", index: nil, threads: nil,
31
31
  build_index: false)
32
32
  if block_given?
33
- message = "HTS::Bcf.new() dose not take block; Please use HTS::Bcf.open() instead"
33
+ message = "HTS::Bcf.new() does not take block; Please use HTS::Bcf.open() instead"
34
34
  raise message
35
35
  end
36
36
 
@@ -62,7 +62,7 @@ module HTS
62
62
  else
63
63
  warn "Create index for #{@file_name}"
64
64
  end
65
- case LibHTS.bcf_index_build3(@file_name, index_name, min_shift, (@nthreads || threads))
65
+ case LibHTS.bcf_index_build3(@file_name, index_name, min_shift, @nthreads || threads)
66
66
  when 0 # successful
67
67
  when -1 then raise "indexing failed"
68
68
  when -2 then raise "opening #{@file_name} failed"
@@ -90,7 +90,7 @@ module HTS
90
90
  end
91
91
 
92
92
  def close
93
- LibHTS.hts_idx_destroy(@idx) unless @idx&.null?
93
+ LibHTS.hts_idx_destroy(@idx) if @idx && !@idx.null?
94
94
  @idx = nil
95
95
  super
96
96
  end
data/lib/hts/faidx.rb CHANGED
@@ -21,7 +21,7 @@ module HTS
21
21
 
22
22
  def initialize(file_name)
23
23
  if block_given?
24
- message = "HTS::Faidx.new() dose not take block; Please use HTS::Faidx.open() instead"
24
+ message = "HTS::Faidx.new() does not take block; Please use HTS::Faidx.open() instead"
25
25
  raise message
26
26
  end
27
27
 
@@ -158,7 +158,7 @@ module HTS
158
158
  :specific, :pointer
159
159
  end
160
160
 
161
- class HtsIdx < FFI::Struct # FIXME: ManagedStruct
161
+ class HtsIdx < FFI::Struct
162
162
  layout \
163
163
  :fmt, :int,
164
164
  :min_shift, :int,
@@ -189,9 +189,9 @@ module HTS
189
189
  :n_unmapped, :uint64
190
190
  )
191
191
 
192
- def self.release(ptr)
193
- LibHTS.hts_idx_destroy(ptr) unless ptr.null?
194
- end
192
+ # def self.release(ptr)
193
+ # LibHTS.hts_idx_destroy(ptr) unless ptr.null?
194
+ # end
195
195
  end
196
196
 
197
197
  class HtsReglist < FFI::Struct
@@ -379,6 +379,10 @@ module HTS
379
379
  :is_refskip, 1,
380
380
  :_reserved, 1,
381
381
  :aux, 27
382
+
383
+ # def self.release(ptr)
384
+ # LibHTS.bam_plp_destroy(ptr) unless ptr.null?
385
+ # end
382
386
  end
383
387
 
384
388
  class TbxConf < FFI::Struct
@@ -105,7 +105,7 @@ module HTS
105
105
 
106
106
  # Modifies a single base in the bam structure.
107
107
  def bam_set_seqi(s, i, b)
108
- s[i >> 1] = (s[i >> 1] & (0xf0 >> ((~i & 1) << 2))) | ((b) << ((~i & 1) << 2))
108
+ s[i >> 1] = (s[i >> 1] & (0xf0 >> ((~i & 1) << 2))) | (b << ((~i & 1) << 2))
109
109
  end
110
110
 
111
111
  # Returns the SAM formatted text of the \@HD header line
@@ -167,7 +167,7 @@ module HTS
167
167
 
168
168
  # Conversion between alleles indexes to Number=G genotype index (assuming diploid, all 0-based)
169
169
  def bcf_alleles2gt(a, b)
170
- ((a) > (b) ? (a * (a + 1) / 2 + b) : (b * (b + 1) / 2 + a))
170
+ (a > b ? (a * (a + 1) / 2 + b) : (b * (b + 1) / 2 + a))
171
171
  end
172
172
 
173
173
  # Get INFO values
data/lib/hts/tabix.rb CHANGED
@@ -24,7 +24,7 @@ module HTS
24
24
 
25
25
  def initialize(file_name, index: nil, threads: nil, build_index: false)
26
26
  if block_given?
27
- message = "HTS::Tabix.new() dose not take block; Please use HTS::Tabix.open() instead"
27
+ message = "HTS::Tabix.new() does not take block; Please use HTS::Tabix.open() instead"
28
28
  raise message
29
29
  end
30
30
 
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.9"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htslib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-09-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ffi
@@ -52,7 +51,6 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- description:
56
54
  email:
57
55
  - 2xijok@gmail.com
58
56
  executables: []
@@ -104,7 +102,6 @@ licenses:
104
102
  - MIT
105
103
  metadata:
106
104
  msys2_mingw_dependencies: htslib
107
- post_install_message:
108
105
  rdoc_options: []
109
106
  require_paths:
110
107
  - lib
@@ -119,8 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
116
  - !ruby/object:Gem::Version
120
117
  version: '0'
121
118
  requirements: []
122
- rubygems_version: 3.5.11
123
- signing_key:
119
+ rubygems_version: 3.7.1
124
120
  specification_version: 4
125
121
  summary: HTSlib bindings for Ruby
126
122
  test_files: []