Class: Bioroebe::Levensthein

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/string_matching/levensthein.rb

Overview

Bioroebe::Levensthein

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
DEFAULT_MATCH_COST =
#

DEFAULT_MATCH_COST

The default cost for a match between two nucleotide sequences.

#
10
DEFAULT_MISMATCH_COST =
#

DEFAULT_MISMATCH_COST

The default cost for a mismatch between two nucleotide sequences.

#
-3
DEFAULT_GAP_COST =
#

DEFAULT_GAP_COST

The default cost for a gap between two nucleotide sequences.

#
-1
DEFAULT_STRING1 =
#

DEFAULT_STRING1

#
'CGTCAGCGTACTT'
DEFAULT_STRING2 =
#

DEFAULT_STRING2

#
'ATTC--CGTACTT'

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandlineApplication

#all_aminoacids?, #append_what_into, #at_home?, #be_silent, #be_verbose?, #cat, #ccliner, #change_directory, #cliner, #codon_table_dataset?, #codon_to_aminoacid, #codons_for?, #colourize_this_dna_sequence, #complement, #cp, #disable_warnings, #download_dir?, #editor?, #enable_warnings, #ensure_that_the_base_directories_exist, #esystem, #extract, #is_this_a_start_codon?, #is_this_a_stop_codon?, #leading_five_prime, #load_bioroebe_yaml_file, #log_directory?, #one_letter_to_long_name, #one_to_three, #only_numbers?, #open_in_browser, #opne, #opnn, #pad_with_double_quotes, #pad_with_single_quotes, #partner_nucleotide, #remove_numbers, #remove_trailing_ansii_escape_code, #return_all_possible_start_codons, #return_array_of_one_letter_aminoacids, #return_cheerful_person, #return_chunked_display, #return_ubiquitin_sequence, #set_be_verbose, #start_codon?, #stop_codons?, #strict_filter_away_invalid_aminoacids, #taxonomy_download_directory?, #three_to_one, #to_rna, #trailing_three_prime, #use_opn?, #verbose_truth, #was_or_were, #without_extname, #write_what_into

Methods included from CommandlineArguments

#commandline_arguments?, #commandline_arguments_that_are_files?, #e, #first?, #first_non_hyphen_argument?, #remove_hyphens_from_the_commandline_arguments, #return_commandline_arguments_as_string, #return_commandline_arguments_that_are_not_files, #return_entries_without_two_leading_hyphens, #select_commandline_arguments, #select_entries_starting_with_two_hyphens, #set_commandline_arguments

Methods included from ColoursForBase

#colourize_this_aminoacid_sequence_for_the_commandline, #colourize_this_nucleotide_sequence, #disable_colours, #ecomment, #efancy, #egold, #enable_colours, #eorange, #eparse, #erev, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #rev, #sdir, #set_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?

Methods inherited from Base

#append_what_into, #can_base_pair?, #convert_global_env, #delete_file, #directory_to_the_codon_tables?, #file_readlines, #infer_the_namespace, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #namespace?, #no_file_exists_at, #no_newlines, #project_yaml_directory?, #rds, #register_sigint, #return_pwd, #return_the_first_line_of_this_file, #word_wrap, #write_what_into

Constructor Details

#initialize(string1 = nil, string2 = nil, run_already = true) ⇒ Levensthein

#

initialize

#

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bioroebe/string_matching/levensthein.rb', line 65

def initialize(
    string1     = nil, # The first sequence.
    string2     = nil, # The second sequence.
    run_already = true
  )
  reset # reset() must come very early.
  register_sigint
  case string1
  when :dont_run_yet
    string1 = nil
    run_already = false
  end
  parse_string1_and_string2(string1, string2) # Must come after the ^^^ above check.
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :be_quiet
    # ===================================================================== #
    when :be_quiet
      @be_verbose = false
    end
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Bioroebe::Levensthein[]

#

685
686
687
# File 'lib/bioroebe/string_matching/levensthein.rb', line 685

def self.[](i = '')
  new(i)
end

Instance Method Details

#ask_the_user_to_assign_different_scoresObject

#

ask_the_user_to_assign_different_scores (user input)

#

378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/bioroebe/string_matching/levensthein.rb', line 378

def ask_the_user_to_assign_different_scores
  erev 'Input new scores next, for:'
  print '  match_cost: '
  new_match_cost = $stdin.gets.chomp.to_i
  set_match_cost(new_match_cost)
  erev 'The new match_cost will be '+sfancy(@match_cost)+rev+'.'
  print '  mismatch_cost: '
  new_mismatch_cost = $stdin.gets.chomp.to_i
  set_mismatch_cost(new_mismatch_cost)
  erev 'The new mismatch_cost will be '+sfancy(@mismatch_cost)+rev+'.'
  print '  gap_cost: '
  new_gap_cost = $stdin.gets.chomp.to_i
  set_gap_cost(new_gap_cost)
end

#calculate_the_amount_of_mismatches_and_gapsObject

#

calculate_the_amount_of_mismatches_and_gaps

#

613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'lib/bioroebe/string_matching/levensthein.rb', line 613

def calculate_the_amount_of_mismatches_and_gaps
  the_string1 = string1?
  the_string2 = string2?
  process_these_characters = the_string1.chars
  process_these_characters.each_with_index {|character, index|
    target_character = the_string2[index]
    if character == target_character
      # =================================================================== #
      # This must be a match then.
      # =================================================================== #
      increment_n_matches_by(1)
    else
      # =================================================================== #
      # else it is a mismatch UNLESS the target character is '-'.
      # in which case it must be a gap.
      # =================================================================== #
      if (character == '-') or (target_character == '-')
        increment_n_gaps_by(1)
      else
        increment_n_mismatches_by(1)
      end
    end
  }
end

#calculate_the_total_costObject Also known as: total_score?

#

calculate_the_total_cost

#

585
586
587
588
589
# File 'lib/bioroebe/string_matching/levensthein.rb', line 585

def calculate_the_total_cost
  (match_cost?    * n_matches?) +
  (mismatch_cost? * n_mismatches?) +
  (gap_cost?      * n_gaps?)
end

#determine_the_edit_distance(string1 = string1? ) ⇒ Object

#

determine_the_edit_distance

This method will determine the edit distance between our two inputted Strings.

#

303
304
305
306
307
308
309
310
311
# File 'lib/bioroebe/string_matching/levensthein.rb', line 303

def determine_the_edit_distance(
    string1 = string1?
  )
  @internal_hash[:edit_distance] = ::Bioroebe.calculate_levensthein_distance(
    string1,
    string2?,
    :be_quiet
  )
end

#do_reportObject Also known as: report

#

do_report (report tag)

#

569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/bioroebe/string_matching/levensthein.rb', line 569

def do_report
  report_the_edit_distance
  report_the_amount_of_mismatches_and_gaps
  report_the_total_cost
  erev 'Showing the alignment, with index-positions on top: '\
       '(0 means 10 or 20 or 30 etc)'
  e
  show_numbered_header
  show_first_string
  show_second_string
  e
end

#edit_distance?Boolean

#

edit_distance?

#

Returns:

  • (Boolean)

316
317
318
# File 'lib/bioroebe/string_matching/levensthein.rb', line 316

def edit_distance?
  @internal_hash[:edit_distance]
end

#gap_cost?Boolean Also known as: score_for_gap?, score_for_gaps?, score_for_gaps

#

gap_cost?

#

Returns:

  • (Boolean)

263
264
265
# File 'lib/bioroebe/string_matching/levensthein.rb', line 263

def gap_cost?
  @internal_hash[:gap_cost]
end

#increment_n_gaps_by(i = 1) ⇒ Object

#

increment_n_gaps_by

#

505
506
507
# File 'lib/bioroebe/string_matching/levensthein.rb', line 505

def increment_n_gaps_by(i = 1)
  @internal_hash[:n_gaps] += i
end

#increment_n_matches_by(i = 1) ⇒ Object

#

increment_n_matches_by

#

512
513
514
# File 'lib/bioroebe/string_matching/levensthein.rb', line 512

def increment_n_matches_by(i = 1)
  @internal_hash[:n_matches] += i
end

#increment_n_mismatches_by(i = 1) ⇒ Object

#

increment_n_mismatches_by

#

498
499
500
# File 'lib/bioroebe/string_matching/levensthein.rb', line 498

def increment_n_mismatches_by(i = 1)
  @internal_hash[:n_mismatches] += i
end

#initial_padding_to_use?Boolean

#

initial_padding_to_use?

#

Returns:

  • (Boolean)

148
149
150
# File 'lib/bioroebe/string_matching/levensthein.rb', line 148

def initial_padding_to_use?
  @internal_hash[:initial_padding_to_use]
end

#match_cost?Boolean Also known as: score_for_match?

#

match_cost?

#

Returns:

  • (Boolean)

293
294
295
# File 'lib/bioroebe/string_matching/levensthein.rb', line 293

def match_cost?
  @internal_hash[:match_cost]
end
#

menu (menu tag)

#

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/bioroebe/string_matching/levensthein.rb', line 396

def menu(i)
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === levensthein --costs
    # ===================================================================== #
    when /^-?-?costs/i,
         /^-?-?use(-|_)?different(-|_)?costs/i,
         /^-?-?input(-|_)?costs/i
      ask_the_user_to_assign_different_scores
    # ===================================================================== #
    # === levensthein --read_sequences_from_this_file=/Depot/j/foo2.md
    # ===================================================================== #
    when /-?-?read(-|_)?sequences(-|_)?from(-|_)?this(-|_)?file=(.+)/
      _ = $5.to_s.dup
      try_to_read_sequences_from_this_file(_)
    # ===================================================================== #
    # === levensthein --use-this-file=/Depot/j/foo.md
    # ===================================================================== #
    when /-?-?use(-|_)?this(-|_)?file=(.+)/
      _ = $3.to_s.dup
      try_to_use_this_file_as_input(_)
    # ===================================================================== #
    # === levensthein --help
    # ===================================================================== #
    when /^-?-?help$/i
      show_help
      exit
    # ===================================================================== #
    # === levensthein --start-gui
    # ===================================================================== #
    when /-?-?start(-|_)?gui$/i,
         /-?-?gui$/i # leven --GUI
      disable_warnings
      require 'bioroebe/gui/gtk3/levensthein_distance/levensthein_distance.rb'
      enable_warnings
      ::Bioroebe::GUI::Gtk::LevenstheinDistance.start_gui_application
    # ===================================================================== #
    # === levensthein ATG ATT --disable-colours
    # ===================================================================== #
    when /^-?-?disable(-|_)?colou?rs$/i
      disable_colours
    # ===================================================================== #
    # === levensthein --gap=
    # ===================================================================== #
    when /^-?-?gap=(.+)/
      set_gap_cost($1.to_s.dup)
    # ===================================================================== #
    # === levensthein --match=
    # ===================================================================== #
    when /^-?-?match=(.+)/
      set_match_cost($1.to_s.dup)
    # ===================================================================== #
    # === levensthein --mismatch=
    # ===================================================================== #
    when /^-?-?mismatch=(.+)/
      set_mismatch_cost($1.to_s.dup)
    end
  end
end

#mismatch_cost?Boolean Also known as: score_for_mismatch?

#

mismatch_cost?

#

Returns:

  • (Boolean)

491
492
493
# File 'lib/bioroebe/string_matching/levensthein.rb', line 491

def mismatch_cost?
  @internal_hash[:mismatch_cost]
end

#n_gaps?Boolean

#

n_gaps?

#

Returns:

  • (Boolean)

286
287
288
# File 'lib/bioroebe/string_matching/levensthein.rb', line 286

def n_gaps?
  @internal_hash[:n_gaps]
end

#n_matches?Boolean

#

n_matches?

#

Returns:

  • (Boolean)

272
273
274
# File 'lib/bioroebe/string_matching/levensthein.rb', line 272

def n_matches?
  @internal_hash[:n_matches]
end

#n_mismatches?Boolean

#

n_mismatches?

#

Returns:

  • (Boolean)

279
280
281
# File 'lib/bioroebe/string_matching/levensthein.rb', line 279

def n_mismatches?
  @internal_hash[:n_mismatches]
end

#parse_string1_and_string2(string1, string2) ⇒ Object

#

parse_string1_and_string2

#

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/bioroebe/string_matching/levensthein.rb', line 472

def parse_string1_and_string2(
    string1, string2
  )
  if string1.is_a? Array
    menu(
      select_two_hyphens_from(string1)
    )
    remove_hyphens_from(string1)
  end
  if string1.is_a?(Array) and string2.nil? and (string1.size > 1)
    string2 = string1.pop
  end
  set_string1(string1)
  set_string2(string2)
end

#report_the_amount_of_mismatches_and_gapsObject

#

report_the_amount_of_mismatches_and_gaps

This method will report how many mismatches and gaps can be found in the main sequence at hand.

#

644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/bioroebe/string_matching/levensthein.rb', line 644

def report_the_amount_of_mismatches_and_gaps
  the_string1 = string1?
  the_string2 = string2?
  # ======================================================================= #
  # First, report the amount of gaps:
  # ======================================================================= #
  if the_string2.include? '-'
    n_gaps = the_string2.count('-').to_s
  elsif the_string1.include? '-'
    n_gaps = the_string1.count('-').to_s
  end
  e
  erev 'The '+mediumseagreen('edit distance')+
       rev+
       ' (that is, only the '+
        slateblue('changes')+rev+') has exactly:'
  e
  plural_or_singular_of_gaps = 'gap'.dup
  plural_or_singular_of_gaps << 's' if n_gaps.to_i > 1
  erev ' '+n_gaps.to_s.rjust(2)+' '+
       plural_or_singular_of_gaps.ljust(11)+
       '(with a gap_cost of:      '+
       gap_cost?.to_s+')' # Report the gaps here, and their cost
  erev '  '+n_mismatches?.to_s+' mismatches '\
       '(with a mismatch_cost of: '+
       mismatch_cost?.to_s+')' # Report the mismatches here, and their cost
  e
end

#report_the_edit_distanceObject

#

report_the_edit_distance

#

462
463
464
465
466
467
# File 'lib/bioroebe/string_matching/levensthein.rb', line 462

def report_the_edit_distance
  erev 'The '+springgreen('Levensthein-distance')+
       rev+' (edit distance) between these '
  erev 'two strings is `'+sfancy(edit_distance?.to_s)+rev+
       '`. (Size of first string is: '+string1.size.to_s+')'
end

#report_the_total_costObject

#

report_the_total_cost

This method will calculate the total score.

#

521
522
523
524
525
526
527
528
529
530
531
# File 'lib/bioroebe/string_matching/levensthein.rb', line 521

def report_the_total_cost
  total_cost = 0
  total_cost += calculate_the_total_cost
  formatted_match_cost = match_cost?.to_s.dup
  unless formatted_match_cost.include? '-'
    formatted_match_cost.prepend('+')
  end
  erev 'The total cost (== score) is: '+sfancy(total_cost.to_s)+rev+' '\
       '(match cost was: '+formatted_match_cost+')'
  e
end

#resetObject

#

reset (reset tag)

#

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/bioroebe/string_matching/levensthein.rb', line 97

def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose = true
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :string1
  # ======================================================================= #
  @internal_hash[:string1] = nil
  # ======================================================================= #
  # === :string2
  # ======================================================================= #
  @internal_hash[:string2] = nil
  # ======================================================================= #
  # === :edit_distance
  # ======================================================================= #
  @internal_hash[:edit_distance] = 0
  # ======================================================================= #
  # === :initial_padding_to_use
  # ======================================================================= #
  @internal_hash[:initial_padding_to_use] = '  '
  # ======================================================================= #
  # Setup the default cost for a match, a mismatch and a gap.
  # ======================================================================= #
  set_match_cost
  set_mismatch_cost
  set_gap_cost
  reset_the_scores
end

#reset_the_scoresObject Also known as: reset_the_score

#

reset_the_scores

#

139
140
141
142
143
# File 'lib/bioroebe/string_matching/levensthein.rb', line 139

def reset_the_scores
  @internal_hash[:n_mismatches] = 0
  @internal_hash[:n_matches]    = 0
  @internal_hash[:n_gaps]       = 0
end

#runObject

#

run

#

676
677
678
679
680
# File 'lib/bioroebe/string_matching/levensthein.rb', line 676

def run
  determine_the_edit_distance
  calculate_the_amount_of_mismatches_and_gaps
  do_report if be_verbose?
end

#set_gap_cost(i = DEFAULT_GAP_COST, optional_be_verbose = false) ⇒ Object Also known as: set_gap_score

#

set_gap_cost

#

200
201
202
203
204
205
206
207
208
209
# File 'lib/bioroebe/string_matching/levensthein.rb', line 200

def set_gap_cost(
    i                   = DEFAULT_GAP_COST,
    optional_be_verbose = false
  )
  i = i.to_i
  if optional_be_verbose == :be_verbose
    erev "Setting the gap cost to #{sfancy(i.to_s)}#{rev}"
  end
  @internal_hash[:gap_cost] = i
end

#set_match_cost(i = DEFAULT_MATCH_COST, optional_be_verbose = false) ⇒ Object Also known as: set_match_score

#

set_match_cost

This method sets the cost for a match.

#

183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/bioroebe/string_matching/levensthein.rb', line 183

def set_match_cost(
    i                   = DEFAULT_MATCH_COST,
    optional_be_verbose = false
  )
  if i.to_s.include? '+'
    i = i.to_s.delete('+')
  end
  i = i.to_i
  if optional_be_verbose == :be_verbose
    erev 'Setting the match cost to '+sfancy(i.to_s)+rev
  end
  @internal_hash[:match_cost] = i
end

#set_mismatch_cost(i = DEFAULT_MISMATCH_COST, optional_be_verbose = false) ⇒ Object Also known as: set_mismatch_score

#

set_mismatch_cost

#

233
234
235
236
237
238
239
240
241
242
# File 'lib/bioroebe/string_matching/levensthein.rb', line 233

def set_mismatch_cost(
    i                   = DEFAULT_MISMATCH_COST,
    optional_be_verbose = false
  )
  i = i.to_i
  if optional_be_verbose == :be_verbose
    erev 'Setting the mismatch cost to '+sfancy(i.to_s)+rev
  end
  @internal_hash[:mismatch_cost] = i
end

#set_string1(i = nil) ⇒ Object Also known as: string1=, set_sequence1

#

set_string1

This method can be used to assign the value to string1.

#

596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/bioroebe/string_matching/levensthein.rb', line 596

def set_string1(i = nil)
  if i.is_a? Array
    i = i.first
  end
  case i
  when :default_value,
       :default
    i = DEFAULT_STRING1
  end
  i = i.to_s.dup.chomp unless i.is_a? Symbol
  @internal_hash[:string1] = i
end

#set_string2(i = nil) ⇒ Object Also known as: string2=, set_sequence2

#

set_string2

This method can be used to assign the value to string2.

#

216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/bioroebe/string_matching/levensthein.rb', line 216

def set_string2(i = nil)
  if i.is_a? Array
    i = i.first
  end
  case i
  when :default_value,
       :default
    i = DEFAULT_STRING2
  end
  i = i.to_s.dup.chomp unless i.is_a? Symbol
  @internal_hash[:string2] = i
end

#show_first_stringObject

#

show_first_string

#

555
556
557
# File 'lib/bioroebe/string_matching/levensthein.rb', line 555

def show_first_string
  e orange(initial_padding_to_use?+string1?)
end

#show_helpObject

#

show_help (help tag)

Invoke this method via:

levensthein --show-help
#

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/bioroebe/string_matching/levensthein.rb', line 160

def show_help
  e
  erev 'You can use the following commandline-flag to read the scores '\
       'from an'
  erev 'existing file:'
  e
  e steelblue('  levensthein --use-this-file=/Depot/j/foo.md')
  e
  erev 'In order to use different costs, set interactively by the user, use:'
  e
  e steelblue('  levensthein --costs')
  e
  erev 'If you wish to start the gtk-GUI component, do:'
  e
  e steelblue('  levensthein --start-gui')
  e
end

#show_numbered_headerObject

#

show_numbered_header

#

536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/bioroebe/string_matching/levensthein.rb', line 536

def show_numbered_header
  length = string1.size
  result = ''.dup
  result << initial_padding_to_use?
  1.upto(length) {|number|
    if number > 9
      # =================================================================== #
      # In this case chop it down to below 10.
      # =================================================================== #
      number = number.to_s[-1,1].to_i
    end
    result << number.to_s
  }
  e lightgreen(result)
end

#show_second_stringObject

#

show_second_string

#

562
563
564
# File 'lib/bioroebe/string_matching/levensthein.rb', line 562

def show_second_string
  e orange(initial_padding_to_use?+string2?)
end

#string1?Boolean Also known as: string1, sequence1?

#

string1

#

Returns:

  • (Boolean)

247
248
249
# File 'lib/bioroebe/string_matching/levensthein.rb', line 247

def string1?
  @internal_hash[:string1]
end

#string2?Boolean Also known as: string2, sequence2?

#

string2

#

Returns:

  • (Boolean)

255
256
257
# File 'lib/bioroebe/string_matching/levensthein.rb', line 255

def string2?
  @internal_hash[:string2]
end

#try_to_read_sequences_from_this_file(i, be_verbose = true) ⇒ Object Also known as: read_sequences_from_this_file

#

try_to_read_sequences_from_this_file

This method can be used to read in one or two sequences from an existing file.

#

326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/bioroebe/string_matching/levensthein.rb', line 326

def try_to_read_sequences_from_this_file(
    i, be_verbose = true
  )
  if File.exist? i
    if be_verbose
      e "Trying to read in the sequence from the file `#{sfile(i)}`."
    end
    dataset = readlines(i)
    set_string1(dataset[0])
    set_string2(dataset[1]) if dataset.size > 1
  else
    no_file_exists_at(i)
  end
end

#try_to_use_this_file_as_input(i) ⇒ Object Also known as: use_this_file_for_score=

#

try_to_use_this_file_as_input

This method can be used to read from an existing file and assign match, mismatch and gap scores. This can be useful if you wish to NOT use the default hardcoded values in this class.

#

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/bioroebe/string_matching/levensthein.rb', line 348

def try_to_use_this_file_as_input(i)
  if File.exist? i
    dataset = file_readlines(i)
    dataset.each {|line|
      case line
      # ==================================================================== #
      # === gap
      # ==================================================================== #
      when /^gap:\s*(-?\d{1,4})/
        set_gap_cost($1, :be_verbose)
      # ==================================================================== #
      # === match
      # ==================================================================== #
      when /^match:\s*(-?\d{1,4})/
        set_match_cost($1, :be_verbose)
      # ==================================================================== #
      # === mismatch
      # ==================================================================== #
      when /^mismatch:\s*(-?\d{1,4})/
        set_mismatch_cost($1, :be_verbose)
      end
    }
  else
    no_file_exists_at(i)
  end
end