Class: BioVcf::VcfGenotypeFields

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

Overview

Holds all samples

Instance Method Summary collapse

Constructor Details

#initialize(fields, format, header, ref, alt) ⇒ VcfGenotypeFields

Returns a new instance of VcfGenotypeFields.



210
211
212
213
214
215
216
217
218
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 210

def initialize fields, format, header, ref, alt
  @fields = fields
  @format = format
  @header = header
  @ref = ref
  @alt = alt
  @samples = {} # lazy cache
  @sample_index = @header.sample_index()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



229
230
231
232
233
234
235
236
237
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 229

def method_missing(m, *args, &block) 
  name = m.to_s
  if name =~ /\?$/
    # test for valid sample
    return !VcfSample::empty?(@fields[@sample_index[name.chop]])
  else
    @samples[name] ||= VcfGenotypeField.new(@fields[@sample_index[name]],@format,@header,@ref,@alt)
  end
end

Instance Method Details

#[](name) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 220

def [] name
  begin
    @samples[name] ||= VcfGenotypeField.new(@fields[@sample_index[name]],@format,@header,@ref,@alt)
  rescue TypeError
    $stderr.print "Unknown field name <#{name}> in record, did you mean r.info.#{name}?\n"
    raise 
  end
end