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(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

#headerObject (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_countObject



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

def allele_count = alleles.length

#allelesObject



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

def alleles = @native.alleles

#alleles=(values) ⇒ Object

Raises:

  • (ArgumentError)


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

def alleles=(values)
  values = Array(values).map(&:to_s)
  raise ArgumentError, "at least one allele is required" if values.empty?

  @native.set_alleles(@header.__send__(:native_handle), values.join(","))
  values
end

#altObject



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

def alt = alleles.drop(1)

#chromObject



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

def chrom = @header.id2name(rid)

#clear_idObject



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

def clear_id
  @native.set_id(@header.__send__(:native_handle), ".")
  nil
end

#each_allele_rawObject

Native migration replacement for the former pointer-yielding API.



52
53
54
55
56
57
# File 'lib/hts/bcf/record.rb', line 52

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



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

def each_filter_id(&block)
  return to_enum(__method__) unless block_given?

  @native.filter_ids.each(&block)
  self
end

#endposObject



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

def endpos = pos + @native.core_get(:rlen)

#filterObject



65
66
67
68
69
70
71
72
# File 'lib/hts/bcf/record.rb', line 65

def filter
  names = @native.filter_names(@header.__send__(:native_handle))
  case names.length
  when 0 then "PASS"
  when 1 then names.first
  else names
  end
end

#filter_id?(target_id) ⇒ Boolean

Returns:

  • (Boolean)


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

def filter_id?(target_id) = filter_ids.include?(Integer(target_id))

#filter_idsObject



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

def filter_ids = @native.filter_ids

#format(key = nil) ⇒ Object



89
90
91
92
# File 'lib/hts/bcf/record.rb', line 89

def format(key = nil)
  accessor = (@format_accessor ||= Format.new(self))
  key ? accessor.get(key) : accessor
end

#idObject



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

def id = @native.id

#id=(value) ⇒ Object



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

def id=(value)
  @native.set_id(@header.__send__(:native_handle), value)
end

#info(key = nil) ⇒ Object



84
85
86
87
# File 'lib/hts/bcf/record.rb', line 84

def info(key = nil)
  accessor = (@info_accessor ||= Info.new(self))
  key ? accessor.get(key) : accessor
end

#posObject



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

#qualObject



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

def qual = @native.core_get(:qual)

#qual=(value) ⇒ Object



61
62
63
# File 'lib/hts/bcf/record.rb', line 61

def qual=(value)
  @native.core_set(:qual, value)
end

#refObject



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

def ref = alleles.first

#ridObject



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_sObject



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

def to_s = @native.format_record(@header.__send__(:native_handle))