Class: Bioroebe::Levensthein

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

Overview

Bioroebe::Levensthein

Constant Summary collapse

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

Constants inherited from Base

Base::NAMESPACE

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, #opnerev, #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, #runmode?, #set_be_verbose, #set_runmode, #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 BaseModule

#absolute_path, #default_file_read, #file_readlines

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_will_we_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?, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #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

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

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

#

initialize

#


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bioroebe/string_matching/levensthein.rb', line 60

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
      set_be_quiet
    end
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Bioroebe::Levensthein[]

#


673
674
675
# File 'lib/bioroebe/string_matching/levensthein.rb', line 673

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)

#


366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/bioroebe/string_matching/levensthein.rb', line 366

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

#


601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
# File 'lib/bioroebe/string_matching/levensthein.rb', line 601

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

#


573
574
575
576
577
# File 'lib/bioroebe/string_matching/levensthein.rb', line 573

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.

#


291
292
293
294
295
296
297
298
299
# File 'lib/bioroebe/string_matching/levensthein.rb', line 291

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)

#


557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/bioroebe/string_matching/levensthein.rb', line 557

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)


304
305
306
# File 'lib/bioroebe/string_matching/levensthein.rb', line 304

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)


251
252
253
# File 'lib/bioroebe/string_matching/levensthein.rb', line 251

def gap_cost?
  @internal_hash[:gap_cost]
end

#increment_n_gaps_by(i = 1) ⇒ Object

#

increment_n_gaps_by

#


493
494
495
# File 'lib/bioroebe/string_matching/levensthein.rb', line 493

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

#increment_n_matches_by(i = 1) ⇒ Object

#

increment_n_matches_by

#


500
501
502
# File 'lib/bioroebe/string_matching/levensthein.rb', line 500

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

#increment_n_mismatches_by(i = 1) ⇒ Object

#

increment_n_mismatches_by

#


486
487
488
# File 'lib/bioroebe/string_matching/levensthein.rb', line 486

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

#initial_padding_to_use?Boolean

#

initial_padding_to_use?

#

Returns:

  • (Boolean)


136
137
138
# File 'lib/bioroebe/string_matching/levensthein.rb', line 136

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)


281
282
283
# File 'lib/bioroebe/string_matching/levensthein.rb', line 281

def match_cost?
  @internal_hash[:match_cost]
end
#

menu (menu tag)

#


384
385
386
387
388
389
390
391
392
393
394
395
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
# File 'lib/bioroebe/string_matching/levensthein.rb', line 384

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)


479
480
481
# File 'lib/bioroebe/string_matching/levensthein.rb', line 479

def mismatch_cost?
  @internal_hash[:mismatch_cost]
end

#n_gaps?Boolean

#

n_gaps?

#

Returns:

  • (Boolean)


274
275
276
# File 'lib/bioroebe/string_matching/levensthein.rb', line 274

def n_gaps?
  @internal_hash[:n_gaps]
end

#n_matches?Boolean

#

n_matches?

#

Returns:

  • (Boolean)


260
261
262
# File 'lib/bioroebe/string_matching/levensthein.rb', line 260

def n_matches?
  @internal_hash[:n_matches]
end

#n_mismatches?Boolean

#

n_mismatches?

#

Returns:

  • (Boolean)


267
268
269
# File 'lib/bioroebe/string_matching/levensthein.rb', line 267

def n_mismatches?
  @internal_hash[:n_mismatches]
end

#parse_string1_and_string2(string1, string2) ⇒ Object

#

parse_string1_and_string2

#


460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/bioroebe/string_matching/levensthein.rb', line 460

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.

#


632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/bioroebe/string_matching/levensthein.rb', line 632

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

#


450
451
452
453
454
455
# File 'lib/bioroebe/string_matching/levensthein.rb', line 450

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.

#


509
510
511
512
513
514
515
516
517
518
519
# File 'lib/bioroebe/string_matching/levensthein.rb', line 509

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)

#


92
93
94
95
96
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
# File 'lib/bioroebe/string_matching/levensthein.rb', line 92

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === :be_verbose
  # ======================================================================= #
  set_be_verbose
  # ======================================================================= #
  # === :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

#


127
128
129
130
131
# File 'lib/bioroebe/string_matching/levensthein.rb', line 127

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

#runObject

#

run

#


664
665
666
667
668
# File 'lib/bioroebe/string_matching/levensthein.rb', line 664

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

#


188
189
190
191
192
193
194
195
196
197
# File 'lib/bioroebe/string_matching/levensthein.rb', line 188

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.

#


171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/bioroebe/string_matching/levensthein.rb', line 171

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

#


221
222
223
224
225
226
227
228
229
230
# File 'lib/bioroebe/string_matching/levensthein.rb', line 221

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.

#


584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/bioroebe/string_matching/levensthein.rb', line 584

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.

#


204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/bioroebe/string_matching/levensthein.rb', line 204

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

#


543
544
545
# File 'lib/bioroebe/string_matching/levensthein.rb', line 543

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
#


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/bioroebe/string_matching/levensthein.rb', line 148

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

#


524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/bioroebe/string_matching/levensthein.rb', line 524

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

#


550
551
552
# File 'lib/bioroebe/string_matching/levensthein.rb', line 550

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

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

#

string1

#

Returns:

  • (Boolean)


235
236
237
# File 'lib/bioroebe/string_matching/levensthein.rb', line 235

def string1?
  @internal_hash[:string1]
end

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

#

string2

#

Returns:

  • (Boolean)


243
244
245
# File 'lib/bioroebe/string_matching/levensthein.rb', line 243

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.

#


314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/bioroebe/string_matching/levensthein.rb', line 314

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.

#


336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/bioroebe/string_matching/levensthein.rb', line 336

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