Class: VCF::Line

Inherits:
Mutation::Record show all
Defined in:
lib/vcf.rb

Instance Attribute Summary

Attributes inherited from Mutation::Record

#muts

Instance Method Summary collapse

Methods inherited from Mutation::Record

#copy, #mut, #skip_oncotator?

Methods included from Mutation::Filtering

#criteria_failed?, #criterion_ok?

Methods included from GenomicLocus

#default_stop, #loc, #long_chrom, #range, #short_chrom

Methods included from IntervalList::Interval

#above?, #below?, #center, #clone, #contains?, #diff, #dist, #intersect, #overlaps?, #size, #union

Methods inherited from HashTable::HashLine

#[], #[]=, alias_key, #approve!, #invalid?, #invalidate!, #method_missing, #respond_to_missing?, #set_table, #to_s, #update

Constructor Details

#initialize(h, s) ⇒ Line

Returns a new instance of Line.



61
62
63
64
65
66
67
68
# File 'lib/vcf.rb', line 61

def initialize(h, s)
  super h, s

  self.format = self.format.split(/:/).map{|f| f.to_sym} if self.format

  build_genotypes
  build_muts
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HashTable::HashLine

Instance Method Details

#build_genotypesObject



70
71
72
73
74
75
76
77
# File 'lib/vcf.rb', line 70

def build_genotypes
  @genotypes = {}
  if @table.samples
    @table.samples.each do |s|
      @genotypes[s] = VCF::Genotype.new self, self.send(s)
    end
  end
end

#build_mutsObject



79
80
81
82
83
# File 'lib/vcf.rb', line 79

def build_muts
  @table.samples.each do |s|
    @muts.push Mutation.new(chrom, pos, ref, alt, genotype(s).ref_count, genotype(s).alt_count)
  end
end

#format_column(column) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/vcf.rb', line 96

def format_column column
  if column == :format
    self.format.join(":")
  elsif genotype(column)
    genotype(column).to_s
  else
    super(column)
  end
end

#genotype(s) ⇒ Object



106
107
108
# File 'lib/vcf.rb', line 106

def genotype(s)
  @genotypes[s.to_sym] if @genotypes
end

#pick_altObject



92
93
94
# File 'lib/vcf.rb', line 92

def pick_alt
  alt.split(/,/).first
end

#skip_genotype?(g) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
# File 'lib/vcf.rb', line 85

def skip_genotype? g
  name, geno = g.first
  geno = genotype(geno)

  !geno || geno.empty? || criteria_failed?(geno, name)
end