Class: HTS::Bcf::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/hts/bcf/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bcf_t, header) ⇒ Record

Returns a new instance of Record.



6
7
8
9
# File 'lib/hts/bcf/record.rb', line 6

def initialize(bcf_t, header)
  @bcf1 = bcf_t
  @header = header
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



11
12
13
# File 'lib/hts/bcf/record.rb', line 11

def header
  @header
end

Instance Method Details

#allelesObject



86
87
88
89
90
91
# File 'lib/hts/bcf/record.rb', line 86

def alleles
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_STR)
  @bcf1[:d][:allele].get_array_of_pointer(
    0, @bcf1[:n_allele]
  ).map(&:read_string)
end

#altObject



79
80
81
82
83
84
# File 'lib/hts/bcf/record.rb', line 79

def alt
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_STR)
  @bcf1[:d][:allele].get_array_of_pointer(
    FFI::TYPE_POINTER.size, @bcf1[:n_allele] - 1
  ).map(&:read_string)
end

#chromObject



27
28
29
30
31
# File 'lib/hts/bcf/record.rb', line 27

def chrom
  rid = @bcf1[:rid]

  LibHTS.bcf_hdr_id2name(@header.struct, rid)
end

#filterObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hts/bcf/record.rb', line 50

def filter
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_FLT)
  d = @bcf1[:d]
  n_flt = d[:n_flt]

  case n_flt
  when 0
    "PASS"
  when 1
    i = d[:flt].read_int
    LibHTS.bcf_hdr_int2id(@header.struct, LibHTS::BCF_DT_ID, i)
  when 2
    d[:flt].get_array_of_int(0, n_flt).map do |i|
      LibHTS.bcf_hdr_int2id(@header.struct, LibHTS::BCF_DT_ID, i)
    end
  else
    raise "Unexpected number of filters. n_flt: #{n_flt}"
  end
end

#formatObject



98
99
100
101
# File 'lib/hts/bcf/record.rb', line 98

def format
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_FMT)
  Format.new(self)
end

#formatsObject

def inspect; end



23
# File 'lib/hts/bcf/record.rb', line 23

def formats; end

#genotypesObject



25
# File 'lib/hts/bcf/record.rb', line 25

def genotypes; end

#idObject



45
46
47
48
# File 'lib/hts/bcf/record.rb', line 45

def id
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_INFO)
  @bcf1[:d][:id]
end

#infoObject



93
94
95
96
# File 'lib/hts/bcf/record.rb', line 93

def info
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_SHR)
  Info.new(self)
end

#posObject



33
34
35
# File 'lib/hts/bcf/record.rb', line 33

def pos
  @bcf1[:pos] + 1 # FIXME
end

#qualObject



70
71
72
# File 'lib/hts/bcf/record.rb', line 70

def qual
  @bcf1[:qual]
end

#refObject



74
75
76
77
# File 'lib/hts/bcf/record.rb', line 74

def ref
  LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_STR)
  @bcf1[:d][:allele].get_pointer(0).read_string
end

#startObject



37
38
39
# File 'lib/hts/bcf/record.rb', line 37

def start
  @bcf1[:pos]
end

#stopObject



41
42
43
# File 'lib/hts/bcf/record.rb', line 41

def stop
  @bcf1[:pos] + @bcf1[:rlen]
end

#structObject



13
14
15
# File 'lib/hts/bcf/record.rb', line 13

def struct
  @bcf1
end

#to_ptrObject



17
18
19
# File 'lib/hts/bcf/record.rb', line 17

def to_ptr
  @bcf1.to_ptr
end

#to_sObject



103
104
105
106
107
108
# File 'lib/hts/bcf/record.rb', line 103

def to_s
  ksr = LibHTS::KString.new
  raise "Failed to format record" if LibHTS.vcf_format(@header.struct, @bcf1, ksr) == -1

  ksr[:s]
end