Class: BioVcf::VcfAltInfoList

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

Overview

Handle info fields with multiple entries, possibly relating to ALT (single nucleotide only)

Instance Method Summary collapse

Constructor Details

#initialize(alt, list) ⇒ VcfAltInfoList

Returns a new instance of VcfAltInfoList.



66
67
68
69
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 66

def initialize alt,list
  @alt = alt
  @list = list.split(/,/).map{|i| i.to_i}
end

Instance Method Details

#[](idx) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 71

def [] idx
  if idx.kind_of?(Integer)
    @list[idx].to_i
  elsif idx.kind_of?(String)
    @list[@alt.index(idx)].to_i
  else idx.kind_of?(Array)
    idx.map { |nuc|
      idx2 = @alt.index(nuc)
      # p [idx,nuc,idx2,@list]
      @list[idx2].to_i
    }
  end
end

#maxObject

Return the max value on the nucleotides in the list (typically rec.alt)



90
91
92
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 90

def max 
  @list.reduce(0){ |memo,v| (v>memo ? v : memo) }
end

#minObject



94
95
96
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 94

def min 
  @list.reduce(MAXINT){ |memo,v| (v<memo ? v : memo) }
end

#sumObject



98
99
100
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 98

def sum 
  @list.reduce(0){ |memo,v| v+memo }
end

#to_aryObject



85
86
87
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 85

def to_ary
  @list
end