Class: BioVcf::VcfRecordInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-vcf/vcfrecord.rb

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ VcfRecordInfo

Returns a new instance of VcfRecordInfo.



4
5
6
# File 'lib/bio-vcf/vcfrecord.rb', line 4

def initialize s
  @info = s
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



51
52
53
# File 'lib/bio-vcf/vcfrecord.rb', line 51

def method_missing(m, *args, &block)
  self[m.to_s]
end

Instance Method Details

#[](k) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object

Set INFO fields (used by –rewrite)



39
40
41
42
43
44
# 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

#fieldsObject



46
47
48
49
# File 'lib/bio-vcf/vcfrecord.rb', line 46

def fields
  split_fields
  @h.keys
end

#to_sObject



8
9
10
11
12
13
14
# 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