Class: HTS::Bcf::Record
- Inherits:
-
Object
- Object
- HTS::Bcf::Record
- Defined in:
- lib/hts/bcf/record.rb
Overview
A class for working with VCF records.
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
Returns a new instance of Record.
7 8 9 10 |
# File 'lib/hts/bcf/record.rb', line 7 def initialize(bcf_t, header) @bcf1 = bcf_t @header = header end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
12 13 14 |
# File 'lib/hts/bcf/record.rb', line 12 def header @header end |
Instance Method Details
#alleles ⇒ Object
76 77 78 79 80 81 |
# File 'lib/hts/bcf/record.rb', line 76 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
69 70 71 72 73 74 |
# File 'lib/hts/bcf/record.rb', line 69 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.
32 33 34 |
# File 'lib/hts/bcf/record.rb', line 32 def chrom LibHTS.bcf_hdr_id2name(@header.struct, rid) end |
#clear_id ⇒ Object
60 61 62 |
# File 'lib/hts/bcf/record.rb', line 60 def clear_id LibHTS.bcf_update_id(@header, @bcf1, ".") end |
#endpos ⇒ Object
Return the 0-based, exclusive end position
46 47 48 |
# File 'lib/hts/bcf/record.rb', line 46 def endpos pos + @bcf1[:rlen] end |
#filter ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hts/bcf/record.rb', line 92 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 id = d[:flt].read_int LibHTS.bcf_hdr_int2id(@header.struct, LibHTS::BCF_DT_ID, id) 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
122 123 124 125 126 127 128 129 |
# File 'lib/hts/bcf/record.rb', line 122 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.
51 52 53 54 |
# File 'lib/hts/bcf/record.rb', line 51 def id LibHTS.bcf_unpack(@bcf1, LibHTS::BCF_UN_INFO) @bcf1[:d][:id] end |
#id=(id) ⇒ Object
56 57 58 |
# File 'lib/hts/bcf/record.rb', line 56 def id=(id) LibHTS.bcf_update_id(@header, @bcf1, id) end |
#info(key = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/hts/bcf/record.rb', line 112 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.
37 38 39 |
# File 'lib/hts/bcf/record.rb', line 37 def pos @bcf1[:pos] end |
#pos=(pos) ⇒ Object
41 42 43 |
# File 'lib/hts/bcf/record.rb', line 41 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
64 65 66 67 |
# File 'lib/hts/bcf/record.rb', line 64 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.
23 24 25 |
# File 'lib/hts/bcf/record.rb', line 23 def rid @bcf1[:rid] end |
#rid=(rid) ⇒ Object
27 28 29 |
# File 'lib/hts/bcf/record.rb', line 27 def rid=(rid) @bcf1[:rid] = rid end |
#struct ⇒ Object
14 15 16 |
# File 'lib/hts/bcf/record.rb', line 14 def struct @bcf1 end |
#to_ptr ⇒ Object
18 19 20 |
# File 'lib/hts/bcf/record.rb', line 18 def to_ptr @bcf1.to_ptr end |
#to_s ⇒ Object
131 132 133 134 135 136 |
# File 'lib/hts/bcf/record.rb', line 131 def to_s ksr = LibHTS::KString.new raise "Failed to format record" if LibHTS.vcf_format(@header.struct, @bcf1, ksr) == -1 ksr[:s] end |