Class: VCF::Genotype

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

Instance Method Summary collapse

Constructor Details

#initialize(line, field) ⇒ Genotype

Returns a new instance of Genotype.



113
114
115
116
# File 'lib/vcf.rb', line 113

def initialize(line,field)
  @line = line
  @hash = Hash[line.format.map(&:downcase).zip(field.split /:/)]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



118
119
120
121
122
123
124
125
126
# File 'lib/vcf.rb', line 118

def method_missing sym, *args, &block
  if @hash[sym]
    @hash[sym]
  elsif sym.to_s =~ /(.*)=/ 
    @hash[$1.to_sym] = args.first
  else
    super sym, *args, &block
  end
end

Instance Method Details

#alt_base_qualityObject



156
# File 'lib/vcf.rb', line 156

def alt_base_quality; respond_to?(:nqsbq) ? nqsbq.split(/,/)[0].to_f : nil; end

#alt_countObject



150
# File 'lib/vcf.rb', line 150

def alt_count; @alt_count ||= respond_to?(:ad) ? ad.split(/,/)[1].to_i : nil; end

#alt_freqObject



152
# File 'lib/vcf.rb', line 152

def alt_freq; alt_count / depth.to_f; end

#alt_lengthObject



155
# File 'lib/vcf.rb', line 155

def alt_length; @line.alt.length; end

#alt_map_qualityObject



157
# File 'lib/vcf.rb', line 157

def alt_map_quality; respond_to?(:mqs) ? mqs.split(/,/)[0].to_f : nil; end

#alt_mismatch_countObject



159
# File 'lib/vcf.rb', line 159

def alt_mismatch_count; respond_to?(:mm) ? mm.split(/,/)[0].to_f : nil; end

#alt_mismatch_rateObject



158
# File 'lib/vcf.rb', line 158

def alt_mismatch_rate; respond_to?(:nqsmm) ? nqsmm.split(/,/)[0].to_f : nil; end

#approx_depthObject



148
# File 'lib/vcf.rb', line 148

def approx_depth; dp.to_i; end

#callable?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/vcf.rb', line 144

def callable?
  gt !~ /\..\./
end

#depthObject



149
# File 'lib/vcf.rb', line 149

def depth; alt_count + ref_count; end

#empty?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/vcf.rb', line 140

def empty?
  gt =~ /\..\./
end

#heterozygous?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/vcf.rb', line 136

def heterozygous?
  gt =~ /0.1/ || gt =~ /1.0/
end

#homozygous?Boolean

Returns:

  • (Boolean)


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

def homozygous?
  gt =~ /0.0/ || gt =~ /1.1/
end

#qualityObject



160
# File 'lib/vcf.rb', line 160

def quality; gq.to_i; end

#ref_countObject



151
# File 'lib/vcf.rb', line 151

def ref_count; @ref_count ||= respond_to?(:ad) ? ad.split(/,/)[0].to_i : nil; end

#ref_freqObject



153
# File 'lib/vcf.rb', line 153

def ref_freq; ref_count / depth.to_f; end

#ref_lengthObject



154
# File 'lib/vcf.rb', line 154

def ref_length; @line.ref.length; end

#respond_to_missing?(sym, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing? sym, include_all = false
  @hash[sym] || super
end

#to_sObject



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

def to_s
  @line.format.map(&:downcase).map{|f| @hash[f]}.join(":")
end