Class: Bio::BioAlignment::Sequence
- Inherits:
-
Object
- Object
- Bio::BioAlignment::Sequence
- Includes:
- State, Enumerable
- Defined in:
- lib/bio-alignment/sequence.rb
Overview
A Sequence is a simple and efficient container for String sequences. To add state to elements unpack it into an Elements object with to_elements.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
Attributes included from State
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #[](index) ⇒ Object
- #clone ⇒ Object
-
#each ⇒ Object
Return each element in the Sequence as an Element opbject, so it can be queried for gap? and undefined?.
- #empty_copy ⇒ Object
-
#initialize(id, seq) ⇒ Sequence
constructor
A new instance of Sequence.
-
#length ⇒ Object
def []= index, value — we should not implement this for reasons of purity @seq = value end.
-
#to_elements ⇒ Object
Return Sequence (string) as an Elements object.
- #to_s ⇒ Object
Constructor Details
#initialize(id, seq) ⇒ Sequence
Returns a new instance of Sequence.
12 13 14 15 16 |
# File 'lib/bio-alignment/sequence.rb', line 12 def initialize id, seq @id = id @id.freeze @seq = seq end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/bio-alignment/sequence.rb', line 11 def id @id end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
11 12 13 |
# File 'lib/bio-alignment/sequence.rb', line 11 def seq @seq end |
Instance Method Details
#<<(element) ⇒ Object
40 41 42 |
# File 'lib/bio-alignment/sequence.rb', line 40 def << element @seq += element.to_s end |
#[](index) ⇒ Object
18 19 20 |
# File 'lib/bio-alignment/sequence.rb', line 18 def [] index @seq[index] end |
#clone ⇒ Object
48 49 50 |
# File 'lib/bio-alignment/sequence.rb', line 48 def clone Sequence.new(@id,@seq.clone) end |
#each ⇒ Object
Return each element in the Sequence as an Element opbject, so it can be queried for gap? and undefined?
32 33 34 |
# File 'lib/bio-alignment/sequence.rb', line 32 def each @seq.each_char { | c | yield Element.new(c) } end |
#empty_copy ⇒ Object
44 45 46 |
# File 'lib/bio-alignment/sequence.rb', line 44 def empty_copy Sequence.new(@id,"") end |
#length ⇒ Object
def []= index, value — we should not implement this for reasons of purity
@seq[index] = value
end
26 27 28 |
# File 'lib/bio-alignment/sequence.rb', line 26 def length @seq.length end |
#to_elements ⇒ Object
Return Sequence (string) as an Elements object
53 54 55 |
# File 'lib/bio-alignment/sequence.rb', line 53 def to_elements Elements.new(@id,@seq) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/bio-alignment/sequence.rb', line 36 def to_s @seq.to_s end |