Class: BioVcf::VcfAltInfoList
- Inherits:
-
Object
- Object
- BioVcf::VcfAltInfoList
- 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
- #[](idx) ⇒ Object
-
#initialize(alt, list) ⇒ VcfAltInfoList
constructor
A new instance of VcfAltInfoList.
-
#max ⇒ Object
Return the max value on the nucleotides in the list (typically rec.alt).
- #min ⇒ Object
- #sum ⇒ Object
- #to_ary ⇒ Object
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 |
#max ⇒ Object
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 |
#min ⇒ Object
94 95 96 |
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 94 def min @list.reduce(MAXINT){ |memo,v| (v<memo ? v : memo) } end |
#sum ⇒ Object
98 99 100 |
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 98 def sum @list.reduce(0){ |memo,v| v+memo } end |
#to_ary ⇒ Object
85 86 87 |
# File 'lib/bio-vcf/vcfgenotypefield.rb', line 85 def to_ary @list end |