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 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.
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 |
#each ⇒ Object
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 |
#length ⇒ Object
75 76 77 |
# File 'lib/bio-alignment/columns.rb', line 75 def length @length ||= @aln.rows.size end |
#to_s ⇒ Object
93 94 95 |
# File 'lib/bio-alignment/columns.rb', line 93 def to_s map{|e| e.to_s}.join('') end |