Class: Bioroebe::GUI::UniversalWidgets::HammingDistance
- Inherits:
-
UniversalWidgets::Base
- Object
- UniversalWidgets::Base
- Bioroebe::GUI::UniversalWidgets::HammingDistance
show all
- Includes:
- CommandlineArguments, Bioroebe::GUI
- Defined in:
- lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb
Overview
Constant Summary
collapse
- TITLE =
#
TITLE
Specify which title to use for this small widget.
#
'Hamming Distance'
- USE_THIS_TITLE =
TITLE
- WIDTH =
'65% or 500px minimum'
- HEIGHT =
'55% or 300px minimum'
- TEXT_COMPARE_THE_TWO_SEQUENCES =
#
TEXT_COMPARE_THE_TWO_SEQUENCES
#
'_Compare the two sequences'
- MONOSPACED_FONT =
#
MONOSPACED_FONT
When this font is changed, don’t forget to also change the font at SMALLER_FONT.
#
:hack_20
- USE_THIS_FONT =
MONOSPACED_FONT
- SMALLER_FONT =
:hack_16
- USE_THIS_SLIGHTLY_SMALLER_FONT =
#
USE_THIS_SLIGHTLY_SMALLER_FONT
#
:hack_16
- USE_THIS_TITLE_FOR_THE_MAIN_BUTTON =
#
USE_THIS_TITLE_FOR_THE_MAIN_BUTTON
#
'_Determine the DNA sequence'
- PADDING_TO_USE =
12
- DEFAULT_TEXT_FOR_ENTRY1 =
#
DEFAULT_TEXT_FOR_ENTRY1
#
'AGUUCGAUGGAAAATAT'
- DEFAULT_TEXT_FOR_ENTRY2 =
#
DEFAULT_TEXT_FOR_ENTRY2
#
'AGUCCGGUCGAAAAAAA'
ARRAY_ALL_GTK_WIDGETS, FONT_SIZE, OLD_VERBOSE_VALUE, Bioroebe::GUI::USE_THIS_FONT_FAMILY_FOR_GUI_APPLICATIONS
ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Class Method Summary
collapse
Instance Method Summary
collapse
#disable_warnings, #enable_warnings, #log_dir?
#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?
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ HammingDistance
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 100
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
624
625
626
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 624
def self.[](i = ARGV)
new(i)
end
|
.run(i = ARGV) ⇒ Object
#
Bioroebe::GUI::Gtk::HammingDistance.run
#
631
632
633
634
635
636
637
638
639
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 631
def self.run(
i = ARGV
)
r = ::Gtk.runner_factory(
::Bioroebe::GUI::Gtk::HammingDistance.new(i)
)
r.modify_background(:normal, :mintcream)
return r
end
|
Instance Method Details
#aminoacid_sequence? ⇒ Boolean
411
412
413
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 411
def aminoacid_sequence?
left_buffer?.to_s
end
|
#border_size? ⇒ Boolean
154
155
156
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 154
def border_size?
8
end
|
#compare_the_two_sequences ⇒ Object
Also known as:
do_compare, do_calculate_the_differences
#
compare_the_two_sequences
This is the method that will compare the two sequences.
#
535
536
537
538
539
540
541
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 535
def compare_the_two_sequences
do_upcase_all_entries
hamming_distance_object = ::Bioroebe::HammingDistance.new("#{seq1?} #{seq2?}") { :be_quiet }
@entry_n_differences.set_text(
hamming_distance_object.n_differences?.to_s
)
end
|
#connect_the_skeleton ⇒ Object
#
connect_the_skeleton (connect tag, skeleton tag)
#
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 571
def connect_the_skeleton
abort_on_exception
@top_box.minimal(@label_on_top, 1)
text = left_aligned_text(
"The <b>Hamming distance</b> - a number - measures the number of "\
"\npositions at which two strings of equal length are "\
"different.")
text.make_selectable
text.use_this_font = SMALLER_FONT
@top_box.minimal(text, 12)
@top_box.minimal(@hbox_for_string1, 2)
@top_box.minimal(@hbox_for_string2, 2)
vpaned = mouse_draggable_via_up_and_down_movement(@top_box, @bottom_box)
vpaned.set_size_request(width?, 550)
Thread.new {
sleep 0.01
@entry_n_differences.do_focus
entry1?.deselect
do_compare
}
window = runner_widget(nil, width?, height?, title?)
window << vpaned
::UniversalWidgets.set_main_window(window)
upon_delete_event_quit_the_application
jump_into_the_first_entry
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.set_size_request(80, 100)
window.top_left
run_main
end
|
559
560
561
562
563
564
565
566
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 559
def consider_sanitizing_the_input
@entry_on_top.set_text(@entry_on_top.text.delete('-'))
@entry_on_bottom.set_text(@entry_on_bottom.text.delete('-'))
do_upcase_all_entries
end
|
463
464
465
466
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 463
def consider_sanitizing_the_input_and_then_compare_the_two_sequences
consider_sanitizing_the_input
compare_the_two_sequences
end
|
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 353
def create_buttons
backtrack_button = bold_button(
USE_THIS_TITLE_FOR_THE_MAIN_BUTTON, self, :use_mnemonic
) {
:do_determine_the_backtrack_sequence
}
backtrack_button.set_name('button1')
backtrack_button.do_use_underline
backtrack_button.hint =
"On the <b>left hand side</b>, you should input the "\
"Aminoacid sequence.\n\n"\
"On the <b>right hand side</b>, a possible DNA "\
"sequence for this Aminoacid Sequence will "\
"be displayed.\n\n"\
"Invalid amino acids, such as 'U', will be filtered "\
"out, if given.\n\n"\
"Note that this will not necessarily "\
"generate the same sequence, due to several different codons "\
"encoding for the same aminoacid."
backtrack_button.on_hover_lightblue
@dataset[:backtrack_button] = backtrack_button
a_quit_button = quit_button
a_quit_button.set_name('button1')
a_quit_button.make_bold
@dataset[:quit_button] = a_quit_button
end
|
#
This method will create the button that will compare the two sequences.
#
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 445
def create_compare_button
@compare_button = bold_button(TEXT_COMPARE_THE_TWO_SEQUENCES, self, :use_mnemonics) {
:consider_sanitizing_the_input_and_then_compare_the_two_sequences
}
@compare_button.apply_markup
@compare_button.on_hover(:lightblue)
@compare_button.set_name('button1')
@compare_button.hint = 'Click this button to '\
'<span weight="bold" foreground="lightblue">compare</span> '\
'the two sequences.'
end
|
#create_left_buffer ⇒ Object
294
295
296
297
298
299
300
301
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 294
def create_left_buffer
@dataset[:left_buffer] = create_text_view @dataset[:left_buffer].bblack1
@dataset[:left_buffer].do_wrap_properly
end
|
#create_middle_bar_containing_the_arrow_pointing_to_the_right_side ⇒ Object
#
create_middle_bar_containing_the_arrow_pointing_to_the_right_side
#
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 245
def create_middle_bar_containing_the_arrow_pointing_to_the_right_side
@middle_bar = create_vbox
event_box = create_eventbox(
create_label(:arrow_right)
)
event_box.hint =
'This arrow can be clicked, to convert from the aminoacid sequence '\
'to (one likely) possible DNA sequence.'
event_box.on_clicked {
do_determine_the_backtrack_sequence
}
@middle_bar.minimal(
event_box
)
end
|
#create_right_buffer ⇒ Object
135
136
137
138
139
140
141
142
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 135
def create_right_buffer
@dataset[:right_buffer] = create_text_view @dataset[:right_buffer].bblack1
@dataset[:right_buffer].do_wrap_properly
end
|
#create_the_entries ⇒ Object
#
create_the_entries (entries tag, entry tag)
#
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 182
def create_the_entries
@entry_n_differences = entry_with_icon_name('edit-undo-symbolic-rtl.symbolic')
@entry_n_differences.xalign = 0.5 @entry_n_differences.bblack1
@entry_n_differences.clear_background
@entry_n_differences.yellow_background
@entry_on_top = create_entry(DEFAULT_TEXT_FOR_ENTRY1)
@entry_on_top.set_font(MONOSPACED_FONT)
@entry_on_top.clear_background
@entry_on_top.css_class('BG_lightsteelblue')
@entry_on_top.bblack1
@entry_on_top.on_changed { do_calculate_the_differences }
@entry_on_top.hint = 'This entry should contain the first sequence (seq1).'
@entry_on_top.set_max_length(50_000)
@entry_on_top.on_key_press_event { |widget, event|
old_text = widget.text
keyname = Gdk::Keyval.to_name(event.keyval)
case keyname.upcase
when *%w( A T C G U )
when *%w( B D E F H I J K L M N O P Q R S V W X Y Z ) unless event.state.control_mask? widget.set_text(old_text.upcase)
end
end
} if false @entry_on_top.on_key_release { |widget, event|
old_text = @entry_on_top.text
new_text = @entry_on_top.text.upcase
unless old_text == new_text
@entry_on_top.set_text(new_text)
@entry_on_top.move_cursor_to_the_most_right_position
end
}
@entry_on_bottom = create_entry(DEFAULT_TEXT_FOR_ENTRY2)
@entry_on_bottom.set_font(MONOSPACED_FONT)
@entry_on_bottom.css_classes('clear_background BG_lightsteelblue')
@entry_on_bottom.bblack1
@entry_on_bottom.on_changed { do_calculate_the_differences }
@entry_on_bottom.hint = 'This entry should contain the second sequence (seq2).'
@entry_on_bottom.set_max_length(50_000)
end
|
#create_the_skeleton ⇒ Object
#
create_the_skeleton (create tag, skeleton tag)
#
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 471
def create_the_skeleton
create_the_entries
@top_box = vbox
@label_on_top = bold_label(USE_THIS_TITLE)
@label_on_top.hint =
"Only <b>valid nucleotides</b> (A, T, C, G, U) \n"\
"can be accepted as input."
@hbox_for_string1 = create_hbox
@hbox_for_string1.minimal(text('1').make_bold, 1)
@hbox_for_string1.maximal(@entry_on_top, 1)
@hbox_for_string2 = create_hbox
@hbox_for_string2.minimal(text('2').make_bold, 1)
@hbox_for_string2.maximal(@entry_on_bottom, 1)
create_compare_button
small_hbox = create_hbox
short_text_widget = text('<b>n differences</b> found:')
short_text_widget.do_markify
small_hbox.minimal(short_text_widget, 2)
small_hbox.hint =
'This entry will show <b>how many differences</b> '\
'exist between these two strings.'
small_hbox.minimal(@entry_n_differences, 2)
@bottom_box = create_vbox
@bottom_box.pack_start(@compare_button, expand: false, fill: false, padding: 1)
@bottom_box.pack_start(small_hbox, expand: false, fill: true, padding: 0)
end
|
#create_top_hbox ⇒ Object
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 264
def create_top_hbox
scrolled_window_right = scrolled_window(right_buffer?)
scrolled_window_right.clear_background
scrolled_window_right.width_height(300, 300)
scrolled_window_right.bblack1
scrolled_window_right.mar2px
scrolled_window_left = scrolled_window(left_buffer?)
scrolled_window_left.clear_background
scrolled_window_left.width_height(300, 300)
scrolled_window_left.bblack1
scrolled_window_left.mar2px
top_hpaned = gtk_hpaned(
scrolled_window_left,
scrolled_window_right
) {{ border_width: 10 }}
this_position = (width?.to_f / 1.5).to_i
top_hpaned.set_position(this_position)
top_hpaned.show_all
@dataset[:top_hbox] = top_hpaned
end
|
#do_determine_the_backtrack_sequence ⇒ Object
Also known as:
do_determine_the_DNA_sequence
#
do_determine_the_backtrack_sequence (click tag)
This will do what is necessary to find the backtrack sequence.
#
427
428
429
430
431
432
433
434
435
436
437
438
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 427
def do_determine_the_backtrack_sequence
filter_away_invalid_aminoacids_from_the_left_buffer
_ = left_buffer?.text?.to_s
_.upcase!
_ = ::Bioroebe.remove_invalid_aminoacids(_)
left_buffer?.set_text(_)
text_for_right_hand_side = ::Bioroebe::ProteinToDNA.new(_, :be_quiet).dna_sequence?
right_buffer?.set_text(text_for_right_hand_side)
end
|
#do_upcase_all_entries ⇒ Object
#
do_upcase_all_entries
#
547
548
549
550
551
552
553
554
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 547
def do_upcase_all_entries
[
@entry_on_top,
@entry_on_bottom
].each {|entry|
entry.do_upcase
}
end
|
#entry1? ⇒ Boolean
Also known as:
entry1
175
176
177
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 175
def entry1?
@entry_on_top
end
|
#filter_away_invalid_aminoacids_from_the_left_buffer ⇒ Object
#
filter_away_invalid_aminoacids_from_the_left_buffer
This method is used to “sanitize” the input - invalid aminoacids are flat out removed.
#
386
387
388
389
390
391
392
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 386
def filter_away_invalid_aminoacids_from_the_left_buffer
_ = left_buffer?.text?.to_s
possible_new_text = Bioroebe.strict_filter_away_invalid_aminoacids(_)
unless _ == possible_new_text
left_buffer?.set_text(possible_new_text)
end
end
|
#handle_CSS_rules ⇒ Object
Also known as:
handle_CSS
#
handle_CSS_rules (CSS tag, css tag)
#
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 320
def handle_CSS_rules
use_gtk_paradise_project_css_file
append_project_css_file
add_these_custom_CSS_rules '
#custom_treeview.view header button {
background-color: white;
color: royalblue;
font-weight: bold;
font-size: larger;
padding: 8px;
}'
apply_the_CSS_rules
end
|
#jump_into_the_first_entry ⇒ Object
#
jump_into_the_first_entry
#
617
618
619
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 617
def jump_into_the_first_entry
entry1?.do_focus
end
|
#left_buffer? ⇒ Boolean
Also known as:
left?
418
419
420
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 418
def left_buffer?
@dataset[:left_buffer]
end
|
#main_font? ⇒ Boolean
306
307
308
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 306
def main_font?
USE_THIS_FONT
end
|
338
339
340
341
342
343
344
345
346
347
348
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 338
def (i = nil)
if i
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when ''
end
end
end
end
|
#padding? ⇒ Boolean
147
148
149
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 147
def padding?
PADDING_TO_USE
end
|
#reset ⇒ Object
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 115
def reset
super() if respond_to?(:super)
reset_the_internal_variables
reset_the_base_module infer_the_namespace
@configuration = [true, __dir__, namespace?]
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
handle_CSS if use_gtk3?
set_border_width(5)
end
|
#right_buffer? ⇒ Boolean
Also known as:
right?
397
398
399
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 397
def right_buffer?
@dataset[:right_buffer]
end
|
#run ⇒ Object
520
521
522
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 520
def run
run_super
end
|
#seq1? ⇒ Boolean
161
162
163
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 161
def seq1?
@entry_on_top.text
end
|
#seq2? ⇒ Boolean
168
169
170
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 168
def seq2?
@entry_on_bottom.text
end
|
#set_aminoacid_sequence(i) ⇒ Object
#
set_aminoacid_sequence
#
404
405
406
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 404
def set_aminoacid_sequence(i)
@dataset[:left_buffer].set_text(i.to_s)
end
|
#slightly_smaller_font? ⇒ Boolean
#
slightly_smaller_font?
#
313
314
315
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 313
def slightly_smaller_font?
USE_THIS_SLIGHTLY_SMALLER_FONT
end
|
#top_hbox? ⇒ Boolean
527
528
529
|
# File 'lib/bioroebe/gui/universal_widgets/hamming_distance/hamming_distance.rb', line 527
def top_hbox?
@dataset[:top_hbox]
end
|