class BioVcf::VcfRecordInfo

Public Class Methods

new(s) click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 4
def initialize s
  @info = s
end

Public Instance Methods

[](k) click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 16
def [] k
  # split_fields if not @h
  # /#{m}=(?<value>[^;])/.@info
  kupper = k.upcase
  v = if @h
        @h[kupper]
      else
        @info =~ /[\A;]#{k}=([^;]+)/i
        value = $1
        # p [m,value]
        # m = @info.match(/#{m.to_s.upcase}=(?<value>[^;]+)/) slower!
        # value = m[:value]
        if value == nil
          split_fields # no option but to split
          @h[kupper]
        else
          value
        end
      end
  ConvertStringToValue::convert(v)
end
[]=(k, v) click to toggle source

Set INFO fields (used by –rewrite)

# File lib/bio-vcf/vcfrecord.rb, line 39
def []= k, v   
  split_fields if not @h
  kupper = k.upcase
  @h[kupper] = v
  @original_key[kupper] = k
end
fields() click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 46
def fields
  split_fields
  @h.keys
end
method_missing(m, *args, &block) click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 51
def method_missing(m, *args, &block)
  self[m.to_s]
end
to_s() click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 8
def to_s
  if @h
    @h.map { |k,v| (v ? @original_key[k] + '=' + v : @original_key[k])  }.join(';')
  else
    @info
  end
end

Private Instance Methods

split_fields() click to toggle source
# File lib/bio-vcf/vcfrecord.rb, line 57
def split_fields
  return @h if @h
  @h = {}
  @original_key = {}
  @info.split(/;/).each do |f| 
    k,v = f.split(/=/) 
    kupper = k.upcase
    @h[kupper] = v
    @original_key[kupper] = k
  end
end