Class: Bioroebe::GUI::Gtk::DnaToAminoacidWidget

Inherits:
Gtk::Box
  • Object
show all
Includes:
Gtk::BaseModule
Defined in:
lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb

Overview

Bioroebe::GUI::Gtk::DnaToAminoacidWidget

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'DNA to Aminoacid Sequence converter'
WIDTH =
#

WIDTH

#
'80%'
HEIGHT =
#

HEIGHT

#
'35% or minimum 120px'
MAIN_FONT =
#

MAIN_FONT

#
:dejavu_condensed_16
SMALLER_FONT =
#

SMALLER_FONT

#
:dejavu_condensed_14

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ DnaToAminoacidWidget

#

initialize

#

64
65
66
67
68
69
70
71
72
73
74
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 64

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  super(:vertical)
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::DnaToAminoacidWidget[]

#

613
614
615
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 613

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

.run(i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::DnaToAminoacidWidget.run

#

620
621
622
623
624
625
626
627
628
629
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 620

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::Bioroebe::GUI::Gtk::DnaToAminoacidWidget.new(i)
  r = ::Gtk.run
  r << _
  r.automatic_size_then_automatic_title
  r.top_left_then_run
end

Instance Method Details

#assign_this_fasta_file(i) ⇒ Object

#

assign_this_fasta_file

#

499
500
501
502
503
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 499

def assign_this_fasta_file(i)
  i = ::Bioroebe.parse_fasta(i).sequence?
  i.upcase! if i
  set_dna_sequence(i)
end

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)

126
127
128
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 126

def border_size?
  4
end

#button_trigger_the_conversion?Boolean

#

button_trigger_the_conversion?

#

Returns:

  • (Boolean)

211
212
213
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 211

def button_trigger_the_conversion?
  @button_trigger_conversion
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 313

def connect_skeleton
  abort_on_exception
  # ======================================================================= #
  # The two top labels denote which widget is the one for the DNA
  # sequence, and which one is for the aminoacid sequence.
  # ======================================================================= #
  dna_sequence_label       = bold_label('DNA sequence')
  dna_sequence_label.set_size_request(sanitized_half_width, 42)
  aminoacid_sequence_label = bold_label('Aminoacid sequence')
  aminoacid_sequence_label.set_size_request(sanitized_half_width, 42)
  # ======================================================================= #
  # API for .attach() is:
  #   .attach(child, left, top, width, height)
  # ======================================================================= #
  @grid.attach(dna_sequence_label,                    0, 0, 2, 1)
  @grid.attach(aminoacid_sequence_label,              3, 0, 2, 1)
  @grid.attach(@left_entry,                           0, 1, 2, 1)
  @grid.attach(@event_box_containing_the_right_arrow, 2, 1, 1, 1)
  @grid.attach(@right_entry,                          3, 1, 2, 1)
  button_box = simplified_button_box(button_trigger_the_conversion?)
  button_box.set_size_request(350, 40)
  @grid.attach(
    button_box, 0, 2, 5, 1
  )
  minimal(@header_bar)
  add(horizontal_spacer)
  minimal(@grid, 8)
  add(horizontal_spacer)
  hbox = gtk_hbox
  # ======================================================================= #
  # Add the dropdown box next; also known as the combobox.
  # ======================================================================= #
  dropdown_box = gtk_dropdown_box(
    Bioroebe.available_codon_tables?
  )
  dropdown_box.use_this_font = SMALLER_FONT
  dropdown_box.first_element_is_active
  dropdown_box.bblack1
  dropdown_box.pad5px
  dropdown_box.hint = 'When a new codon table is assigned, via the '\
    'drop-down menu, then any assigned DNA sequence will be automatically '\
    'translated to its corresponding amino acid sequence.'
  dropdown_box.on_changed {
    new_text = dropdown_box.text?.to_s
    @entry_for_the_codon_table_in_use.set_text(new_text)
    do_determine_the_aminoacid_sequence
  }
  hbox.minimal(text('Codon table in use:'),       3)
  hbox.minimal(@entry_for_the_codon_table_in_use, 3)
  hbox.minimal(dropdown_box,                      3)
  add(hbox)
  vbox = gtk_vbox
  # ======================================================================= #
  # === @label_n_DNA_nucleotides
  # ======================================================================= #
  @label_n_DNA_nucleotides = bold_label('n DNA nucleotides: ')
  @label_n_DNA_nucleotides.align_left
  @label_n_DNA_nucleotides.make_selectable
  vbox.add(@label_n_DNA_nucleotides)
  @label_n_aminoacids = bold_label('n aminoacids:      ')
  @label_n_aminoacids.align_left
  @label_n_aminoacids.make_selectable
  vbox.add(@label_n_aminoacids)
  minimal(vbox)
end

#create_button_trigger_conversionObject

#

create_button_trigger_conversion

#

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
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 576

def create_button_trigger_conversion
  # ======================================================================= #
  # === @button_trigger_conversion
  # ======================================================================= #
  @button_trigger_conversion = bold_button('_Trigger Conversion')
  @button_trigger_conversion.clear_background
  @button_trigger_conversion.disallow_resizing
  @button_trigger_conversion.set_size_request(125, 40)
  @button_trigger_conversion.set_background_colour :whitesmoke
  @button_trigger_conversion.on_hover(:lightgreen)
  @button_trigger_conversion.on_clicked {
    update_the_dna_sequence_then_do_the_conversion
    do_properly_space_the_top_left_entry
  }
  @button_trigger_conversion.bblack2
  # ======================================================================= #
  # Use a tooltip as well for our button:
  # ======================================================================= #
  @button_trigger_conversion.hint = 
    "Clicking on this button will convert from a <b>DNA</b> "\
    "<b>sequence</b> \n(on the left hand side) to the <b>corresponding "\
    "Aminoacid sequence</b>.\n\nMake sure you input the DNA sequence "\
    "on the left hand side. The space character, aka ' ', will "\
    "be ignored."
end

#create_gridObject

#

create_grid (grid tag)

#

225
226
227
228
229
230
231
232
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 225

def create_grid
  # ======================================================================= #
  # === @grid
  # ======================================================================= #
  @grid = gtk_grid
  @grid.set_column_spacing(5)
  @grid.set_row_spacing(5)
end

#create_skeletonObject

#

create_skeleton (create tag)

#

565
566
567
568
569
570
571
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 565

def create_skeleton
  create_the_header_bar
  create_grid
  create_button_trigger_conversion
  create_the_entries
  create_the_event_box
end

#create_the_entriesObject

#

create_the_entries (entries tag)

#

174
175
176
177
178
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 174

def create_the_entries
  create_the_left_entry
  create_the_right_entry
  create_the_entry_for_the_codon_table_in_use
end

#create_the_entry_for_the_codon_table_in_useObject

#

create_the_entry_for_the_codon_table_in_use

#

183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 183

def create_the_entry_for_the_codon_table_in_use
  # ======================================================================= #
  # === @entry_for_the_codon_table_in_use
  # ======================================================================= #
  @entry_for_the_codon_table_in_use = gtk_entry(Bioroebe.codon_table_in_use?.to_s)
  @entry_for_the_codon_table_in_use.center
  @entry_for_the_codon_table_in_use.bblack2
  @entry_for_the_codon_table_in_use.bg_azure
  @entry_for_the_codon_table_in_use.read_only
  @entry_for_the_codon_table_in_use.use_this_font = SMALLER_FONT
  @entry_for_the_codon_table_in_use.width_height(450, 42)
end

#create_the_event_boxObject

#

create_the_event_box

#

199
200
201
202
203
204
205
206
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 199

def create_the_event_box
  @event_box_containing_the_right_arrow = gtk_eventbox(
    gtk_label(:arrow_right)
  )
  @event_box_containing_the_right_arrow.on_clicked {
    update_the_dna_sequence_then_do_the_conversion
  }
end

#create_the_header_barObject

#

create_the_header_bar

#

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 382

def create_the_header_bar
  @header_bar = return_default_header_bar
  @header_bar.pad8px
  @header_bar.bblack1
  button_open_file = icon_theme(:open_file)
  button_open_file.hint = 'Click on this button to open a '\
                          'local FASTA file.'
  button_open_file.on_clicked {
    result = do_pick_a_local_file
    if result and File.file?(result) and result.end_with?('.fasta','.fa')
      assign_this_fasta_file(result)
    end
  }
  @header_bar.pack_left(button_open_file)
end

#create_the_left_entryObject

#

create_the_left_entry (left tag)

This entry will keep the DNA sequence.

#

479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 479

def create_the_left_entry
  # ======================================================================= #
  # The left entry, a DNA widget as a gtk-entry widget.
  # ======================================================================= #
  @left_entry = gtk_entry
  @left_entry.clear_background
  @left_entry.yellow_background
  @left_entry.bblack1
  @left_entry.pad5px
  @left_entry.set_size_request(sanitized_half_width, 42)
  @left_entry.hint = 'You can either hit the enter key here, or '\
    'click the trigger-conversion button.'
  @left_entry.on_enter_key {
    update_the_dna_sequence_then_do_the_conversion
  }
end

#create_the_right_entryObject

#

create_the_right_entry

#

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 293

def create_the_right_entry
  # ======================================================================= #
  # === The right Aminoacid widget.
  # ======================================================================= #
  @right_entry = gtk_entry
  @right_entry.clear_background
  @right_entry.lightskyblue_background
  @right_entry.bblack1
  @right_entry.pad5px
  @right_entry.set_size_request(sanitized_half_width, 42)
  # ======================================================================= #
  # The AA widget. Will be highlighted on a click event. This was
  # reconsidered and disabled as of August 2021.
  # ======================================================================= #
  # @right_entry.on_click_event { :select_text }
end

#dna_sequence?Boolean Also known as: return_the_main_DNA_sequence

#

dna_sequence?

#

Returns:

  • (Boolean)

167
168
169
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 167

def dna_sequence?
  left_entry?.text.to_s
end

#do_pick_a_local_fileObject

#

do_pick_a_local_file (open tag)

This method is run when the user wants to open a local file.

#

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 403

def do_pick_a_local_file
  create_a_new_file_chooser_dialog(self) {{
    start_dir:              return_pwd,
    show_hidden_files:      :yes,
    current_folder:         ::Bioroebe.log_dir?,
    additional_directories: [
      ::Bioroebe.log_dir?,
      ENV['PC'].to_s,
      ENV['MY_TEMP'].to_s,
      ENV['RSRC'].to_s
    ]
  }}
  _ = ::Gtk.main_file?.to_s
  return _
end

#do_properly_space_the_top_left_entryObject

#

do_properly_space_the_top_left_entry

#

251
252
253
254
255
256
257
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 251

def do_properly_space_the_top_left_entry
  old_text = @left_entry.text?.delete(' ')
  _ = old_text.
      gsub(/(.{3})/,' \1').
      lstrip
  @left_entry.set_text(_)
end

#do_the_conversion(i = @dna_sequence) ⇒ Object Also known as: do_sync_fields, do_trigger_the_conversion, do_determine_the_aminoacid_sequence

#

do_the_conversion (conversion tag)

This is the method that is to be used for the actual conversion.

#

517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 517

def do_the_conversion(
    i = @dna_sequence
  )
  # ======================================================================= #
  # Next, we must translate from DNA to Aminoacid sequence.
  # ======================================================================= #
  sanitized_input = i.delete(' ').delete('-')
  i.tr!('U','T') if i.include? 'U'
  set_dna_sequence(i)
  if ::Bioroebe.const_defined? :Controller
    # ===================================================================== #
    # Ok, in this case we can store the dataset via a class-method.
    # ===================================================================== #
    ::Bioroebe::GUI::Controller.set_dna_sequence(i)
  end
  aminoacid_sequence = ::Bioroebe.convert_dna_to_protein_sequence(
    sanitized_input,
    :default,
    Bioroebe::CodonTable.by_name(
      entry_for_the_codon_table?.text?
    )
  )
  set_aminoacid_sequence(aminoacid_sequence)
  update_the_entries
  sync_the_entries_back_onto_the_two_main_strings
  if @parent_widget and @parent_widget.respond_to?(:set_aminoacid_sequence)
    @parent_widget.set_aminoacid_sequence(aminoacid_sequence)
  end
  @label_n_DNA_nucleotides.set_text(
    'n DNA nucleotides: '+
    i.delete(' ').
      delete('-').size.to_s
  )
  @label_n_DNA_nucleotides.make_bold
  @label_n_DNA_nucleotides.align_left
  @label_n_aminoacids.set_text(
    'n aminoacids:      '+
    aminoacid_sequence.size.to_s
  )
  @label_n_aminoacids.make_bold
  @label_n_aminoacids.align_left
end

#entry_for_the_codon_table?Boolean

#

entry_for_the_codon_table?

#

Returns:

  • (Boolean)

262
263
264
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 262

def entry_for_the_codon_table?
  @entry_for_the_codon_table_in_use
end

#handle_CSS_rulesObject

#

handle_CSS_rules

#

111
112
113
114
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 111

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_CSS_file 
end

#left_entry?Boolean

#

left_entry?

#

Returns:

  • (Boolean)

244
245
246
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 244

def left_entry?
  @left_entry
end
#

menu (menu tag)

#

441
442
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
468
469
470
471
472
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 441

def menu(
    i = commandline_arguments?
  )
  if i and i.is_a?(Array)
    if i.empty?
      set_dna_sequence(:default)
      update_the_left_entry
    else
      i.each {|entry| menu(entry) }
    end
  else
    case i # Perform some sanitizing here. (case tag)
    # ===================================================================== #
    # === ubiquitin
    # ===================================================================== #
    when 'ubiquitin',
         'ubi'
      i = ''
      set_these_aminoacids(
        ::Bioroebe.return_ubiquitin_sequence
      )
    else
      # =================================================================== #
      # Else we will simply assign the DNA sequence as-is. If the input
      # is a .fasta or .fasta file then we will use ParseFasta to obtain
      # the real sequence instead.
      # =================================================================== #
      assign_this_fasta_file(i)
      update_the_left_entry
    end
  end
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)

119
120
121
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 119

def padding?
  8
end

#resetObject

#

reset (reset tag)

#

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 79

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  infer_the_size_automatically
  set_border_width(15) if respond_to? :set_border_width
  signal_destroy_then_quit
  # ======================================================================= #
  # === @dna_sequence
  #
  # This is the dna sequence we will use. We will not work on the
  # entry directly, as this depends on gtk-initialization which
  # may not yet have happened.
  # ======================================================================= #
  @dna_sequence = :default
  # ======================================================================= #
  # === @aminoacid_sequence
  # ======================================================================= #
  @aminoacid_sequence = ''.dup
  # ======================================================================= #
  # === @parent_widget
  # ======================================================================= #
  @parent_widget = nil
  handle_CSS_rules
end

#right_entry?Boolean

#

right_entry?

#

Returns:

  • (Boolean)

269
270
271
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 269

def right_entry?
  @right_entry
end

#runObject

#

run (run tag)

#

605
606
607
608
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 605

def run
  super()
  menu
end

#sanitized_half_widthObject

#

sanitized_half_width

#

237
238
239
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 237

def sanitized_half_width
  (@width / 2) - 30
end

#set_aminoacid_sequence(i) ⇒ Object Also known as: set_these_aminoacids

#

set_aminoacid_sequence

#

508
509
510
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 508

def set_aminoacid_sequence(i)
  @aminoacid_sequence = i
end

#set_dna_sequence(i = left_entry?.text) ⇒ Object

#

set_dna_sequence

#

422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 422

def set_dna_sequence(
    i = left_entry?.text
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    i = 'ATG CGG'.dup
  end
  if i and i.start_with?('--')
    i = '' # Ad-hoc fix.
  end
  @dna_sequence = i.to_s.dup
end

#set_left_entry(i = @dna_sequence) ⇒ Object

#

set_left_entry

#

150
151
152
153
154
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 150

def set_left_entry(
    i = @dna_sequence
  )
  left_entry?.set_text(i)
end

#set_parent_widget(i) ⇒ Object

#

set_parent_widget

#

276
277
278
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 276

def set_parent_widget(i)
  @parent_widget = i
end

#set_right_entry(i = @aminoacid_sequence) ⇒ Object

#

set_right_entry

#

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

def set_right_entry(
    i = @aminoacid_sequence
  )
  right_entry?.set_text(i)
end

#sync_the_entries_back_onto_the_two_main_stringsObject

#

sync_the_entries_back_onto_the_two_main_strings

#

159
160
161
162
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 159

def sync_the_entries_back_onto_the_two_main_strings
  @dna_sequence       = return_the_main_DNA_sequence
  @aminoacid_sequence = right_entry?.text.to_s
end

#update_the_dna_sequence_then_do_the_conversionObject

#

update_the_dna_sequence_then_do_the_conversion

#

283
284
285
286
287
288
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 283

def update_the_dna_sequence_then_do_the_conversion
  set_dna_sequence(
    left_entry?.text.upcase # Upcasing this is more elegant, in my opinion.
  )
  do_the_conversion
end

#update_the_entriesObject

#

update_the_entries

#

133
134
135
136
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 133

def update_the_entries
  set_left_entry
  set_right_entry
end

#update_the_left_entryObject

#

update_the_left_entry

#

218
219
220
# File 'lib/bioroebe/gui/gtk3/dna_to_aminoacid_widget/dna_to_aminoacid_widget.rb', line 218

def update_the_left_entry
  set_left_entry(@dna_sequence.to_s)
end