Class: Bioroebe::GUI::UniversalWidgets::LevenstheinDistance

Inherits:
UniversalWidgets::Base
  • Object
show all
Includes:
CommandlineArguments, Bioroebe::GUI
Defined in:
lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb

Overview

Bioroebe::GUI::UniversalWidgets::LevenstheinDistance

Constant Summary collapse

TITLE =
#

TITLE

Specify which title to use for this widget.

#
'Levensthein Distance'
WIDTH =
#

WIDTH

#
'75% or 900px minimum'
HEIGHT =
#

HEIGHT

#
'55% or 440px minimum'
FONT_LARGE =
#

FONT_LARGE

#
'Calibri 32'
MONOSPACED_FONT =
#

MONOSPACED_FONT

When this font is changed, don’t forget to also change the font at SMALLER_FONT.

#
:hack_22
USE_THIS_FONT =
MONOSPACED_FONT
USE_THIS_MONOFONT =
MONOSPACED_FONT
SMALLER_FONT =
#

SMALLER_FONT

#
:hack_16
USE_THIS_SLIGHTLY_SMALLER_FONT =
#

USE_THIS_SLIGHTLY_SMALLER_FONT

#
:hack_16
USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET =
#

USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET

This constant can be used to designate the background colour to be used for the widget.

#
:white
INPUT_HINT =
#

INPUT_HINT

#
"Hit the enter-key to compare the two sequences. Don't forget to "\
"assign two sequences first, e. g. ATG and then ATT, as an example."
TEXT_COMPARE_THE_TWO_SEQUENCES =
#

Bioroebe::GUI::LevenstheinDistanceModule::TEXT_COMPARE_THE_TWO_SEQUENCES

#
'_Compare the two sequences'

Constants included from Bioroebe::GUI

ARRAY_ALL_GTK_WIDGETS, FONT_SIZE, OLD_VERBOSE_VALUE, Bioroebe::GUI::USE_THIS_FONT_FAMILY_FOR_GUI_APPLICATIONS

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bioroebe::GUI

#disable_warnings, #enable_warnings, #log_dir?

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?

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ LevenstheinDistance

#

initialize

#


101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 101

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  determine_the_GUI_to_be_used(commandline_arguments)
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Bioroebe::GUI::UniversalWidgets::LevenstheinDistance[]

#


607
608
609
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 607

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

.run(i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::LevenstheinDistance.run

#


614
615
616
617
618
619
620
621
622
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 614

def self.run(
    i = ARGV
  )
  r = ::Gtk.runner_factory(
    ::Bioroebe::GUI::Gtk::LevenstheinDistance.new(i)
  )
  r.modify_background(:normal, :mintcream)
  return r
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


143
144
145
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 143

def border_size?
  4
end

#check_for_commandline_arguments(commandline_arguments = commandline_arguments? ) ⇒ Object Also known as: parse_the_commandline_arguments

#

check_for_commandline_arguments

#


496
497
498
499
500
501
502
503
504
505
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 496

def check_for_commandline_arguments(
    commandline_arguments = commandline_arguments?
  )
  if commandline_arguments and commandline_arguments.is_a?(Array)
    unless commandline_arguments.empty?
      set_entry1(commandline_arguments[0])
      set_entry2(commandline_arguments[1])
    end
  end
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag, skeleton tag)

#


539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 539

def connect_the_skeleton
  abort_on_exception

  vbox1 = create_vbox
  populate_the_grid
  vbox1.minimal(@grid, 4)
  if levensthein_object?.sequence1?
    unless levensthein_object?.sequence1?.empty?
      @input_for_string1.set_text(levensthein_object?.sequence1?)
    end
  end
  if levensthein_object?.sequence2?
    unless levensthein_object?.sequence2?.empty?
      @input_for_string2.set_text(levensthein_object?.sequence2?)
    end
  end
  vbox1.minimal(@input_for_string1, 4)
  vbox1.minimal(@input_for_string2, 4)
  # ======================================================================= #
  # Next below these two input-fields we will add more info:
  # ======================================================================= #
  small_label = return_the_edit_distance_label
  @hbox_with_the_label_for_the_edit_distance = return_hbox_containing_the_edit_distance(
    small_label, @label_for_the_edit_distance
  )
  @hbox4 = return_hbox4(
    @label_for_the_total_score
  )
  vbox1.minimal(@hbox_with_the_label_for_the_edit_distance, 4)
  vbox1.minimal(@hbox4, 4)
  button_box = create_button_box(
    @button_compare_the_two_strings
  ) { :spread }
  vbox1.minimal(button_box, 4)

  window = runner_widget(nil, width?, height?, title?)
  window << vbox1
  
  check_for_commandline_arguments
  do_compare_the_two_sequences
  let_the_fist_entry_respond_to_on_changed_events

  ::UniversalWidgets.set_main_window(window)
  jump_into_the_first_entry
  upon_delete_event_quit_the_application
  window.use_this_font = font?
  window.show_all
  window.set_size_request(width?, height?)
  window.set_default_size(width?, height?)
  window.set_padding(padding?)
  window.set_border_size(border_size?)
  window.modify_background(
    :normal, USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET
  )
  window.top_left
  run_main
end

#create_the_buttonsObject

#

create_the_buttons

#


271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 271

def create_the_buttons
  # ======================================================================= #
  # === @button_compare_the_two_strings
  # ======================================================================= #
  @button_compare_the_two_strings = bold_button(
    TEXT_COMPARE_THE_TWO_SEQUENCES, self, :use_mnemonics
  ) {
    do_compare_the_two_strings
  }
  @button_compare_the_two_strings.clear_background
  @button_compare_the_two_strings.set_size_request(200, 40)
  @button_compare_the_two_strings.set_border_width(4)
  @button_compare_the_two_strings.bblack2
  @button_compare_the_two_strings.hint =
    'Click to compare the two sequences. Ideally use the '\
    '<b>same length</b> for the two sequences. Make sure to '\
    'click it once more after you are done, as the auto-calculation '\
    'currently does NOT take the second entry into '\
    'consideration.'
  @button_compare_the_two_strings.on_hover(:lightcyan) 
end

#create_the_entriesObject

#

create_the_entries (entries tag, entry tag)

#


510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 510

def create_the_entries
  # ======================================================================= #
  # Next, add the two input-fields for our two nucleotide sequences.
  # ======================================================================= #
  # ======================================================================= #
  # === @input_for_string1
  # ======================================================================= #
  @input_for_string1 = input
  @input_for_string1.light_green_background
  @input_for_string1.bblack1
  @input_for_string1.css_class('pad4px')
  @input_for_string1.on_enter { do_compare_the_two_strings }
  @input_for_string1.use_this_font = USE_THIS_MONOFONT
  @input_for_string1.hint = INPUT_HINT
  # ======================================================================= #
  # === @input_for_string2
  # ======================================================================= #
  @input_for_string2 = input
  @input_for_string2.light_green_background
  @input_for_string2.bblack1
  @input_for_string2.css_class('pad4px')
  @input_for_string2.on_enter { do_compare_the_two_strings }
  @input_for_string2.use_this_font = USE_THIS_MONOFONT
  @input_for_string2.hint = INPUT_HINT
end

#create_the_first_rowObject

#

create_the_first_row

#


318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 318

def create_the_first_row
  # ======================================================================= #
  # === @text1
  # ======================================================================= #
  @text1 = bold_text_left_aligned('Score for match (match cost): ')
  @text1.make_selectable
  # ======================================================================= #
  # === @input_field_for_matches
  # ======================================================================= #
  @input_field_for_matches = spinbutton(-50, 150)
  @input_field_for_matches.bblack1
  @input_field_for_matches.center
  @input_field_for_matches.yellow_background
  @input_field_for_matches.set_size_request(100, 40)
  @input_field_for_matches.set_value(
    levensthein_object?.score_for_match?.to_s.to_i
  )
  @input_field_for_matches.align_to_center
  @input_field_for_matches.on_changed {
    recalculate_the_score
  }
end

#create_the_gridObject

#

create_the_grid (grid tag)

#


150
151
152
153
154
155
156
157
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 150

def create_the_grid
  # ======================================================================= #
  # === @grid
  # ======================================================================= #
  @grid = create_grid
  @grid.set_column_spacing(4)
  @grid.set_row_spacing(4)
end

#create_the_labelsObject

#

create_the_labels

#


365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 365

def create_the_labels
  # ======================================================================= #
  # === @label_for_the_total_score
  # ======================================================================= #
  @label_for_the_total_score = text('0')
  @label_for_the_total_score.use_this_font = USE_THIS_MONOFONT
  @label_for_the_total_score.make_bold
  @label_for_the_total_score.make_selectable
  # ======================================================================= #
  # === @label_for_the_edit_distance
  # ======================================================================= #
  @label_for_the_edit_distance = return_the_label_for_the_edit_distance
end

#create_the_second_rowObject

#

create_the_second_row

#


415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 415

def create_the_second_row
  # ======================================================================= #
  # === Score for mismatch
  # ======================================================================= #
  @text2 = bold_text_left_aligned('Score for mismatch (mismatch cost): ')
  @text2.make_selectable
  # ======================================================================= #
  # === @input_field_for_mismatches
  # ======================================================================= #
  @input_field_for_mismatches = spinbutton(-50, 150)
  @input_field_for_mismatches.center
  @input_field_for_mismatches.yellow_background
  @input_field_for_mismatches.bblack1
  @input_field_for_mismatches.set_size_request(100, 40)
  @input_field_for_mismatches.set_value(
    levensthein_object?.score_for_mismatch?.to_s.to_i
  )
  @input_field_for_mismatches.align_to_center
  @input_field_for_mismatches.on_changed {
    recalculate_the_score
  }
end

#create_the_skeletonObject

#

create_the_skeleton (create tag, skeleton tag)

#


199
200
201
202
203
204
205
206
207
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 199

def create_the_skeleton
  create_the_entries
  create_the_labels
  create_the_grid
  create_the_first_row
  create_the_second_row
  create_the_third_row
  create_the_buttons
end

#create_the_third_rowObject

#

create_the_third_row

#


296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 296

def create_the_third_row
  # ======================================================================= #
  # === @text3
  # ======================================================================= #
  @text3 = bold_text_left_aligned(
    'Score for gap (gap cost): '
  )
  @input_field_for_gap_cost = spinbutton(-50, 150)
  @input_field_for_gap_cost.yellow_background
  @input_field_for_gap_cost.bblack1
  @input_field_for_gap_cost.set_value(
    levensthein_object?.score_for_gaps?.to_s.to_i
  )
  @input_field_for_gap_cost.align_to_center
  @input_field_for_gap_cost.on_changed {
    recalculate_the_score
  }
end

#do_compare_the_two_strings(text1 = entry1?.text?, text2 = entry2?.text?) ⇒ Object Also known as: do_compare_the_two_sequences, recalculate_the_score

#

do_compare_the_two_strings (click tag)

This is the main action of the widget.

#


443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 443

def do_compare_the_two_strings(
    text1 = entry1?.text?,
    text2 = entry2?.text?
  )
  # ======================================================================= #
  # First capitalize the two entries:
  # ======================================================================= #
  entry1?.set_text(text1.upcase)
  entry2?.set_text(text2.upcase)
  @levensthein_object.reset_the_score
  @levensthein_object.set_match_score(@input_field_for_matches.text?)
  @levensthein_object.set_mismatch_score(@input_field_for_mismatches.text?)
  @levensthein_object.set_gap_score(input_field_for_gap_cost?.text?)
  @levensthein_object.set_string1(text1)
  @levensthein_object.set_string2(text2)
  @levensthein_object.run
  set_edit_distance(
    @levensthein_object.edit_distance?
  )
  total_score = @levensthein_object.total_score?.to_s
  unless text2.empty?
    @label_for_the_total_score.set_text(total_score)
    @label_for_the_total_score.make_bold
  end
end

#entry1?Boolean Also known as: entry1, entry?

#

entry1?

#

Returns:

  • (Boolean)


389
390
391
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 389

def entry1?
  @input_for_string1
end

#entry2?Boolean

#

entry2?

#

Returns:

  • (Boolean)


397
398
399
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 397

def entry2?
  @input_for_string2
end

#handle_CSS_rulesObject Also known as: handle_CSS

#

handle_CSS_rules (CSS tag, css tag)

#


188
189
190
191
192
193
194
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 188

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  add_these_custom_CSS_rules '
'
  apply_the_CSS_rules
end

#input_field_for_gap_cost?Boolean

#

input_field_for_gap_cost?

#

Returns:

  • (Boolean)


245
246
247
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 245

def input_field_for_gap_cost?
  @input_field_for_gap_cost
end

#instantiate_a_new_levensthein_objectObject

#

instantiate_a_new_levensthein_object

#


219
220
221
222
223
224
225
226
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 219

def instantiate_a_new_levensthein_object
  # ======================================================================= #
  # === @levensthein_object
  # ======================================================================= #
  @levensthein_object = ::Bioroebe::Levensthein.new(:dont_run_yet) {
    :be_quiet
  }
end

#jump_into_the_first_entryObject

#

jump_into_the_first_entry

#


600
601
602
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 600

def jump_into_the_first_entry
  entry1?.do_focus
end

#let_the_fist_entry_respond_to_on_changed_events(widget_to_use = @input_for_string1) ⇒ Object

#

let_the_fist_entry_respond_to_on_changed_events

#


404
405
406
407
408
409
410
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 404

def let_the_fist_entry_respond_to_on_changed_events(
    widget_to_use = @input_for_string1
  )
  widget_to_use.on_changed {
    do_compare_the_two_sequences
  }
end

#levensthein_object?Boolean Also known as: levensthein

#

levensthein_object?

#

Returns:

  • (Boolean)


231
232
233
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 231

def levensthein_object?
  @levensthein_object
end

#main_font?Boolean

#

main_font?

#

Returns:

  • (Boolean)


174
175
176
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 174

def main_font?
  USE_THIS_FONT
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


136
137
138
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 136

def padding?
  12
end

#populate_the_gridObject

#

populate_the_grid

#


162
163
164
165
166
167
168
169
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 162

def populate_the_grid
  @grid.left(@text1)
  @grid.right(@input_field_for_matches)
  @grid.left(@text2)
  @grid.right(@input_field_for_mismatches)
  @grid.left(@text3)
  @grid.right(@input_field_for_gap_cost)
end

#resetObject

#

reset (reset tag)

#


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 116

def reset
  super() if respond_to?(:super)
  reset_the_internal_variables
  reset_the_base_module # This must come after reset_the_internal_variables().
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  handle_CSS if use_gtk3?
  instantiate_a_new_levensthein_object
end

#return_hbox4(label_for_the_total_score = @label_for_the_total_score) ⇒ Object

#

return_hbox4

#


344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 344

def return_hbox4(
    label_for_the_total_score = @label_for_the_total_score
  )
  # ======================================================================= #
  # === Total score: label
  # ======================================================================= #
  small_label_for_total_score = bold_label('Total score:     ')
  small_label_for_total_score.make_selectable
  # ======================================================================= #
  # === @hbox4
  # ======================================================================= #
  hbox4 = hbox(
    small_label_for_total_score,
    label_for_the_total_score
  )
  return hbox4 
end

#return_hbox_containing_the_edit_distance(small_label, label_for_the_edit_distance) ⇒ Object

#

return_hbox_containing_the_edit_distance

#


484
485
486
487
488
489
490
491
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 484

def return_hbox_containing_the_edit_distance(
    small_label,
    label_for_the_edit_distance
  )
  return hbox(
    small_label, label_for_the_edit_distance
  )
end

#return_the_edit_distance_labelObject

#

return_the_edit_distance_label

#


473
474
475
476
477
478
479
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 473

def return_the_edit_distance_label
  small_label = bold_label('Edit distance: ')
  small_label.make_selectable
  small_label.hint = 'This number tells us how many differences '\
                     'exist between the two sequences at hand.'
  return small_label
end

#return_the_label_for_the_edit_distanceObject

#

return_the_label_for_the_edit_distance

#


261
262
263
264
265
266
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 261

def return_the_label_for_the_edit_distance
  label_for_the_edit_distance = text('0')
  label_for_the_edit_distance.use_this_font = USE_THIS_MONOFONT
  label_for_the_edit_distance.make_bold
  return label_for_the_edit_distance
end

#runObject

#

run (run tag)

#


212
213
214
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 212

def run
  run_super
end

#set_edit_distance(i) ⇒ Object

#

set_edit_distance

#


252
253
254
255
256
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 252

def set_edit_distance(i)
  i = i.to_s
  @label_for_the_edit_distance.set_text(i.rjust(2))
  @label_for_the_edit_distance.make_bold
end

#set_entry1(i) ⇒ Object

#

set_entry1

#


382
383
384
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 382

def set_entry1(i)
  entry1?.set_text(i.to_s) unless i and i.start_with? '--'
end

#set_entry2(i) ⇒ Object

#

set_entry2

#


238
239
240
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 238

def set_entry2(i)
  entry2?.set_text(i.to_s) unless i and i.start_with? '--'
end

#slightly_smaller_font?Boolean

#

slightly_smaller_font?

#

Returns:

  • (Boolean)


181
182
183
# File 'lib/bioroebe/gui/universal_widgets/levensthein_distance/levensthein_distance.rb', line 181

def slightly_smaller_font?
  USE_THIS_SLIGHTLY_SMALLER_FONT
end