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 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

#state

Instance Method Summary collapse

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

#eachObject

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

#lengthObject



85
86
87
# File 'lib/bio-alignment/columns.rb', line 85

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

#to_sObject



103
104
105
# File 'lib/bio-alignment/columns.rb', line 103

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