htslib 0.0.2 → 0.0.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.
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  # Build index for a FASTA or FASTQ or bgzip-compressed FASTA or FASTQ file.
6
6
  attach_function \
7
7
  :fai_build3,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  # Open the named file or URL as a stream
6
6
  attach_function \
7
7
  :hopen,
@@ -1,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  # hts_expand
6
6
  # hts_expand3
7
7
  # hts_resize
8
8
 
9
+ # hts_log.h
10
+ attach_function \
11
+ :hts_get_log_level,
12
+ [],
13
+ HtsLogLevel
14
+
9
15
  attach_function \
10
16
  :hts_lib_shutdown,
11
17
  [],
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  # Log gamma function
6
6
  attach_function \
7
7
  :kf_lgamma,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  # constants
6
6
  BAM_CMATCH = 0
7
7
  BAM_CINS = 1
@@ -14,8 +14,8 @@ module HTS
14
14
  BAM_CDIFF = 8
15
15
  BAM_CBACK = 9
16
16
 
17
- BAM_CIGAR_STR = 'MIDNSHP=XB'
18
- BAM_CIGAR_STR_PADDED = 'MIDNSHP=XB??????'
17
+ BAM_CIGAR_STR = "MIDNSHP=XB"
18
+ BAM_CIGAR_STR_PADDED = "MIDNSHP=XB??????"
19
19
  BAM_CIGAR_SHIFT = 4
20
20
  BAM_CIGAR_MASK = 0xf
21
21
  BAM_CIGAR_TYPE = 0x3C1A7
@@ -441,7 +441,7 @@ module HTS
441
441
  # Get the next read from a SAM/BAM/CRAM iterator
442
442
  def self.sam_itr_next(htsfp, itr, r)
443
443
  # FIXME: check if htsfp is compressed BGZF
444
- hts_log_error('Null iterator') if itr.null?
444
+ hts_log_error("Null iterator") if itr.null?
445
445
  # FIXME: check multi
446
446
  hts_itr_next(htsfp[:fp][:bgzf], itr, r, htsfp)
447
447
  end
@@ -584,52 +584,52 @@ module HTS
584
584
  attach_function \
585
585
  :bam_plp_init,
586
586
  %i[bam_plp_auto_f pointer],
587
- BamPlp
587
+ :bam_plp
588
588
 
589
589
  attach_function \
590
590
  :bam_plp_destroy,
591
- [BamPlp],
591
+ [:bam_plp],
592
592
  :void
593
593
 
594
594
  attach_function \
595
595
  :bam_plp_push,
596
- [BamPlp, Bam1],
596
+ [:bam_plp, Bam1],
597
597
  :int
598
598
 
599
599
  attach_function \
600
600
  :bam_plp_next,
601
- [BamPlp, :pointer, :pointer, :pointer],
602
- :pointer
601
+ %i[bam_plp pointer pointer pointer],
602
+ BamPileup1.by_ref
603
603
 
604
604
  attach_function \
605
605
  :bam_plp_auto,
606
- [BamPlp, :pointer, :pointer, :pointer],
607
- :pointer
606
+ %i[bam_plp pointer pointer pointer],
607
+ BamPileup1.by_ref
608
608
 
609
609
  attach_function \
610
610
  :bam_plp64_next,
611
- [BamPlp, :pointer, :pointer, :pointer],
612
- :pointer
611
+ %i[bam_plp pointer pointer pointer],
612
+ BamPileup1.by_ref
613
613
 
614
614
  attach_function \
615
615
  :bam_plp64_auto,
616
- [BamPlp, :pointer, :pointer, :pointer],
617
- :pointer
616
+ %i[bam_plp pointer pointer pointer],
617
+ BamPileup1.by_ref
618
618
 
619
619
  attach_function \
620
620
  :bam_plp_set_maxcnt,
621
- [BamPlp, :int],
621
+ %i[bam_plp int],
622
622
  :void
623
623
 
624
624
  attach_function \
625
625
  :bam_plp_reset,
626
- [BamPlp],
626
+ [:bam_plp],
627
627
  :void
628
628
 
629
629
  # sets a callback to initialise any per-pileup1_t fields.
630
630
  attach_function \
631
631
  :bam_plp_insertion,
632
- [:pointer, KString, :pointer],
632
+ [BamPileup1, KString, :pointer],
633
633
  :int
634
634
 
635
635
  # sets a callback to initialise any per-pileup1_t fields.
@@ -643,36 +643,36 @@ module HTS
643
643
  attach_function \
644
644
  :bam_mplp_init,
645
645
  %i[int bam_plp_auto_f pointer],
646
- BamMplp.by_ref
646
+ :bam_mplp
647
647
 
648
648
  attach_function \
649
649
  :bam_mplp_init_overlaps,
650
- [BamMplp],
650
+ [:bam_mplp],
651
651
  :int
652
652
 
653
653
  attach_function \
654
654
  :bam_mplp_destroy,
655
- [BamMplp],
655
+ [:bam_mplp],
656
656
  :void
657
657
 
658
658
  attach_function \
659
659
  :bam_mplp_set_maxcnt,
660
- [BamMplp, :int],
660
+ %i[bam_mplp int],
661
661
  :void
662
662
 
663
663
  attach_function \
664
664
  :bam_mplp_auto,
665
- [BamMplp, :pointer, :pointer, :pointer, :pointer],
665
+ %i[bam_mplp pointer pointer pointer pointer], # BamPileup1T
666
666
  :int
667
667
 
668
668
  attach_function \
669
669
  :bam_mplp64_auto,
670
- [BamMplp, :pointer, :pointer, :pointer, :pointer],
670
+ %i[bam_mplp pointer pointer pointer pointer], # BamPileup1T
671
671
  :int
672
672
 
673
673
  attach_function \
674
674
  :bam_mplp_reset,
675
- [BamMplp],
675
+ [:bam_mplp],
676
676
  :void
677
677
 
678
678
  # bam_mplp_constructor
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  attach_function \
6
6
  :tbx_name2id,
7
7
  [Tbx, :string],
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTS
4
- module FFI
4
+ module LibHTS
5
5
  # constants
6
6
  BCF_HL_FLT = 0 # header line
7
7
  BCF_HL_INFO = 1
data/lib/hts/vcf.rb CHANGED
@@ -3,40 +3,40 @@
3
3
  # Based on hts-python
4
4
  # https://github.com/quinlan-lab/hts-python
5
5
 
6
- require_relative 'vcf/header'
7
- require_relative 'vcf/variant'
6
+ require_relative "vcf/header"
7
+ require_relative "vcf/record"
8
8
 
9
9
  module HTS
10
10
  class VCF
11
11
  include Enumerable
12
- attr_reader :file_path, :mode, :header, :htf
12
+ attr_reader :file_path, :mode, :htf, :header
13
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}")
14
+ def initialize(file_path, mode = "r")
15
+ file_path = File.expand_path(file_path)
16
+ raise("No such VCF/BCF file - #{file_path}") unless File.exist?(file_path)
17
17
 
18
- @mode = mode
19
- @htf = FFI.hts_open(@file_path, mode)
18
+ @file_path = file_path
19
+ @mode = mode
20
+ @htf = LibHTS.hts_open(file_path, mode)
21
+ @header = VCF::Header.new(LibHTS.bcf_hdr_read(htf))
20
22
 
21
- @header = VCF::Header.new(FFI.bcf_hdr_read(@htf))
22
-
23
- @c = FFI.bcf_init
23
+ # FIXME: should be defined here?
24
+ @c = LibHTS.bcf_init
24
25
  end
25
26
 
26
27
  # def inspect; end
27
28
 
28
29
  def each(&block)
29
- block.call(Variant.new(@c, self)) while FFI.bcf_read(@htf, @header.h, @c) != -1
30
+ while LibHTS.bcf_read(htf, header.h, @c) != -1
31
+ record = Record.new(@c, self)
32
+ block.call(record)
33
+ end
30
34
  end
31
35
 
32
36
  def seq(tid); end
33
37
 
34
38
  def n_samples
35
- FFI.bcf_hdr_nsamples(header.h)
39
+ LibHTS.bcf_hdr_nsamples(header.h)
36
40
  end
37
41
  end
38
-
39
- class Format
40
- def initialize; end
41
- end
42
42
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://github.com/brentp/hts-nim/blob/master/src/hts/vcf.nim
4
+ # This is a port from Nim.
5
+ # TODO: Make it more like Ruby.
6
+
7
+ module HTS
8
+ class VCF
9
+ class Format
10
+ def initialize; end
11
+
12
+ def delete; end
13
+
14
+ def get; end
15
+
16
+ def set; end
17
+
18
+ # def fields # iterator
19
+ # end
20
+
21
+ def genotypes; end
22
+ end
23
+ end
24
+ end
@@ -12,12 +12,12 @@ module HTS
12
12
  # FIXME: better name?
13
13
  def seqs
14
14
  Array.new(@h[:n_targets]) do |i|
15
- FFI.sam_hdr_tid2name(@h, i)
15
+ LibHTS.sam_hdr_tid2name(@h, i)
16
16
  end
17
17
  end
18
18
 
19
19
  def text
20
- FFI.sam_hdr_str(@h)
20
+ LibHTS.sam_hdr_str(@h)
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://github.com/brentp/hts-nim/blob/master/src/hts/vcf.nim
4
+ # This is a port from Nim.
5
+ # TODO: Make it more like Ruby.
6
+
7
+ module HTS
8
+ class VCF
9
+ class Info
10
+ def initialize; end
11
+
12
+ def has_flag?; end
13
+
14
+ def get; end
15
+
16
+ def set; end
17
+
18
+ def delete; end
19
+
20
+ # def fields # iterator
21
+ # end
22
+ end
23
+ end
24
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module HTS
4
4
  class VCF
5
- class Variant
5
+ class Record
6
6
  def initialize(bcf_t, vcf)
7
7
  @c = bcf_t
8
- FFI.bcf_unpack(@c, HTS::FFI::BCF_UN_ALL) # FIXME
8
+ LibHTS.bcf_unpack(@c, LibHTS::BCF_UN_ALL) # FIXME
9
9
  @vcf = vcf
10
10
  end
11
11
 
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.0.2'
4
+ VERSION = "0.0.3"
5
5
  end
data/lib/htslib.rb CHANGED
@@ -1,27 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ffi'
3
+ require "ffi"
4
4
 
5
- require 'hts/version'
5
+ require "hts/version"
6
6
 
7
7
  module HTS
8
8
  class Error < StandardError; end
9
9
 
10
10
  class << self
11
- attr_accessor :ffi_lib
11
+ attr_accessor :lib_path
12
12
 
13
13
  def search_htslib(name = nil)
14
- name ||= "libhts.#{::FFI::Platform::LIBSUFFIX}"
15
- lib_path = if ENV['HTSLIBDIR']
16
- File.expand_path(name, ENV['HTSLIBDIR'])
14
+ name ||= "libhts.#{FFI::Platform::LIBSUFFIX}"
15
+ lib_path = if ENV["HTSLIBDIR"]
16
+ File.expand_path(name, ENV["HTSLIBDIR"])
17
17
  else
18
18
  File.expand_path("../vendor/#{name}", __dir__)
19
19
  end
20
20
  return lib_path if File.exist?(lib_path)
21
21
 
22
22
  begin
23
- require 'pkg-config'
24
- lib_dir = PKGConfig.variable('htslib', 'libdir')
23
+ require "pkg-config"
24
+ lib_dir = PKGConfig.variable("htslib", "libdir")
25
25
  lib_path = File.expand_path(name, lib_dir)
26
26
  rescue PackageConfig::NotFoundError
27
27
  warn "htslib.pc was not found in the pkg-config search path."
@@ -32,17 +32,14 @@ module HTS
32
32
  end
33
33
  end
34
34
 
35
- self.ffi_lib = search_htslib
35
+ self.lib_path = search_htslib
36
36
 
37
- # You can change the path of the shared library with `HTS.ffi_lib=`
38
- # before calling the FFI module.
39
- autoload :FFI, 'hts/ffi'
37
+ # You can change the path of the shared library with `HTS.lib_path=`
38
+ # before calling the LibHTS module.
39
+ autoload :LibHTS, "hts/libhts"
40
40
  end
41
41
 
42
- # alias
43
- HTSlib = HTS
44
-
45
- require_relative 'hts/bam'
46
- require_relative 'hts/fai'
47
- require_relative 'hts/tbx'
48
- require_relative 'hts/vcf'
42
+ require_relative "hts/bam"
43
+ require_relative "hts/fai"
44
+ require_relative "hts/tbx"
45
+ require_relative "hts/vcf"
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: irb
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rake
70
+ name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -118,24 +118,27 @@ files:
118
118
  - LICENSE.txt
119
119
  - README.md
120
120
  - lib/hts/bam.rb
121
- - lib/hts/bam/alignment.rb
122
121
  - lib/hts/bam/cigar.rb
122
+ - lib/hts/bam/flag.rb
123
123
  - lib/hts/bam/header.rb
124
+ - lib/hts/bam/record.rb
124
125
  - 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
126
+ - lib/hts/libhts.rb
127
+ - lib/hts/libhts/bgzf.rb
128
+ - lib/hts/libhts/constants.rb
129
+ - lib/hts/libhts/faidx.rb
130
+ - lib/hts/libhts/hfile.rb
131
+ - lib/hts/libhts/hts.rb
132
+ - lib/hts/libhts/kfunc.rb
133
+ - lib/hts/libhts/sam.rb
134
+ - lib/hts/libhts/tbx.rb
135
+ - lib/hts/libhts/vcf.rb
135
136
  - lib/hts/tbx.rb
136
137
  - lib/hts/vcf.rb
138
+ - lib/hts/vcf/format.rb
137
139
  - lib/hts/vcf/header.rb
138
- - lib/hts/vcf/variant.rb
140
+ - lib/hts/vcf/info.rb
141
+ - lib/hts/vcf/record.rb
139
142
  - lib/hts/version.rb
140
143
  - lib/htslib.rb
141
144
  homepage: https://github.com/kojix2/ruby-htslib