Class: BioVcf::VcfGenotypeField

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, format, header, ref, alt) ⇒ VcfGenotypeField

Returns a new instance of VcfGenotypeField.



107
108
109
110
111
112
113
114
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 107

def initialize s, format, header, ref, alt
  @is_empty = VcfSample::empty?(s)
  @original_s = s
  @format = format
  @header = header
  @ref = ref
  @alt = alt
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Returns the value of a field



172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 172

def method_missing(m, *args, &block)
  return nil if @is_empty
  if m =~ /\?$/
    # query if a value exists, e.g., r.info.dp? or s.dp?
    v = values[fetch(m.to_s.upcase.chop)]
    return (not VcfValue::empty?(v))
  else
    v = values[fetch(m.to_s.upcase)]
    return nil if VcfValue::empty?(v)
    v = v.to_i if v =~ /^\d+$/
    v = v.to_f if v =~ /^\d+\.\d+$/
    v
  end
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



105
106
107
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 105

def format
  @format
end

#headerObject (readonly)

Returns the value of attribute header.



105
106
107
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 105

def header
  @header
end

#valuesObject (readonly)

Returns the value of attribute values.



105
106
107
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 105

def values
  @values
end

Instance Method Details

#adObject



135
136
137
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 135

def ad 
  ilist('AD') 
end

#amqObject



150
151
152
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 150

def amq
  VcfAltInfoList.new(@alt,values[fetch('AMQ')])
end

#bcountObject



142
143
144
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 142

def bcount
  VcfNucleotideCount4.new(@alt,values[fetch('BCOUNT')])
end

#bqObject



146
147
148
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 146

def bq
  VcfAltInfoList.new(@alt,values[fetch('BQ')])
end

#dp4Object



132
133
134
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 132

def dp4 
  ilist('DP4') 
end

#empty?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 124

def empty?
  @is_empty
end

#gtiObject



158
159
160
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 158

def gti
  gt.split(/[\/\|]/).map { |g| g.to_i }
end

#gti?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 154

def gti?
  not VcfValue::empty?(fetch_value("GT"))
end

#gtsObject



166
167
168
169
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 166

def gts
  genotypes = [@ref] + @alt
  gti.map { |i| genotypes[i] }
end

#gts?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 162

def gts?
  not VcfValue::empty?(fetch_value("GT"))
end

#plObject



138
139
140
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 138

def pl 
  ilist('PL') 
end

#to_sObject



116
117
118
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 116

def to_s
  @original_s
end

#valid?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 128

def valid?
  !empty?
end