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
- #allele_count ⇒ Object
- #alleles ⇒ Object
- #alleles=(values) ⇒ Object
- #alt ⇒ Object
- #chrom ⇒ Object
- #clear_id ⇒ Object
-
#each_allele_raw ⇒ Object
Native migration replacement for the former pointer-yielding API.
- #each_filter_id(&block) ⇒ Object
- #endpos ⇒ Object
- #filter_id?(target_id) ⇒ Boolean
- #filter_ids ⇒ Object
- #filter_missing? ⇒ Boolean
- #filtered? ⇒ Boolean
- #filters ⇒ Object (also: #filter)
- #format(key = nil) ⇒ Object
- #id ⇒ Object
- #id=(value) ⇒ Object
- #info(key = nil) ⇒ Object
-
#initialize(header, native_record = nil) ⇒ Record
constructor
A new instance of Record.
- #passed? ⇒ Boolean
- #pos ⇒ Object
- #pos=(value) ⇒ Object
- #qual ⇒ Object
- #qual=(value) ⇒ Object
- #ref ⇒ Object
- #rid ⇒ Object
- #rid=(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(header, native_record = nil) ⇒ Record
Returns a new instance of Record.
8 9 10 11 |
# File 'lib/hts/bcf/record.rb', line 8 def initialize(header, native_record = nil) @native = native_record || Native::BcfRecordHandle.create @header = header end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
6 7 8 |
# File 'lib/hts/bcf/record.rb', line 6 def header @header end |
Instance Method Details
#allele_count ⇒ Object
42 |
# File 'lib/hts/bcf/record.rb', line 42 def allele_count = alleles.length |
#alleles ⇒ Object
39 |
# File 'lib/hts/bcf/record.rb', line 39 def alleles = @native.alleles |
#alleles=(values) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/hts/bcf/record.rb', line 44 def alleles=(values) values = Array(values).map(&:to_s) raise ArgumentError, "at least one allele is required" if values.empty? encoded = values.join(",") check_update_rc!(@native.set_alleles(@header.__send__(:native_handle), encoded), "alleles", encoded) values end |
#alt ⇒ Object
41 |
# File 'lib/hts/bcf/record.rb', line 41 def alt = alleles.drop(1) |
#chrom ⇒ Object
19 |
# File 'lib/hts/bcf/record.rb', line 19 def chrom = @header.id2name(rid) |
#clear_id ⇒ Object
34 35 36 37 |
# File 'lib/hts/bcf/record.rb', line 34 def clear_id check_update_rc!(@native.set_id(@header.__send__(:native_handle), "."), "ID", ".") nil end |
#each_allele_raw ⇒ Object
Native migration replacement for the former pointer-yielding API.
54 55 56 57 58 59 |
# File 'lib/hts/bcf/record.rb', line 54 def each_allele_raw return to_enum(__method__) unless block_given? alleles.each { |allele| yield allele, allele.bytesize } self end |
#each_filter_id(&block) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/hts/bcf/record.rb', line 81 def each_filter_id(&block) return to_enum(__method__) unless block_given? @native.filter_ids.each(&block) self end |
#endpos ⇒ Object
26 |
# File 'lib/hts/bcf/record.rb', line 26 def endpos = pos + @native.core_get(:rlen) |
#filter_id?(target_id) ⇒ Boolean
89 |
# File 'lib/hts/bcf/record.rb', line 89 def filter_id?(target_id) = filter_ids.include?(Integer(target_id)) |
#filter_ids ⇒ Object
88 |
# File 'lib/hts/bcf/record.rb', line 88 def filter_ids = @native.filter_ids |
#filter_missing? ⇒ Boolean
78 |
# File 'lib/hts/bcf/record.rb', line 78 def filter_missing? = filters.empty? |
#filtered? ⇒ Boolean
79 |
# File 'lib/hts/bcf/record.rb', line 79 def filtered? = !passed? && !filter_missing? |
#filters ⇒ Object Also known as: filter
67 68 69 70 |
# File 'lib/hts/bcf/record.rb', line 67 def filters names = @native.filter_names(@header.__send__(:native_handle)) names end |
#format(key = nil) ⇒ Object
96 97 98 99 |
# File 'lib/hts/bcf/record.rb', line 96 def format(key = nil) accessor = (@format_accessor ||= Format.new(self)) key ? accessor.get(key) : accessor end |
#id ⇒ Object
27 |
# File 'lib/hts/bcf/record.rb', line 27 def id = @native.id |
#id=(value) ⇒ Object
29 30 31 32 |
# File 'lib/hts/bcf/record.rb', line 29 def id=(value) check_update_rc!(@native.set_id(@header.__send__(:native_handle), value), "ID", value) value end |
#info(key = nil) ⇒ Object
91 92 93 94 |
# File 'lib/hts/bcf/record.rb', line 91 def info(key = nil) accessor = (@info_accessor ||= Info.new(self)) key ? accessor.get(key) : accessor end |
#passed? ⇒ Boolean
77 |
# File 'lib/hts/bcf/record.rb', line 77 def passed? = filters == ["PASS"] |
#pos ⇒ Object
20 |
# File 'lib/hts/bcf/record.rb', line 20 def pos = @native.core_get(:pos) |
#pos=(value) ⇒ Object
22 23 24 |
# File 'lib/hts/bcf/record.rb', line 22 def pos=(value) @native.core_set(:pos, value) end |
#qual ⇒ Object
61 |
# File 'lib/hts/bcf/record.rb', line 61 def qual = @native.core_get(:qual) |
#qual=(value) ⇒ Object
63 64 65 |
# File 'lib/hts/bcf/record.rb', line 63 def qual=(value) @native.core_set(:qual, value) end |
#ref ⇒ Object
40 |
# File 'lib/hts/bcf/record.rb', line 40 def ref = alleles.first |
#rid ⇒ Object
13 |
# File 'lib/hts/bcf/record.rb', line 13 def rid = @native.core_get(:rid) |
#rid=(value) ⇒ Object
15 16 17 |
# File 'lib/hts/bcf/record.rb', line 15 def rid=(value) @native.core_set(:rid, value) end |
#to_s ⇒ Object
101 |
# File 'lib/hts/bcf/record.rb', line 101 def to_s = @native.format_record(@header.__send__(:native_handle)) |