Class: Bio::BioAlignment::Sequence

Inherits:
Object
  • Object
show all
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

Attributes included from State

#state

Instance Method Summary collapse

Constructor Details

#initialize(id, seq) ⇒ Sequence

Returns a new instance of Sequence.



12
13
14
15
# File 'lib/bio-alignment/sequence.rb', line 12

def initialize id, seq
  @id = id
  @seq = seq
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/bio-alignment/sequence.rb', line 11

def id
  @id
end

#seqObject (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



35
36
37
# File 'lib/bio-alignment/sequence.rb', line 35

def << element
  @seq += element.to_s
end

#[](index) ⇒ Object



17
18
19
# File 'lib/bio-alignment/sequence.rb', line 17

def [] index
  @seq[index]
end

#cloneObject



43
44
45
# File 'lib/bio-alignment/sequence.rb', line 43

def clone
  Sequence.new(@id,@seq.clone)
end

#eachObject

Return each element in the Sequence as an Element opbject, so it can be queried for gap? and undefined?



27
28
29
# File 'lib/bio-alignment/sequence.rb', line 27

def each
  @seq.each_char { | c | yield Element.new(c) }
end

#empty_copyObject



39
40
41
# File 'lib/bio-alignment/sequence.rb', line 39

def empty_copy
  Sequence.new(@id,"")
end

#lengthObject



21
22
23
# File 'lib/bio-alignment/sequence.rb', line 21

def length
  @seq.length
end

#to_elementsObject

Return Sequence (string) as an Elements object



48
49
50
# File 'lib/bio-alignment/sequence.rb', line 48

def to_elements
  Elements.new(@id,@seq)
end

#to_sObject



31
32
33
# File 'lib/bio-alignment/sequence.rb', line 31

def to_s
  @seq.to_s
end