Class: Bio::BioAlignment::Column
- Inherits:
-
Object
- Object
- Bio::BioAlignment::Column
- Includes:
- State, Enumerable
- Defined in:
- lib/bio-alignment/columns.rb
Overview
Support the notion of columns in an alignment. A column is simply an integer index into the alignment, stored in @col. A column can have state by attaching state objects.
Instance Attribute Summary
Attributes included from State
Instance Method Summary collapse
- #[](index) ⇒ Object
- #count(&block) ⇒ Object
-
#each ⇒ Object
iterator fetches a column on demand, yielding column elements.
-
#initialize(aln, col) ⇒ Column
constructor
A new instance of Column.
- #length ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(aln, col) ⇒ Column
Returns a new instance of Column.
60 61 62 63 64 65 |
# File 'lib/bio-alignment/columns.rb', line 60 def initialize aln, col @aln = aln @col = col # column index number @col.freeze @aln end |
Instance Method Details
#[](index) ⇒ Object
67 68 69 |
# File 'lib/bio-alignment/columns.rb', line 67 def [] index @aln[index][@col] end |
#count(&block) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bio-alignment/columns.rb', line 89 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 |
#each ⇒ Object
iterator fetches a column on demand, yielding column elements
79 80 81 82 83 |
# File 'lib/bio-alignment/columns.rb', line 79 def each @aln.each do | seq | yield seq[@col] end end |
#length ⇒ Object
85 86 87 |
# File 'lib/bio-alignment/columns.rb', line 85 def length @length ||= @aln.rows.size end |
#to_s ⇒ Object
103 104 105 |
# File 'lib/bio-alignment/columns.rb', line 103 def to_s map{|e| e.to_s}.join('') end |