Class: Bioroebe::GUI::UniversalWidgets::DnaToReverseComplementWidget

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

Overview

Bioroebe::GUI::UniversalWidgets::DnaToReverseComplementWidget

Constant Summary collapse

TITLE =
#

TITLE

Specify which title to use for this small widget.

#
'DNA to Reverse Complement'
WIDTH =
#

WIDTH

#
'65% or 500px minimum'
HEIGHT =
#

HEIGHT

#
'55% or 300px minimum'
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
USE_THIS_SLIGHTLY_SMALLER_FONT =
#

USE_THIS_SLIGHTLY_SMALLER_FONT

#
:hack_16

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) ⇒ DnaToReverseComplementWidget

#

initialize

#


73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 73

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::DnaToReverseComplementWidget[]

#


452
453
454
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 452

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

.run(i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::DnaToReverseComplementWidget.run

#


459
460
461
462
463
464
465
466
467
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 459

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

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


323
324
325
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 323

def border_size?
  0
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag, skeleton tag)

#


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
446
447
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 409

def connect_the_skeleton
  abort_on_exception

  vbox = create_vbox

  @grid.left  @dna_sequence_label
  @grid.middle text('')
  @grid.right @reverse_complement_sequence_label
  @grid.left  @left_input_field_dna
  @grid.middle @event_box_containing_the_right_arrow
  @grid.right @right_input_field_aa
  @grid.full_row(
    @button_trigger_conversion,
    :default,
    :default,
    3
  )
  vbox.minimal(@grid)
  vbox.minimal(horizontal_separator)
  vbox.minimal(@label_n_nucleotides)

  window = runner_widget(nil, width?, height?, title?)
  window << vbox

  ::UniversalWidgets.set_main_window(window)
  upon_delete_event_quit_the_application
  handle_commandline_arguments # This must come after the GUI skeleton was created.
  let_the_left_entry_react_to_enter_events

  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

#consider_sanitizing_the_left_input_field_for_dnaObject

#

consider_sanitizing_the_left_input_field_for_dna

#


236
237
238
239
240
241
242
243
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 236

def consider_sanitizing_the_left_input_field_for_dna
  _ = @left_input_field_dna.text?.dup
  if _.include? 'U'
    _.tr!('U','T')
  end
  _.upcase!
  set_dna_sequence(_)
end

#create_button_trigger_conversionObject

#

create_button_trigger_conversion

#


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 168

def create_button_trigger_conversion
  # ======================================================================= #
  # === @button_trigger_conversion
  # ======================================================================= #
  @button_trigger_conversion = bold_button('_Trigger Conversion', self, :use_mnemonics) {
    :do_sync_the_fields
  }
  @button_trigger_conversion.clear_background
  @button_trigger_conversion.set_background_colour :whitesmoke
  @button_trigger_conversion.on_hover(:lightgreen)
  @button_trigger_conversion.bblack1
  # ======================================================================= #
  # Use a tooltip as well for our button:
  # ======================================================================= #
  @button_trigger_conversion.hint = 
    "Clicking on this button will convert from a <b>DNA</b>\n"\
    "<b>sequence</b> to the <b>corresponding reverse "\
    "complement sequence</b>.\n\nMake sure you input the DNA sequence "\
    "on the left hand side."
end

#create_hbox_containing_the_two_input_fieldsObject

#

create_hbox_containing_the_two_input_fields

This method will combine the two widgets.

#


301
302
303
304
305
306
307
308
309
310
311
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 301

def create_hbox_containing_the_two_input_fields
  
  # ========================================================================= #
  # In the middle will be a small arrow, though.
  # ========================================================================= #
  @hbox_containing_the_two_input_fields.maximal(@left_input_field_dna)
  if use_gtk3?
    @hbox_containing_the_two_input_fields.minimal(@event_box_containing_the_right_arrow)
  end
  @hbox_containing_the_two_input_fields.maximal(@right_input_field_aa)
end

#create_input_fieldsObject

#

create_input_fields

These are the two input fields, also known as “gtk-entries”.

#


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 194

def create_input_fields
  # ======================================================================= #
  # The DNA widget, a gtk-entry widget.
  # ======================================================================= #
  @left_input_field_dna = input_field
  @left_input_field_dna.width_height(600, 20)
  @left_input_field_dna.very_light_yellowish_background
  @left_input_field_dna.hint = 'Input your DNA sequence here. Upon '\
    'clicking on the arrow or hitting the <b>enter</b> key, the sequence is '\
    'first converted to DNA, and then the reverse complement is '\
    'calculated. Afterwards the result is shown on the right input '\
    'field.'
  # ======================================================================= #
  # === The right widget.
  # ======================================================================= #
  @right_input_field_aa = input_field
  @right_input_field_aa.very_light_yellowish_background
  # ======================================================================= #
  # The AA widget. Will be highlighted on a click event.
  # ======================================================================= #
  if @right_input_field_aa.respond_to? :on_click_event
    @right_input_field_aa.on_click_event { :highlight_text }
  end
end

#create_the_event_boxObject

#

create_the_event_box

#


382
383
384
385
386
387
388
389
390
391
392
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 382

def create_the_event_box
  # ======================================================================= #
  # === @event_box_containing_the_right_arrow
  # ======================================================================= #
  @event_box_containing_the_right_arrow = create_eventbox(
    create_label(:arrow_right)
  )
  @event_box_containing_the_right_arrow.on_clicked {
    do_sync_the_fields
  }
end

#create_the_gridObject

#

create_the_grid

#


397
398
399
400
401
402
403
404
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 397

def create_the_grid
  # ======================================================================= #
  # === @grid
  # ======================================================================= #
  @grid = default_grid
  @grid.set_column_spacing(6)
  @grid.set_row_spacing(6)
end

#create_the_skeletonObject

#

create_the_skeleton (create tag, skeleton tag)

#


359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 359

def create_the_skeleton
  @label_n_nucleotides = text
  create_input_fields
  # ======================================================================= #
  # === @dna_sequence_label
  # ======================================================================= #
  @dna_sequence_label = return_dna_sequence_label
  create_the_grid
  create_the_event_box
  create_button_trigger_conversion
  create_the_top_labels
end

#create_the_top_labelsObject

#

create_the_top_labels

The two top labels denote which widget is the one for the DNA sequence, and which one is for the aminoacid sequence.

#


153
154
155
156
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 153

def create_the_top_labels
  @dna_sequence_label = return_dna_sequence_label
  @reverse_complement_sequence_label = return_reverse_complement_to_that_dna_sequence
end

#do_sync_the_fieldsObject

#

do_sync_the_fields

This method will sync between the two main widgets - the DNA input field on the left, and the reverse complement on the right side.

#


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 110

def do_sync_the_fields
  consider_sanitizing_the_left_input_field_for_dna
  _ = @left_input_field_dna.text?
  if ::Bioroebe.const_defined? :Controller
    # ===================================================================== #
    # Ok, in this case we can store the dataset via a class-method.
    # ===================================================================== #
    ::Bioroebe::GUI::Controller.set_dna_sequence(_)
  end
  # ======================================================================= #
  # Next, we must translate from DNA to the reverse complement sequence.
  # ======================================================================= #
  _ = ::Bioroebe.complement(_)
  set_reverse_complement(_.reverse)
  n_nucleotides = _.size
  @label_n_nucleotides.set_text(
    'This DNA sequence contains <b>'+n_nucleotides.to_s+'</b> nucleotides.'
  )
  @label_n_nucleotides.do_markify
end

#favicon?Boolean

#

favicon?

#

Returns:

  • (Boolean)


222
223
224
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 222

def favicon?
  :tabble
end

#handle_commandline_argumentsObject

#

handle_commandline_arguments

#


289
290
291
292
293
294
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 289

def handle_commandline_arguments
  input = input?
  if input and !input.empty? and !input.include?('--') # Reject commandline-arguments, though.
    set_dna_sequence(input)
  end
end

#handle_CSS_rulesObject Also known as: handle_CSS

#

handle_CSS_rules (CSS tag, css tag)

#


344
345
346
347
348
349
350
351
352
353
354
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 344

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  add_these_custom_CSS_rules '

 grid {
    padding: 20px;
  }
  '
  apply_the_CSS_rules
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


282
283
284
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 282

def input?
  @input
end

#let_the_left_entry_react_to_enter_eventsObject

#

let_the_left_entry_react_to_enter_events

#


141
142
143
144
145
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 141

def let_the_left_entry_react_to_enter_events
  @left_input_field_dna.on_enter {
    do_sync_the_fields unless @left_input_field_dna.text?.empty?
  }
end

#main_font?Boolean

#

main_font?

#

Returns:

  • (Boolean)


330
331
332
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 330

def main_font?
  USE_THIS_FONT
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


316
317
318
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 316

def padding?
  2
end

#resetObject

#

reset (reset tag)

#


88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 88

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?
end

#return_dna_sequence_labelObject

#

return_dna_sequence_label

#


134
135
136
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 134

def return_dna_sequence_label
  bold_label('DNA sequence')
end

#return_reverse_complement_to_that_dna_sequenceObject

#

return_reverse_complement_to_that_dna_sequence

#


161
162
163
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 161

def return_reverse_complement_to_that_dna_sequence
  bold_label('Reverse complement to that DNA sequence')
end

#runObject

#

run (run tag)

#


375
376
377
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 375

def run
  run_super
end

#set_dna_sequence(i = input? ) ⇒ Object

#

set_dna_sequence

This method will set to the input-field on the left hand side.

#


250
251
252
253
254
255
256
257
258
259
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 250

def set_dna_sequence(
    i = input?
  )
  if i.is_a? Array
    i = i.join(' ').strip
  end
  unless i.include?('--') # Reject commandline-arguments, though.
    @left_input_field_dna.set_text(i)
  end
end

#set_input(i = '') ⇒ Object

#

set_input

#


264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 264

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  case i # Perform some sanitizing here. (case tag)
  # ======================================================================= #
  # === ubiquitin
  # ======================================================================= #
  when 'ubiquitin',
       'ubi'
    i = ''
    set_these_aminoacids(::Bioroebe.return_ubiquitin_sequence)
  end
  @input = i
end

#set_reverse_complement(i) ⇒ Object

#

set_reverse_complement

#


229
230
231
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 229

def set_reverse_complement(i)
  @right_input_field_aa.set_text(i)
end

#slightly_smaller_font?Boolean

#

slightly_smaller_font?

#

Returns:

  • (Boolean)


337
338
339
# File 'lib/bioroebe/gui/universal_widgets/dna_to_reverse_complement_widget/dna_to_reverse_complement_widget.rb', line 337

def slightly_smaller_font?
  USE_THIS_SLIGHTLY_SMALLER_FONT
end