Class: HTS::Bcf::Record
- Inherits:
-
Object
- Object
- HTS::Bcf::Record
- Defined in:
- lib/hts/bcf/record.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #alleles ⇒ Object
- #alt ⇒ Object
-
#chrom ⇒ Object
Get the chromosome of variant.
- #clear_id ⇒ Object
-
#endpos ⇒ Object
Return the 0-based, exclusive end position.
- #filter ⇒ Object
- #format(key = nil) ⇒ Object
-
#id ⇒ Object
Return the value of the ID column.
- #id=(id) ⇒ Object
- #info(key = nil) ⇒ Object
-
#initialize(bcf_t, header) ⇒ Record
constructor
A new instance of Record.
-
#pos ⇒ Object
Return 0-based position.
- #pos=(pos) ⇒ Object
-
#qual ⇒ Object
Get variant quality.
- #qual=(qual) ⇒ Object
- #ref ⇒ Object
-
#rid ⇒ Object
Get the reference id of the record.
- #rid=(rid) ⇒ Object
- #struct ⇒ Object
- #to_ptr ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(bcf_t, header) ⇒ 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
#header ⇒ Object (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
#alleles ⇒ Object
104 105 106 107 108 109 |
# File 'lib/hts/bcf/record.rb', line 104 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 |
#alt ⇒ Object
97 98 99 100 101 102 |
# File 'lib/hts/bcf/record.rb', line 97 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 |
#chrom ⇒ Object
Get the chromosome of variant.
31 32 33 |
# File 'lib/hts/bcf/record.rb', line 31 def chrom LibHTS.bcf_hdr_id2name(@header.struct, rid) end |
#clear_id ⇒ Object
59 60 61 |
# File 'lib/hts/bcf/record.rb', line 59 def clear_id LibHTS.bcf_update_id(@header, @bcf1, ".") end |
#endpos ⇒ Object
Return the 0-based, exclusive end position
45 46 47 |
# File 'lib/hts/bcf/record.rb', line 45 def endpos pos + @bcf1[:rlen] end |
#filter ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hts/bcf/record.rb', line 63 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..nil 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 |
#format(key = nil) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/hts/bcf/record.rb', line 121 def format(key = nil) LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_FMT) if key Format.new(self).get(key) else Format.new(self) end end |
#id ⇒ Object
Return the value of the ID column.
50 51 52 53 |
# File 'lib/hts/bcf/record.rb', line 50 def id LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_INFO) @bcf1[:d][:id] end |
#id=(id) ⇒ Object
55 56 57 |
# File 'lib/hts/bcf/record.rb', line 55 def id=(id) LibHTS.bcf_update_id(@header, @bcf1, id) end |
#info(key = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/hts/bcf/record.rb', line 111 def info(key = nil) LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_SHR) info = Info.new(self) if key info.get(key) else info end end |
#pos ⇒ Object
Return 0-based position.
36 37 38 |
# File 'lib/hts/bcf/record.rb', line 36 def pos @bcf1[:pos] end |
#pos=(pos) ⇒ Object
40 41 42 |
# File 'lib/hts/bcf/record.rb', line 40 def pos=(pos) @bcf1[:pos] = pos end |
#qual ⇒ Object
Get variant quality.
84 85 86 |
# File 'lib/hts/bcf/record.rb', line 84 def qual @bcf1[:qual] end |
#qual=(qual) ⇒ Object
88 89 90 |
# File 'lib/hts/bcf/record.rb', line 88 def qual=(qual) @bcf1[:qual] = qual end |
#ref ⇒ Object
92 93 94 95 |
# File 'lib/hts/bcf/record.rb', line 92 def ref LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_STR) @bcf1[:d][:allele].get_pointer(0).read_string end |
#rid ⇒ Object
Get the reference id of the record.
22 23 24 |
# File 'lib/hts/bcf/record.rb', line 22 def rid @bcf1[:rid] end |
#rid=(rid) ⇒ Object
26 27 28 |
# File 'lib/hts/bcf/record.rb', line 26 def rid=(rid) @bcf1[:rid] = rid end |
#struct ⇒ Object
13 14 15 |
# File 'lib/hts/bcf/record.rb', line 13 def struct @bcf1 end |
#to_ptr ⇒ Object
17 18 19 |
# File 'lib/hts/bcf/record.rb', line 17 def to_ptr @bcf1.to_ptr end |
#to_s ⇒ Object
130 131 132 133 134 135 |
# File 'lib/hts/bcf/record.rb', line 130 def to_s ksr = LibHTS::KString.new raise "Failed to format record" if LibHTS.vcf_format(@header.struct, @bcf1, ksr) == -1 ksr[:s] end |