Class: HTS::Faidx
- Inherits:
-
Object
- Object
- HTS::Faidx
- Defined in:
- lib/hts/faidx.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#chrom_names ⇒ Object
return the length of the requested chromosome.
-
#chrom_size(chrom) ⇒ Object
(also: #chrom_length)
return the length of the requested chromosome.
- #close ⇒ Object
-
#initialize(file_name) ⇒ Faidx
constructor
A new instance of Faidx.
-
#length ⇒ Object
(also: #size)
the number of sequences in the index.
- #seq(name, start = nil, stop = nil) ⇒ Object
- #struct ⇒ Object
Constructor Details
#initialize(file_name) ⇒ Faidx
Returns a new instance of Faidx.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hts/faidx.rb', line 21 def initialize(file_name) if block_given? = "HTS::Faidx.new() dose not take block; Please use HTS::Faidx.open() instead" raise end @file_name = file_name @fai = LibHTS.fai_load(@file_name) raise Errno::ENOENT, "Failed to open #{@file_name}" if @fai.null? end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
7 8 9 |
# File 'lib/hts/faidx.rb', line 7 def file_name @file_name end |
Class Method Details
.open(*args, **kw) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hts/faidx.rb', line 9 def self.open(*args, **kw) file = new(*args, **kw) # do not yield return file unless block_given? begin yield file ensure file.close end file end |
Instance Method Details
#chrom_names ⇒ Object
return the length of the requested chromosome.
63 64 65 |
# File 'lib/hts/faidx.rb', line 63 def chrom_names Array.new(length) { |i| LibHTS.faidx_iseq(@fai, i) } end |
#chrom_size(chrom) ⇒ Object Also known as: chrom_length
return the length of the requested chromosome.
53 54 55 56 57 58 59 |
# File 'lib/hts/faidx.rb', line 53 def chrom_size(chrom) raise ArgumentError, "Expect chrom to be String or Symbol" unless chrom.is_a?(String) || chrom.is_a?(Symbol) chrom = chrom.to_s result = LibHTS.faidx_seq_len(@fai, chrom) result == -1 ? nil : result end |
#close ⇒ Object
37 38 39 |
# File 'lib/hts/faidx.rb', line 37 def close LibHTS.fai_destroy(@fai) end |
#length ⇒ Object Also known as: size
the number of sequences in the index.
47 48 49 |
# File 'lib/hts/faidx.rb', line 47 def length LibHTS.faidx_nseq(@fai) end |
#fetch(name) ⇒ Object #fetch(name, start, stop) ⇒ String
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/hts/faidx.rb', line 77 def seq(name, start = nil, stop = nil) name = name.to_s rlen = FFI::MemoryPointer.new(:int) if start.nil? && stop.nil? result = LibHTS.fai_fetch(@fai, name, rlen) else start < 0 && raise(ArgumentError, "Expect start to be >= 0") stop < 0 && raise(ArgumentError, "Expect stop to be >= 0") start > stop && raise(ArgumentError, "Expect start to be <= stop") result = LibHTS.faidx_fetch_seq(@fai, name, start, stop, rlen) end case rlen.read_int when -2 then raise "Invalid chromosome name: #{name}" when -1 then raise "Error fetching sequence: #{name}:#{start}-#{stop}" end result end |
#struct ⇒ Object
33 34 35 |
# File 'lib/hts/faidx.rb', line 33 def struct @fai end |