Class: Bio::BioAlignment::Column

Inherits:
Object
  • Object
show all
Includes:
State, Enumerable
Defined in:
lib/bio-alignment/columns.rb

Overview

Support the notion of columns in an alignment. A column can have state by attaching state objects

Instance Attribute Summary

Attributes included from State

#state

Instance Method Summary collapse

Constructor Details

#initialize(aln, col) ⇒ Column

Returns a new instance of Column.



59
60
61
62
# File 'lib/bio-alignment/columns.rb', line 59

def initialize aln, col
  @aln = aln
  @col = col
end

Instance Method Details

#[](index) ⇒ Object



64
65
66
# File 'lib/bio-alignment/columns.rb', line 64

def [] index
  @aln[index][@col] 
end

#count(&block) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bio-alignment/columns.rb', line 79

def count &block
  counter = 0
  each do | e |
    found = 
      if e.kind_of?(String)
        block.call(Element.new(e))
      else
        block.call(e)
      end
    counter += 1 if found
  end
  counter
end

#eachObject

iterator fetches a column on demand, yielding column elements



69
70
71
72
73
# File 'lib/bio-alignment/columns.rb', line 69

def each
  @aln.each do | seq |
    yield seq[@col]
  end
end

#lengthObject



75
76
77
# File 'lib/bio-alignment/columns.rb', line 75

def length
  @length ||= @aln.rows.size
end

#to_sObject



93
94
95
# File 'lib/bio-alignment/columns.rb', line 93

def to_s
  map{|e| e.to_s}.join('')
end