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
16
# File 'lib/bio-alignment/sequence.rb', line 12

def initialize id, seq
  @id = id
  @id.freeze
  @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



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

#cloneObject



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

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?



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

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

#empty_copyObject



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

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

#lengthObject

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_elementsObject

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_sObject



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

def to_s
  @seq.to_s
end