Module: ViennaRna::Global::RnaExtensions::TwoStructureBasedMethods
- Defined in:
- lib/vienna_rna/global/rna_extensions.rb
Instance Method Summary collapse
- #bp_distance(structure_1, structure_2) ⇒ Object
- #symmetric_bp_distance(structure_1, structure_2) ⇒ Object
Instance Method Details
#bp_distance(structure_1, structure_2) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/vienna_rna/global/rna_extensions.rb', line 84 def bp_distance(structure_1, structure_2) # Takes two structures and calculates the distance between them by |symmetric difference(bp_in_a, bp_in_b)| raise "The two structures are not the same length" unless structure_1.length == structure_2.length bp_set_1, bp_set_2 = base_pairs(structure_1), base_pairs(structure_2) ((bp_set_1 - bp_set_2) + (bp_set_2 - bp_set_1)).count end |
#symmetric_bp_distance(structure_1, structure_2) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/vienna_rna/global/rna_extensions.rb', line 93 def symmetric_bp_distance(structure_1, structure_2) # Takes two structures and calculates the distance between them by: sum { ((x_j - x_i) - (y_j - y_i)).abs } raise "The two structures are not the same length" unless structure_1.length == structure_2.length bp_dist = ->(array, i) { array[i] == -1 ? 0 : array[i] - i } structure_1_pairings = get_pairings(structure_1) structure_2_pairings = get_pairings(structure_2) structure_1.length.times.inject(0) do |distance, i| distance + (bp_dist[structure_1_pairings, i] - bp_dist[structure_2_pairings, i]).abs end end |