Class: Wrnap::Rna::Helix

Inherits:
Object
  • Object
show all
Defined in:
lib/wrnap/rna/motifs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(i, j, length) ⇒ Helix

Returns a new instance of Helix.



6
7
8
# File 'lib/wrnap/rna/motifs.rb', line 6

def initialize(i, j, length)
  @i, @j, @length = i, j, length
end

Instance Attribute Details

#iObject (readonly)

Returns the value of attribute i.



4
5
6
# File 'lib/wrnap/rna/motifs.rb', line 4

def i
  @i
end

#jObject (readonly)

Returns the value of attribute j.



4
5
6
# File 'lib/wrnap/rna/motifs.rb', line 4

def j
  @j
end

#lengthObject (readonly)

Returns the value of attribute length.



4
5
6
# File 'lib/wrnap/rna/motifs.rb', line 4

def length
  @length
end

Instance Method Details

#apply!(structure) ⇒ Object



23
24
25
26
27
28
# File 'lib/wrnap/rna/motifs.rb', line 23

def apply!(structure)
  structure.tap do
    structure[i, length] = ?( * length
    structure[l, length] = ?) * length
  end
end

#in(sequence) ⇒ Object



13
14
15
16
17
# File 'lib/wrnap/rna/motifs.rb', line 13

def in(sequence)
  (0...length).map do |stem_position|
    [sequence[i + stem_position], sequence[j - stem_position]]
  end
end

#inspectObject



50
51
52
# File 'lib/wrnap/rna/motifs.rb', line 50

def inspect
  "#<Helix: %s>" % name
end

#kObject



10
# File 'lib/wrnap/rna/motifs.rb', line 10

def k; i + length - 1; end

#lObject



11
# File 'lib/wrnap/rna/motifs.rb', line 11

def l; j - length + 1; end

#merge!(helix) ⇒ Object



30
31
32
# File 'lib/wrnap/rna/motifs.rb', line 30

def merge!(helix)
  @length = helix.k - i + 1
end

#nameObject



46
47
48
# File 'lib/wrnap/rna/motifs.rb', line 46

def name
  "(%d..%d, %d..%d [%d])" % [i, k, l, j, length]
end

#reindex!(rna) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wrnap/rna/motifs.rb', line 34

def reindex!(rna)
  tap do
    if i < 0 && j < 0
      @i = rna.len + i
      @j = rna.len + j
    else
      @i = i - rna.len
      @j = j - rna.len
    end
  end
end

#to_loopsObject



19
20
21
# File 'lib/wrnap/rna/motifs.rb', line 19

def to_loops
  [Loop.new(i, k), Loop.new(l, j)]
end