Class: Bioroebe::GUI::Gtk::HammingDistance
- Inherits:
-
Gtk::Box
- Object
- Gtk::Box
- Bioroebe::GUI::Gtk::HammingDistance
- Includes:
- Gtk::BaseModule
- Defined in:
- lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb
Overview
Bioroebe::GUI::Gtk::HammingDistance
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- WIDTH =
#
WIDTH
#
500
- HEIGHT =
#
HEIGHT
#
320
- TITLE =
#
TITLE
Specify which title to use for this small widget.
#
'Hamming Distance'
- USE_THIS_TITLE =
USE_THIS_TITLE
TITLE
- PADDING_TO_USE =
#
PADDING_TO_USE
#
5
- 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 =
#
SMALLER_FONT
#
:hack_16
- DEFAULT_TEXT_FOR_ENTRY1 =
#
DEFAULT_TEXT_FOR_ENTRY1
#
'AGUUCGAUGGAAAATAT'
- DEFAULT_TEXT_FOR_ENTRY2 =
#
DEFAULT_TEXT_FOR_ENTRY2
#
'AGUCCGGUCGAAAAAAA'
Class Method Summary collapse
-
.run(i = ARGV) ⇒ Object
# === Bioroebe::GUI::Gtk::HammingDistance.run ========================================================================= #.
Instance Method Summary collapse
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#compare_the_two_sequences ⇒ Object
(also: #do_compare, #do_calculate_the_differences)
# === compare_the_two_sequences.
-
#connect_skeleton ⇒ Object
# === connect_skeleton (connect tag) ========================================================================= #.
-
#consider_sanitizing_the_input ⇒ Object
# === consider_sanitizing_the_input ========================================================================= #.
-
#create_compare_button ⇒ Object
# === create_compare_button.
-
#create_entries ⇒ Object
# === create_entries (entries tag, entry tag) ========================================================================= #.
-
#create_skeleton ⇒ Object
# === create_skeleton (create tag, skeleton tag) ========================================================================= #.
-
#do_upcase_all_entries ⇒ Object
# === do_upcase_all_entries ========================================================================= #.
-
#entry1? ⇒ Boolean
# === entry1? ========================================================================= #.
-
#initialize(optional_commandline_arguments = nil, run_already = true) ⇒ HammingDistance
constructor
# === initialize ========================================================================= #.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#seq1? ⇒ Boolean
# === seq1? ========================================================================= #.
-
#seq2? ⇒ Boolean
# === seq2? ========================================================================= #.
-
#set_minimum_size ⇒ Object
# === set_minimum_size ========================================================================= #.
Constructor Details
#initialize(optional_commandline_arguments = nil, run_already = true) ⇒ HammingDistance
#
initialize
#
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 82 def initialize( optional_commandline_arguments = nil, run_already = true ) super(:horizontal) register_sigint reset set_title(USE_THIS_TITLE) if respond_to?(:set_title) if optional_commandline_arguments and respond_to?(:menu) (optional_commandline_arguments) end signal_destroy_then_quit run if run_already end |
Class Method Details
.run(i = ARGV) ⇒ Object
#
Bioroebe::GUI::Gtk::HammingDistance.run
#
368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 368 def self.run( i = ARGV ) require 'gtk_paradise/run' _ = ::Bioroebe::GUI::Gtk::HammingDistance.new(i) r = ::Gtk.run r << _ r.modify_background(:normal, :mintcream) r.automatic_size_then_automatic_title r.top_left_then_run end |
Instance Method Details
#border_size? ⇒ Boolean
#
border_size?
#
123 124 125 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 123 def border_size? 0 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.
#
318 319 320 321 322 323 324 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 318 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_skeleton ⇒ Object
#
connect_skeleton (connect tag)
#
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 292 def connect_skeleton abort_on_exception # ======================================================================= # # @top_box is an instance of gtk-vbox. # ======================================================================= # @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.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) maximal(vpaned, 8) show_all end |
#consider_sanitizing_the_input ⇒ Object
#
consider_sanitizing_the_input
#
342 343 344 345 346 347 348 349 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 342 def consider_sanitizing_the_input # ======================================================================= # # The following two lines were added as of 07.05.2020. # ======================================================================= # @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 |
#create_compare_button ⇒ Object
#
create_compare_button
This method will create the button that will compare the two sequences.
#
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 223 def # ======================================================================= # # === @compare_button # ======================================================================= # @compare_button = (::Bioroebe::GUI::LevenstheinDistanceModule::TEXT_COMPARE_THE_TWO_SEQUENCES) @compare_button.apply_markup @compare_button.lightblue @compare_button.set_name('button1') @compare_button.hint = 'Click this button to '\ '<span weight="bold" foreground="lightblue">compare</span> '\ 'the two sequences.' @compare_button.on_clicked { consider_sanitizing_the_input compare_the_two_sequences } end |
#create_entries ⇒ Object
#
create_entries (entries tag, entry tag)
#
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 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 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 158 def create_entries # ======================================================================= # # === @entry_n_differences # # This is the entry that will simply show the number of differences # between the two sequences, as a number. # ======================================================================= # @entry_n_differences = gtk_entry_with_icon_name('edit-undo-symbolic-rtl.symbolic') @entry_n_differences.xalign = 0.5 # Align towards the center. @entry_n_differences.bblack1 @entry_n_differences.clear_background @entry_n_differences.yellow_background # ======================================================================= # # === @entry_on_top # ======================================================================= # @entry_on_top = gtk_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 { |, event| old_text = .text keyname = Gdk::Keyval.to_name(event.keyval) case keyname.upcase when *%w( A T C G U ) # This is ok. when *%w( B D E F H I J K L M N O P Q R S V W X Y Z ) # Otherwise set the old input here. unless event.state.control_mask? # This snippet checks whether a key-combination has been used. .set_text(old_text.upcase) end end } if false # disabled as of August 2022. # ======================================================================= # # And keep things upcased here: # ======================================================================= # @entry_on_top.on_key_release { |, 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 # ======================================================================= # @entry_on_bottom = gtk_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_skeleton ⇒ Object
#
create_skeleton (create tag, skeleton tag)
#
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 243 def create_skeleton create_entries # ======================================================================= # # === The top box # ======================================================================= # @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." # ======================================================================= # # Create the top hbox for string1 next: # ======================================================================= # @hbox_for_string1 = gtk_hbox @hbox_for_string1.minimal(gtk_label('1').make_bold, 1) @hbox_for_string1.maximal(@entry_on_top, 1) # ======================================================================= # # Create the bottom hbox for string2 next: # ======================================================================= # @hbox_for_string2 = gtk_hbox @hbox_for_string2.minimal(gtk_label('2').make_bold, 1) @hbox_for_string2.maximal(@entry_on_bottom, 1) small_hbox = gtk_hbox # ======================================================================= # # === n_differences found Gtk::Text # ======================================================================= # = gtk_text('<b>n differences</b> found:') .do_markify small_hbox.minimal(, 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) # ======================================================================= # # === The bottom box # ======================================================================= # @bottom_box = gtk_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 |
#do_upcase_all_entries ⇒ Object
#
do_upcase_all_entries
#
330 331 332 333 334 335 336 337 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 330 def do_upcase_all_entries [ @entry_on_top, @entry_on_bottom ].each {|entry| entry.do_upcase } end |
#entry1? ⇒ Boolean
#
entry1?
#
151 152 153 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 151 def entry1? @entry_on_top end |
#padding? ⇒ Boolean
#
padding?
#
116 117 118 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 116 def padding? PADDING_TO_USE end |
#reset ⇒ Object
#
reset (reset tag)
#
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 100 def reset reset_the_internal_variables # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT) use_gtk_paradise_project_CSS_file append_project_CSS_file set_border_width(5) infer_the_size_automatically end |
#run ⇒ Object
#
run (run tag)
#
354 355 356 357 358 359 360 361 362 363 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 354 def run create_skeleton_then_connect_skeleton set_minimum_size Thread.new { sleep 0.01 @entry_n_differences.do_focus entry1?.deselect do_compare } end |
#seq1? ⇒ Boolean
#
seq1?
#
130 131 132 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 130 def seq1? @entry_on_top.text end |
#seq2? ⇒ Boolean
#
seq2?
#
137 138 139 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 137 def seq2? @entry_on_bottom.text end |
#set_minimum_size ⇒ Object
#
set_minimum_size
#
144 145 146 |
# File 'lib/bioroebe/gui/gtk3/hamming_distance/hamming_distance.rb', line 144 def set_minimum_size set_size_request(80, 100) end |