Class: Wrnap::Rna::Constraints::ConstraintBox
- Inherits:
-
Object
- Object
- Wrnap::Rna::Constraints::ConstraintBox
- Includes:
- MetaMissing
- Defined in:
- lib/wrnap/rna/constraints.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#rna ⇒ Object
readonly
Returns the value of attribute rna.
Instance Method Summary collapse
- #between(i, j) ⇒ Object
- #end_to(i) ⇒ Object
- #freeze(mask_object) ⇒ Object
-
#initialize(rna) ⇒ ConstraintBox
constructor
A new instance of ConstraintBox.
- #inside(i, j) ⇒ Object
- #inspect ⇒ Object
- #mask!(mask_object, *args) ⇒ Object
- #mask_helix!(helix, side: :both, symbol: "()") ⇒ Object
- #mask_loop!(l00p, symbol: "x") ⇒ Object
- #mask_region!(i, j, symbol: "x") ⇒ Object
- #n ⇒ Object
- #prune! ⇒ Object
- #start_to(i) ⇒ Object
- #to_s ⇒ Object (also: #mask)
Constructor Details
#initialize(rna) ⇒ ConstraintBox
31 32 33 |
# File 'lib/wrnap/rna/constraints.rb', line 31 def initialize(rna) @rna, @constraints = rna, [] end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
29 30 31 |
# File 'lib/wrnap/rna/constraints.rb', line 29 def constraints @constraints end |
#rna ⇒ Object (readonly)
Returns the value of attribute rna.
29 30 31 |
# File 'lib/wrnap/rna/constraints.rb', line 29 def rna @rna end |
Instance Method Details
#between(i, j) ⇒ Object
39 40 41 |
# File 'lib/wrnap/rna/constraints.rb', line 39 def between(i, j) Loop.new(i, j) end |
#end_to(i) ⇒ Object
51 52 53 |
# File 'lib/wrnap/rna/constraints.rb', line 51 def end_to(i) between(i, n) end |
#freeze(mask_object) ⇒ Object
55 56 57 58 |
# File 'lib/wrnap/rna/constraints.rb', line 55 def freeze(mask_object) force mask_object prohibit mask_object.unpaired_regions end |
#inside(i, j) ⇒ Object
43 44 45 |
# File 'lib/wrnap/rna/constraints.rb', line 43 def inside(i, j) between(i + 1, j - 1) end |
#inspect ⇒ Object
97 98 99 |
# File 'lib/wrnap/rna/constraints.rb', line 97 def inspect "#<Constraints: %s>" % constraints.map(&:name).join(", ") end |
#mask!(mask_object, *args) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/wrnap/rna/constraints.rb', line 60 def mask!(mask_object, *args) case mask_object when TreeStem then mask_object.preorder_traversal { |node| mask!(node.content, *args) } when Array then mask_object.map { |node| mask!(node, *args) } when Helix then mask_helix!(mask_object, *args) when Loop then mask_loop!(mask_object, symbol: args[0][:symbol]) end end |
#mask_helix!(helix, side: :both, symbol: "()") ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wrnap/rna/constraints.rb', line 69 def mask_helix!(helix, side: :both, symbol: "()") left_loop, right_loop = helix.to_loops if symbol.length > 1 left_symbol, right_symbol = symbol.split(//) else left_symbol = right_symbol = symbol end mask_loop!(left_loop, symbol: left_symbol) if side == :left || side == :both mask_loop!(right_loop, symbol: right_symbol) if side == :right || side == :both end |
#mask_loop!(l00p, symbol: "x") ⇒ Object
82 83 84 |
# File 'lib/wrnap/rna/constraints.rb', line 82 def mask_loop!(l00p, symbol: "x") mask_region!(l00p.i, l00p.j, symbol: symbol) end |
#mask_region!(i, j, symbol: "x") ⇒ Object
86 87 88 89 90 91 |
# File 'lib/wrnap/rna/constraints.rb', line 86 def mask_region!(i, j, symbol: "x") raise ArgumentError.new("Trying to apply symbol '%s' from %d to %d, all symbols must be 1 char long." % [symbol, i, j]) if symbol.length > 1 constraints << ConstraintData.new(i, j, symbol) prune! end |
#n ⇒ Object
35 36 37 |
# File 'lib/wrnap/rna/constraints.rb', line 35 def n rna.len - 1 end |
#prune! ⇒ Object
93 94 95 |
# File 'lib/wrnap/rna/constraints.rb', line 93 def prune! @constraints = constraints.group_by(&:name).map(&:last).map(&:first) end |
#start_to(i) ⇒ Object
47 48 49 |
# File 'lib/wrnap/rna/constraints.rb', line 47 def start_to(i) between(0, i) end |
#to_s ⇒ Object Also known as: mask
101 102 103 104 105 |
# File 'lib/wrnap/rna/constraints.rb', line 101 def to_s (?. * rna.len).tap do |string| constraints.each { |constraint| string[constraint.from..constraint.to] = constraint.symbol * constraint.length } end end |