Class: HTS::Bcf::Header

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(arg = nil) ⇒ Header

Returns a new instance of Header.



11
12
13
14
15
16
17
18
19
20
21
22
# 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
end

Instance Method Details

#add_sample(sample, sync: true) ⇒ Object



51
52
53
54
# File 'lib/hts/bcf/header.rb', line 51

def add_sample(sample, sync: true)
  LibHTS.bcf_hdr_add_sample(@bcf_hdr, sample)
  self.sync if sync
end

#append(line) ⇒ Object



68
69
70
# File 'lib/hts/bcf/header.rb', line 68

def append(line)
  LibHTS.bcf_hdr_append(@bcf_hdr, line)
end

#delete(bcf_hl_type, key) ⇒ Object

FIXME



72
73
74
75
# File 'lib/hts/bcf/header.rb', line 72

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



77
78
79
80
81
# File 'lib/hts/bcf/header.rb', line 77

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_versionObject



32
33
34
# File 'lib/hts/bcf/header.rb', line 32

def get_version
  LibHTS.bcf_hdr_get_version(@bcf_hdr)
end

#merge(hdr) ⇒ Object



56
57
58
# File 'lib/hts/bcf/header.rb', line 56

def merge(hdr)
  LibHTS.bcf_hdr_merge(@bcf_hdr, hdr.struct)
end

#nsamplesObject



40
41
42
# File 'lib/hts/bcf/header.rb', line 40

def nsamples
  LibHTS.bcf_hdr_nsamples(@bcf_hdr)
end

#read_bcf(fname) ⇒ Object



64
65
66
# File 'lib/hts/bcf/header.rb', line 64

def read_bcf(fname)
  LibHTS.bcf_hdr_set(@bcf_hdr, fname)
end

#samplesObject



44
45
46
47
48
49
# File 'lib/hts/bcf/header.rb', line 44

def samples
  # bcf_hdr_id2name is macro function
  @bcf_hdr[:samples]
    .read_array_of_pointer(nsamples)
    .map(&:read_string)
end

#seqnamesObject



83
84
85
86
87
88
# File 'lib/hts/bcf/header.rb', line 83

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



36
37
38
# File 'lib/hts/bcf/header.rb', line 36

def set_version(version)
  LibHTS.bcf_hdr_set_version(@bcf_hdr, version)
end

#structObject



24
25
26
# File 'lib/hts/bcf/header.rb', line 24

def struct
  @bcf_hdr
end

#syncObject



60
61
62
# File 'lib/hts/bcf/header.rb', line 60

def sync
  LibHTS.bcf_hdr_sync(@bcf_hdr)
end

#to_ptrObject



28
29
30
# File 'lib/hts/bcf/header.rb', line 28

def to_ptr
  @bcf_hdr.to_ptr
end

#to_sObject



90
91
92
93
94
95
# File 'lib/hts/bcf/header.rb', line 90

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