Class: HTS::Bcf::Header
- Inherits:
-
Object
- Object
- HTS::Bcf::Header
- Defined in:
- lib/hts/bcf/header.rb
Overview
A class for working with VCF records. NOTE: This class has a lot of methods that are not stable. The method names and the number of arguments may change in the future.
Instance Method Summary collapse
- #add_sample(sample, sync: true) ⇒ Object
- #append(line) ⇒ Object
-
#delete(bcf_hl_type, key) ⇒ Object
FIXME.
- #get_hrec(bcf_hl_type, key, value, str_class = nil) ⇒ Object
- #get_version ⇒ Object
- #id2name(id) ⇒ Object
-
#initialize(arg = nil) {|_self| ... } ⇒ Header
constructor
A new instance of Header.
- #merge(hdr) ⇒ Object
- #name2id(name) ⇒ Object
- #nsamples ⇒ Object
- #read_bcf(fname) ⇒ Object
- #samples ⇒ Object
- #seqnames ⇒ Object
- #set_version(version) ⇒ Object
- #struct ⇒ Object
- #sync ⇒ Object
- #to_ptr ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(arg = nil) {|_self| ... } ⇒ Header
Returns a new instance of Header.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hts/bcf/header.rb', line 11 def initialize(arg = nil) case arg when LibHTS::HtsFile @bcf_hdr = LibHTS.bcf_hdr_read(arg) when LibHTS::BcfHdr @bcf_hdr = arg when nil @bcf_hdr = LibHTS.bcf_hdr_init("w") else raise TypeError, "Invalid argument" end yield self if block_given? end |
Instance Method Details
#add_sample(sample, sync: true) ⇒ Object
53 54 55 56 |
# File 'lib/hts/bcf/header.rb', line 53 def add_sample(sample, sync: true) LibHTS.bcf_hdr_add_sample(@bcf_hdr, sample) self.sync if sync end |
#append(line) ⇒ Object
70 71 72 |
# File 'lib/hts/bcf/header.rb', line 70 def append(line) LibHTS.bcf_hdr_append(@bcf_hdr, line) end |
#delete(bcf_hl_type, key) ⇒ Object
FIXME
74 75 76 77 |
# File 'lib/hts/bcf/header.rb', line 74 def delete(bcf_hl_type, key) # FIXME type = bcf_hl_type_to_int(bcf_hl_type) LibHTS.bcf_hdr_remove(@bcf_hdr, type, key) end |
#get_hrec(bcf_hl_type, key, value, str_class = nil) ⇒ Object
79 80 81 82 83 |
# File 'lib/hts/bcf/header.rb', line 79 def get_hrec(bcf_hl_type, key, value, str_class = nil) type = bcf_hl_type_to_int(bcf_hl_type) hrec = LibHTS.bcf_hdr_get_hrec(@bcf_hdr, type, key, value, str_class) HeaderRecord.new(hrec) end |
#get_version ⇒ Object
34 35 36 |
# File 'lib/hts/bcf/header.rb', line 34 def get_version LibHTS.bcf_hdr_get_version(@bcf_hdr) end |
#id2name(id) ⇒ Object
103 104 105 |
# File 'lib/hts/bcf/header.rb', line 103 def id2name(id) LibHTS.bcf_hdr_id2name(@bcf_hdr, id) end |
#merge(hdr) ⇒ Object
58 59 60 |
# File 'lib/hts/bcf/header.rb', line 58 def merge(hdr) LibHTS.bcf_hdr_merge(@bcf_hdr, hdr.struct) end |
#name2id(name) ⇒ Object
99 100 101 |
# File 'lib/hts/bcf/header.rb', line 99 def name2id(name) LibHTS.bcf_hdr_name2id(@bcf_hdr, name) end |
#nsamples ⇒ Object
42 43 44 |
# File 'lib/hts/bcf/header.rb', line 42 def nsamples LibHTS.bcf_hdr_nsamples(@bcf_hdr) end |
#read_bcf(fname) ⇒ Object
66 67 68 |
# File 'lib/hts/bcf/header.rb', line 66 def read_bcf(fname) LibHTS.bcf_hdr_set(@bcf_hdr, fname) end |
#samples ⇒ Object
46 47 48 49 50 51 |
# File 'lib/hts/bcf/header.rb', line 46 def samples # bcf_hdr_id2name is macro function @bcf_hdr[:samples] .read_array_of_pointer(nsamples) .map(&:read_string) end |
#seqnames ⇒ Object
85 86 87 88 89 90 |
# File 'lib/hts/bcf/header.rb', line 85 def seqnames n = FFI::MemoryPointer.new(:int) names = LibHTS.bcf_hdr_seqnames(@bcf_hdr, n) names.read_array_of_pointer(n.read_int) .map(&:read_string) end |
#set_version(version) ⇒ Object
38 39 40 |
# File 'lib/hts/bcf/header.rb', line 38 def set_version(version) LibHTS.bcf_hdr_set_version(@bcf_hdr, version) end |
#struct ⇒ Object
26 27 28 |
# File 'lib/hts/bcf/header.rb', line 26 def struct @bcf_hdr end |
#sync ⇒ Object
62 63 64 |
# File 'lib/hts/bcf/header.rb', line 62 def sync LibHTS.bcf_hdr_sync(@bcf_hdr) end |
#to_ptr ⇒ Object
30 31 32 |
# File 'lib/hts/bcf/header.rb', line 30 def to_ptr @bcf_hdr.to_ptr end |
#to_s ⇒ Object
92 93 94 95 96 97 |
# File 'lib/hts/bcf/header.rb', line 92 def to_s kstr = LibHTS::KString.new raise "Failed to get header string" unless LibHTS.bcf_hdr_format(@bcf_hdr, 0, kstr) kstr[:s] end |