Module: Wrnap::Rna::Extensions::InstanceMethods
- Defined in:
- lib/wrnap/rna/extensions.rb
Instance Method Summary collapse
- #boltzmann_probability(dangle: 2) ⇒ Object
- #dishuffle ⇒ Object
- #gc_content ⇒ Object
- #global_structural_shuffle ⇒ Object
- #hamming_distance(other_rna) ⇒ Object
- #local_structural_dishuffle ⇒ Object
- #local_structural_shuffle(dishuffle: false) ⇒ Object
Instance Method Details
#boltzmann_probability(dangle: 2) ⇒ Object
104 105 106 |
# File 'lib/wrnap/rna/extensions.rb', line 104 def boltzmann_probability(dangle: 2) Math.exp(-run(:eval, d: dangle).mfe / Wrnap::RT) / Math.exp(-run(:fold, d: dangle, p: 0).ensemble_energy / Wrnap::RT) end |
#dishuffle ⇒ Object
96 97 98 |
# File 'lib/wrnap/rna/extensions.rb', line 96 def dishuffle Rna.init_from_string(self.class.shuffle(sequence, 2)) end |
#gc_content ⇒ Object
100 101 102 |
# File 'lib/wrnap/rna/extensions.rb', line 100 def gc_content seq.split(//).select { |i| i =~ /[GC]/i }.size.to_f / seq.size end |
#global_structural_shuffle ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/wrnap/rna/extensions.rb', line 76 def global_structural_shuffle # Permutes the nucleotides of the sequence such that the basepairs in the initial structure are shuffled independently of the # unpaired bases. This ensures that the resulting sequence is compatible with the original structure. raise "the structural_shuffle functions require the initial RNA to have a structure" unless str sequence = " " * len loops, helices = loops_and_helices shuffled_loops = Shuffle.new(loops.map { |loop| loop.in(seq) }.join.split(//)).shuffle shuffled_helices = helices.map { |helix| helix.in(seq) }.inject(&:+).shuffle.map { |array| rand(2).zero? ? array : array.reverse } loops.each { |loop| sequence[loop.i..loop.j] = shuffled_loops.shift(loop.length).join } helices.each do |helix| left_stem, right_stem = shuffled_helices.shift(helix.length).transpose.map(&:join) sequence[helix.i..helix.k] = left_stem sequence[helix.l..helix.j] = right_stem.reverse end Rna.init_from_string(sequence, str) end |
#hamming_distance(other_rna) ⇒ Object
42 43 44 45 46 |
# File 'lib/wrnap/rna/extensions.rb', line 42 def hamming_distance(other_rna) raise "The two sequences are not the same length" unless len == other_rna.len [seq, other_rna.seq].map(&:each_char).map(&:to_a).transpose.select { |array| array.uniq.size > 1 }.count end |
#local_structural_dishuffle ⇒ Object
72 73 74 |
# File 'lib/wrnap/rna/extensions.rb', line 72 def local_structural_dishuffle local_structural_shuffle(dishuffle: true) end |
#local_structural_shuffle(dishuffle: false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/wrnap/rna/extensions.rb', line 48 def local_structural_shuffle(dishuffle: false) # Permutes the base pairs of the structure provided for the template sequence independently of the unpaired regions, as in # global_structural_shuffle. This adds the additional constraint that loops and helices are permuted as individual sets, # rather than using two global loop / helix bags. raise "the structural_shuffle functions require the initial RNA to have a structure" unless str sequence = " " * len loops, helices = loops_and_helices loops.each { |loop| sequence[loop.i..loop.j] = Shuffle.new(loop.in(seq)).send(dishuffle ? :dishuffle : :shuffle) } helices.each do |helix| left_stem, right_stem = if dishuffle Shuffle.new(helix.in(seq)).dishuffle else Shuffle.new(helix.in(seq)).shuffle.map { |array| rand(2).zero? ? array : array.reverse } end.transpose.map(&:join) sequence[helix.i..helix.k] = left_stem sequence[helix.l..helix.j] = right_stem.reverse end Rna.init_from_string(sequence, str) end |