Class: Bioroebe::SmithWaterman
- Inherits:
-
Object
- Object
- Bioroebe::SmithWaterman
- Defined in:
- lib/bioroebe/string_matching/smith_waterman.rb
Overview
Bioroebe::SmithWaterman
Constant Summary collapse
- MATCH_COST =
#
MATCH_COST
First, define the match, mismatch and gap costs.
#
2
- MISMATCH_COST =
#
MISMATCH_COST
#
-1
- GAP_COST =
#
GAP_COST
#
-4
- SCORE_INSERT =
#
SCORE_INSERT
#
0
- SCORE_DELETE =
#
SCORE_DELETE
#
-1
- SCORE_MISS =
-1
- SCORE_MATCH =
2
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#m ⇒ Object
readonly
Returns the value of attribute m.
-
#mat ⇒ Object
readonly
Returns the value of attribute mat.
-
#n ⇒ Object
readonly
Returns the value of attribute n.
-
#str_a ⇒ Object
readonly
Returns the value of attribute str_a.
-
#str_a_arr ⇒ Object
readonly
Returns the value of attribute str_a_arr.
-
#str_b ⇒ Object
readonly
Returns the value of attribute str_b.
-
#str_b_arr ⇒ Object
readonly
Returns the value of attribute str_b_arr.
Instance Method Summary collapse
-
#alignment_inspect ⇒ Object
# === alignment_inspect ========================================================================= #.
-
#do_perform_the_alignment ⇒ Object
# === do_perform_the_alignment ========================================================================= #.
-
#initialize(stra, strb, opts = {}) ⇒ SmithWaterman
constructor
# === initialize.
Constructor Details
#initialize(stra, strb, opts = {}) ⇒ SmithWaterman
#
initialize
Provide the two strings as input.
#
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 57 def initialize( stra, strb, opts = {} ) @str_a = stra @str_b = strb @str_a_arr = stra.unpack('U*') @str_b_arr = strb.unpack('U*') @m = str_a.length + 1 @n = str_b.length + 1 @mat = Matrix.new(m, n) @config = opts end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
50 51 52 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 50 def config @config end |
#m ⇒ Object (readonly)
Returns the value of attribute m.
47 48 49 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 47 def m @m end |
#mat ⇒ Object (readonly)
Returns the value of attribute mat.
49 50 51 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 49 def mat @mat end |
#n ⇒ Object (readonly)
Returns the value of attribute n.
48 49 50 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 48 def n @n end |
#str_a ⇒ Object (readonly)
Returns the value of attribute str_a.
43 44 45 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 43 def str_a @str_a end |
#str_a_arr ⇒ Object (readonly)
Returns the value of attribute str_a_arr.
45 46 47 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 45 def str_a_arr @str_a_arr end |
#str_b ⇒ Object (readonly)
Returns the value of attribute str_b.
44 45 46 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 44 def str_b @str_b end |
#str_b_arr ⇒ Object (readonly)
Returns the value of attribute str_b_arr.
46 47 48 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 46 def str_b_arr @str_b_arr end |
Instance Method Details
#alignment_inspect ⇒ Object
#
alignment_inspect
#
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 82 def alignment_inspect la = '... '.dup lb = '... '.dup alignment.each_with_index { |pos, i| next if i == 0 case alignment[i-1][2] when :down la << [ str_a_arr[pos[0]-1] ].pack('U*') lb << '-' when :right la << '-' lb << [ str_b_arr[pos[1]-1] ].pack('U*') else la << [ str_a_arr[pos[0]-1] ].pack('U*') lb << [ str_b_arr[pos[1]-1] ].pack('U*') end } "#{la} ...\n#{lb} ..." end |
#do_perform_the_alignment ⇒ Object
#
do_perform_the_alignment
#
73 74 75 76 77 |
# File 'lib/bioroebe/string_matching/smith_waterman.rb', line 73 def do_perform_the_alignment do_iterate_over_the_cells find_optimal_path return alignment end |