Class: Bioroebe::Levensthein
Overview
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 =
'CGTCAGCGTACTT'
- DEFAULT_STRING2 =
'ATTC--CGTACTT'
CommandlineApplication::OLD_VERBOSE_VALUE
ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Constants inherited
from Base
Base::NAMESPACE
Class Method Summary
collapse
-
.[](i = '') ⇒ Object
# === Bioroebe::Levensthein[] ========================================================================= #.
Instance Method Summary
collapse
-
#ask_the_user_to_assign_different_scores ⇒ Object
-
#calculate_the_amount_of_mismatches_and_gaps ⇒ Object
# === calculate_the_amount_of_mismatches_and_gaps ========================================================================= #.
-
#calculate_the_total_cost ⇒ Object
(also: #total_score?)
# === calculate_the_total_cost ========================================================================= #.
-
#determine_the_edit_distance(string1 = string1? ) ⇒ Object
# === determine_the_edit_distance.
-
#do_report ⇒ Object
(also: #report)
# === do_report (report tag) ========================================================================= #.
-
#edit_distance? ⇒ Boolean
# === edit_distance? ========================================================================= #.
-
#gap_cost? ⇒ Boolean
(also: #score_for_gap?, #score_for_gaps?, #score_for_gaps)
# === gap_cost? ========================================================================= #.
-
#increment_n_gaps_by(i = 1) ⇒ Object
# === increment_n_gaps_by ========================================================================= #.
-
#increment_n_matches_by(i = 1) ⇒ Object
# === increment_n_matches_by ========================================================================= #.
-
#increment_n_mismatches_by(i = 1) ⇒ Object
# === increment_n_mismatches_by ========================================================================= #.
-
#initial_padding_to_use? ⇒ Boolean
# === initial_padding_to_use? ========================================================================= #.
-
#initialize(string1 = nil, string2 = nil, run_already = true) ⇒ Levensthein
constructor
# === initialize ========================================================================= #.
-
#match_cost? ⇒ Boolean
(also: #score_for_match?)
# === match_cost? ========================================================================= #.
-
#menu(i) ⇒ Object
-
#mismatch_cost? ⇒ Boolean
(also: #score_for_mismatch?)
# === mismatch_cost? ========================================================================= #.
-
#n_gaps? ⇒ Boolean
# === n_gaps? ========================================================================= #.
-
#n_matches? ⇒ Boolean
# === n_matches? ========================================================================= #.
-
#n_mismatches? ⇒ Boolean
# === n_mismatches? ========================================================================= #.
-
#parse_string1_and_string2(string1, string2) ⇒ Object
# === parse_string1_and_string2 ========================================================================= #.
-
#report_the_amount_of_mismatches_and_gaps ⇒ Object
# === report_the_amount_of_mismatches_and_gaps.
-
#report_the_edit_distance ⇒ Object
# === report_the_edit_distance ========================================================================= #.
-
#report_the_total_cost ⇒ Object
# === report_the_total_cost.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#reset_the_scores ⇒ Object
(also: #reset_the_score)
# === reset_the_scores ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#set_gap_cost(i = DEFAULT_GAP_COST, optional_be_verbose = false) ⇒ Object
(also: #set_gap_score)
# === set_gap_cost ========================================================================= #.
-
#set_match_cost(i = DEFAULT_MATCH_COST, optional_be_verbose = false) ⇒ Object
(also: #set_match_score)
# === set_match_cost.
-
#set_mismatch_cost(i = DEFAULT_MISMATCH_COST, optional_be_verbose = false) ⇒ Object
(also: #set_mismatch_score)
# === set_mismatch_cost ========================================================================= #.
-
#set_string1(i = nil) ⇒ Object
(also: #string1=, #set_sequence1)
# === set_string1.
-
#set_string2(i = nil) ⇒ Object
(also: #string2=, #set_sequence2)
# === set_string2.
-
#show_first_string ⇒ Object
# === show_first_string ========================================================================= #.
-
#show_help ⇒ Object
# === show_help (help tag).
-
#show_numbered_header ⇒ Object
-
#show_second_string ⇒ Object
# === show_second_string ========================================================================= #.
-
#string1? ⇒ Boolean
(also: #string1, #sequence1?)
# === string1 ========================================================================= #.
-
#string2? ⇒ Boolean
(also: #string2, #sequence2?)
# === string2 ========================================================================= #.
-
#try_to_read_sequences_from_this_file(i, be_verbose = true) ⇒ Object
(also: #read_sequences_from_this_file)
# === try_to_read_sequences_from_this_file.
-
#try_to_use_this_file_as_input(i) ⇒ Object
(also: #use_this_file_for_score=)
#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
#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
#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
#internal_hash?, #reset_the_internal_hash
#infer_the_namespace, #namespace?
Constructor Details
#initialize(string1 = nil, string2 = nil, run_already = true) ⇒ Levensthein
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, string2 = nil, run_already = true
)
reset register_sigint
case string1
when :dont_run_yet
string1 = nil
run_already = false
end
parse_string1_and_string2(string1, string2) if block_given?
yielded = yield
case yielded
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_scores ⇒ Object
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_gaps ⇒ Object
#
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
increment_n_matches_by(1)
else
if (character == '-') or (target_character == '-')
increment_n_gaps_by(1)
else
increment_n_mismatches_by(1)
end
end
}
end
|
#calculate_the_total_cost ⇒ Object
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_report ⇒ Object
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_first_string
show_second_string
e
end
|
#edit_distance? ⇒ 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
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
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?
#
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?
281
282
283
|
# File 'lib/bioroebe/string_matching/levensthein.rb', line 281
def match_cost?
@internal_hash[:match_cost]
end
|
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 (i)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when /^-?-?costs/i,
/^-?-?use(-|_)?different(-|_)?costs/i,
/^-?-?input(-|_)?costs/i
ask_the_user_to_assign_different_scores
when /-?-?read(-|_)?sequences(-|_)?from(-|_)?this(-|_)?file=(.+)/
_ = $5.to_s.dup
try_to_read_sequences_from_this_file(_)
when /-?-?use(-|_)?this(-|_)?file=(.+)/
_ = $3.to_s.dup
try_to_use_this_file_as_input(_)
when /^-?-?help$/i
show_help
exit
when /-?-?start(-|_)?gui$/i,
/-?-?gui$/i disable_warnings
require 'bioroebe/gui/gtk3/levensthein_distance/levensthein_distance.rb'
enable_warnings
::Bioroebe::GUI::Gtk::LevenstheinDistance.start_gui_application
when /^-?-?disable(-|_)?colou?rs$/i
disable_colours
when /^-?-?gap=(.+)/
set_gap_cost($1.to_s.dup)
when /^-?-?match=(.+)/
set_match_cost($1.to_s.dup)
when /^-?-?mismatch=(.+)/
set_mismatch_cost($1.to_s.dup)
end
end
end
|
#mismatch_cost? ⇒ Boolean
Also known as:
score_for_mismatch?
479
480
481
|
# File 'lib/bioroebe/string_matching/levensthein.rb', line 479
def mismatch_cost?
@internal_hash[:mismatch_cost]
end
|
#n_gaps? ⇒ Boolean
274
275
276
|
# File 'lib/bioroebe/string_matching/levensthein.rb', line 274
def n_gaps?
@internal_hash[:n_gaps]
end
|
#n_matches? ⇒ Boolean
260
261
262
|
# File 'lib/bioroebe/string_matching/levensthein.rb', line 260
def n_matches?
@internal_hash[:n_matches]
end
|
#n_mismatches? ⇒ 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
(
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_gaps ⇒ Object
#
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?
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+')' erev ' '+n_mismatches?.to_s+' mismatches '\
'(with a mismatch_cost of: '+
mismatch_cost?.to_s+')' e
end
|
#report_the_edit_distance ⇒ Object
#
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_cost ⇒ Object
#
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
|
#reset ⇒ Object
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
set_be_verbose
@internal_hash[:string1] = nil
@internal_hash[:string2] = nil
@internal_hash[:edit_distance] = 0
@internal_hash[:initial_padding_to_use] = ' '
set_match_cost
set_mismatch_cost
set_gap_cost
reset_the_scores
end
|
#reset_the_scores ⇒ Object
Also known as:
reset_the_score
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
|
#run ⇒ Object
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
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
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_string ⇒ Object
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_help ⇒ Object
#
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
|
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
length = string1.size
result = ''.dup
result << initial_padding_to_use?
1.upto(length) {|number|
if number > 9
number = number.to_s[-1,1].to_i
end
result << number.to_s
}
e lightgreen(result)
end
|
#show_second_string ⇒ Object
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?
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?
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
|
#
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
when /^gap:\s*(-?\d{1,4})/
set_gap_cost($1, :be_verbose)
when /^match:\s*(-?\d{1,4})/
set_match_cost($1, :be_verbose)
when /^mismatch:\s*(-?\d{1,4})/
set_mismatch_cost($1, :be_verbose)
end
}
else
no_file_exists_at(i)
end
end
|