Class: Bioroebe::GUI::Gtk::PrimerDesignWidget

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

Overview

Bioroebe::GUI::Gtk::PrimerDesignWidget

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Primer Design'
WIDTH =
#

WIDTH

#
'80% or minimum 800px'
HEIGHT =
#

HEIGHT

#
'70% or minimum 500px'
PADDING_OF_THE_WHOLE_WIDGET =
#

PADDING_OF_THE_WHOLE_WIDGET

#
12
HUGE_FONT =
#

HUGE_FONT

#
:hack_25
USE_THIS_FONT =
#

USE_THIS_FONT

#
:hack_18
SMALLER_FONT =
#

SMALLER_FONT

#
:hack_17
COLOUR_FOR_NON_MATCHES =
#

COLOUR_FOR_NON_MATCHES

This is the colour that will be used for non-matching nucleotides.

#
:magenta

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

#

initialize

#

78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 78

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

Class Method Details

.run(i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::PrimerDesignWidget.run

#

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

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

Instance Method Details

#add_the_header_barObject

#

add_the_header_bar

#

120
121
122
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 120

def add_the_header_bar
  minimal(@header_bar, 4)
end

#add_the_main_labelObject

#

add_the_main_label

#

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

def add_the_main_label
  @main_label = gtk_left_aligned_label(TITLE)
  @main_label.make_bold
  @main_label.use_this_font = HUGE_FONT
  minimal(@main_label)
end

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)

338
339
340
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 338

def border_size?
  2
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#

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
241
242
243
244
245
246
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 212

def connect_skeleton
  abort_on_exception
  add_the_header_bar
  add_the_main_label
  outer_vbox = gtk_vbox
  outer_vbox.minimal(@top_primer, 8)
  outer_vbox.minimal(gtk_hspacer)
  outer_vbox.minimal(@top_strand)
  @bottom_strand = gtk_bold_label("3'-#{@reverse_sequence}-5'")
  @bottom_strand.darkgreen
  outer_vbox.minimal(@bottom_strand)
  outer_vbox.minimal(gtk_hspacer)
  outer_vbox.minimal(@bottom_primer, 8)
  hbox = gtk_hbox
  hbox.minimal(text('Amplified area:'), 1)
  hbox.minimal(@amplified_area, 1)
  outer_vbox.minimal(hbox, 1)
  # ======================================================================= #
  # === The reverse primer will be added here
  # ======================================================================= #
  hbox = return_widget_containing_the_reverse_primer_information
  outer_vbox.minimal(hbox, 1)
  # ======================================================================= #
  # === The forward primer will be added here
  # ======================================================================= #
  hbox = return_widget_containing_the_forward_primer_information
  outer_vbox.minimal(hbox, 1)
  maximal(
    add_an_up_and_down_dragger(
      outer_vbox,
      @scrolled_window
    )
  )
  sync_forward_and_reverse_primer
end

#create_entriesObject

#

create_entries (entries tag, entry tag)

#

150
151
152
153
154
155
156
157
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
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 150

def create_entries
  # ======================================================================= #
  # === @amplified_area
  # ======================================================================= #
  @amplified_area = gtk_entry
  @amplified_area.set_text('TACGTACG')
  @amplified_area.clear_background
  @amplified_area.lightblue_background
  @amplified_area.bblack1
  @amplified_area.pad5px
  # ======================================================================= #
  # === @reverse_primer
  # ======================================================================= #
  @reverse_primer = gtk_entry
  @reverse_primer.yellow_background
  @reverse_primer.bblack1
  @reverse_primer.width_height(250, 50)
  @reverse_primer.set_text(@reverse_sequence.reverse[0,3])
  @reverse_primer.hint = ''
  @reverse_primer.on_changed {
    @reverse_primer.set_text(@reverse_primer.text?.upcase)
    sync_the_reverse_primer
    do_calculate_GC_content_for_the_reverse_primer
  }
  # ======================================================================= #
  # === @forward_primer
  # ======================================================================= #
  @forward_primer = gtk_entry
  @forward_primer.yellow_background
  @forward_primer.bblack1
  @forward_primer.width_height(250, 50)
  @forward_primer.set_text('ATG')
  @forward_primer.on_changed {
    @forward_primer.set_text(@forward_primer.text?.upcase)
    sync_the_forward_primer
    do_calculate_GC_content_for_the_forward_primer
  }
  @forward_primer.hint = "The forward primer is the sequence "\
    "corresponding to the sense strand (5'→3'). It appears "\
    "on the bottom side of the above text."
end

#create_scrolled_windowObject

#

create_scrolled_window (scrolled tag)

#

135
136
137
138
139
140
141
142
143
144
145
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 135

def create_scrolled_window
  @text_buffer = gtk_text_buffer
  @text_view = gtk_text_view(@text_buffer)
  # ======================================================================= #
  # === @scrolled_window
  # ======================================================================= #
  @scrolled_window = gtk_scrolled_window(@text_view) { :always }
  @scrolled_window.bblack1
  @scrolled_window.pad8px
  @scrolled_window.width_height(500, 400)
end

#create_skeletonObject

#

create_skeleton (create tag)

#

359
360
361
362
363
364
365
366
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 359

def create_skeleton
  create_entries
  create_the_header_bar
  create_scrolled_window
  create_the_top_primer
  create_the_top_strand
  create_the_bottom_primer
end

#create_the_bottom_primerObject

#

create_the_bottom_primer

#

371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 371

def create_the_bottom_primer
  # ======================================================================= #
  # === @bottom_primer
  # ======================================================================= #
  @bottom_primer = gtk_bold_label
  @bottom_primer.make_selectable
  @bottom_primer.tomato
  @bottom_primer.hint = 'This is the forward primer. A '\
    'match will be shown in green colour, whereas a '\
    'non-match will be shown in the '+
    COLOUR_FOR_NON_MATCHES.to_s+'-colour.'
end

#create_the_header_barObject

#

create_the_header_bar

#

387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 387

def create_the_header_bar
  @header_bar = default_header_bar
  @header_bar.pad8px
  @header_bar.bblack1
  event_box = gtk_event_box(image_information)
  event_box.hint = 'Click on this image to show some information '\
                   'about <b>primer design</b> in a PCR.'
  event_box.on_clicked {
    do_pop_up_the_widget_containing_information_about_primer_design_in_a_PCR
  }
  @header_bar.add_left(event_box)
end

#create_the_top_primerObject

#

create_the_top_primer

#

195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 195

def create_the_top_primer
  # ======================================================================= #
  # === @top_primer
  # ======================================================================= #
  @top_primer = bold_label
  @top_primer.make_selectable
  @top_primer.tomato
  @top_primer.hint =
    'This is the reverse primer. A '\
    'match will be shown in green colour, whereas a '\
    'non-match will be shown in the '+
    COLOUR_FOR_NON_MATCHES.to_s+'-colour.'
end

#create_the_top_strandObject

#

create_the_top_strand

#

127
128
129
130
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 127

def create_the_top_strand
  @top_strand = gtk_bold_label("5'-#{@forward_sequence}-3'")
  @top_strand.darkblue
end

#do_calculate_the_GC_content_for_the_forward_primerObject Also known as: do_calculate_GC_content_for_the_forward_primer

#

do_calculate_the_GC_content_for_the_forward_primer

#

553
554
555
556
557
558
559
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 553

def do_calculate_the_GC_content_for_the_forward_primer
  _ = ::Bioroebe.gc_content_of_this_sequence(
    @forward_primer.text?.to_s, 1 # The second number is for how much to round.
  )
  _ = 0 if _ == 'NaN'
  @text_GC_content_for_the_forward_primer_as_percentage.set_text("#{_}%")
end

#do_calculate_the_GC_content_for_the_reverse_primerObject Also known as: do_calculate_GC_content_for_the_reverse_primer

#

do_calculate_the_GC_content_for_the_reverse_primer

#

542
543
544
545
546
547
548
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 542

def do_calculate_the_GC_content_for_the_reverse_primer
  _ = ::Bioroebe.gc_content_of_this_sequence(
    @reverse_primer.text?.to_s, 1 # The second number is for how much to round.
  )
  _ = 0 if _ == 'NaN'
  @text_GC_content_for_the_reverse_primer_as_percentage.set_text("#{_}%")
end

#do_pop_up_the_widget_containing_information_about_primer_design_in_a_PCRObject

#

do_pop_up_the_widget_containing_information_about_primer_design_in_a_PCR

#

403
404
405
406
407
408
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
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 403

def do_pop_up_the_widget_containing_information_about_primer_design_in_a_PCR
  vbox = gtk_vbox
  # ======================================================================= #
  # Style this vbox a bit:
  # ======================================================================= #
  outer_vbox = gtk_vbox
  outer_vbox.set_border_width(8)
  outer_vbox.pad8px
  outer_vbox.bblack1
  vbox.pad5px
  vbox.use_this_font = :hack_18
  vbox.add_hspacer
  _ = left_aligned_text(
    'Some advice on primer design'
  )
  _.use_this_font = :hack_20
  vbox.minimal(_, 10)
  vbox.add_hspacer
  vbox.add(
    left_aligned_text(
      ' - use a moderate G+C content'
    )
  )
  vbox.add(
    left_aligned_text(
      ' - binding region should be 17-27 bp'
    )
  )
  vbox.add(
    left_aligned_text(
      " - binding region Tm’s in the range of 50 to 65°C"
    )
  )
  vbox.add(
    left_aligned_text(
      ' - avoid repetitive poly-N regions'
    )
  )
  vbox.add(
    left_aligned_text(
      ' - avoid secondary structure (hairpins, '\
      'self dimerization or primer dimer)'
    )
  )
  vbox.add(
    left_aligned_text(
      " - primer pairs should have similar Tm's (±4°C)"
    )
  )
  vbox.add_hspacer
  outer_vbox.maximal(vbox, 2)
  pop_up_widget(
    over_this_widget: main_label?,
    custom_widget:    outer_vbox
  ).popup
end
#
#

477
478
479
480
481
482
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 477

def do_startup_related_actions
  print ' '
  @top_primer.deselect
  do_calculate_the_GC_content_for_the_reverse_primer
  do_calculate_the_GC_content_for_the_forward_primer
end

#establish_the_forward_and_reverse_sequenceObject

#

establish_the_forward_and_reverse_sequence

#

317
318
319
320
321
322
323
324
325
326
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 317

def establish_the_forward_and_reverse_sequence
  # ======================================================================= #
  # === @forward_sequence
  # ======================================================================= #
  @forward_sequence = 'ATGAGGTTTGCAGCG'
  # ======================================================================= #
  # === @reverse_sequence
  # ======================================================================= #
  @reverse_sequence = 'TACTCCAAACGTCGC'
end

#main_label?Boolean

#

main_label?

#

Returns:

  • (Boolean)

463
464
465
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 463

def main_label?
  @main_label
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)

331
332
333
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 331

def padding?
  PADDING_OF_THE_WHOLE_WIDGET
end

#remove_ends(i = "3'-TACGTACGTACGTACG-5'") ⇒ Object

#

remove_ends

#

564
565
566
567
568
569
570
571
572
573
574
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 564

def remove_ends(
    i = "3'-TACGTACGTACGTACG-5'"
  )
  i = i.dup
  i.sub!(/3'-/,'')
  i.sub!(/-5'/,'')
  i.sub!(/5'-/,'')
  i.sub!(/'3-/,'')
  i.sub!(/-'5/,'')
  return i
end

#resetObject

#

reset (reset tag)

#

94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 94

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 
  infer_the_size_automatically
  establish_the_forward_and_reverse_sequence
end

#return_widget_containing_the_forward_primer_informationObject

#

return_widget_containing_the_forward_primer_information

#

516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 516

def return_widget_containing_the_forward_primer_information
  hbox = gtk_hbox
  hbox.minimal(bold_text("Forward primer: 5'-"), 1)
  hbox.minimal(@forward_primer, 1)
  hbox.minimal(bold_text("-3'",1))
  button1 = gtk_button('')
  button1.hint = 'Remove the last nucleotide from the primer.'
  button1.bblack1
  button1.on_clicked {
    @forward_primer.try_to_remove_the_last_character
  }
  hbox.minimal(button1)
  text_showing_the_GC_content = left_aligned_text(' GC content:')
  text_showing_the_GC_content.use_this_font = smaller_font?
  text_showing_the_GC_content.make_bold
  hbox.minimal(text_showing_the_GC_content, 5)
  @text_GC_content_for_the_forward_primer_as_percentage = left_aligned_text
  @text_GC_content_for_the_forward_primer_as_percentage.use_this_font = smaller_font?
  @text_GC_content_for_the_forward_primer_as_percentage.make_bold
  hbox.minimal(@text_GC_content_for_the_forward_primer_as_percentage, 5)
  return hbox
end

#return_widget_containing_the_reverse_primer_informationObject

#

return_widget_containing_the_reverse_primer_information

This is the widget that contains the various smaller widgets necessary for the “Reverse primer:” info, close to the bottom of this widget.

#

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 490

def return_widget_containing_the_reverse_primer_information
  hbox = gtk_hbox
  hbox.minimal(bold_text("Reverse primer: 5'-"),1)
  hbox.minimal(@reverse_primer,1)
  hbox.minimal(bold_text("-3'",1))
  button2 = gtk_button('')
  button2.hint = 'Remove the last nucleotide from the primer.'
  button2.bblack1
  button2.on_clicked {
    @reverse_primer.try_to_remove_the_last_character
  }
  hbox.minimal(button2)
  text_showing_the_GC_content = left_aligned_text(' GC content:')
  text_showing_the_GC_content.use_this_font = smaller_font?
  text_showing_the_GC_content.make_bold
  hbox.minimal(text_showing_the_GC_content, 5)
  @text_GC_content_for_the_reverse_primer_as_percentage = left_aligned_text
  @text_GC_content_for_the_reverse_primer_as_percentage.use_this_font = smaller_font?
  @text_GC_content_for_the_reverse_primer_as_percentage.make_bold
  hbox.minimal(@text_GC_content_for_the_reverse_primer_as_percentage, 5)
  return hbox
end

#runObject

#

run (run tag)

#

306
307
308
309
310
311
312
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 306

def run
  create_skeleton_then_connect_skeleton
  Thread.new {
    sleep 0.001
    do_startup_related_actions
  }
end

#smaller_font?Boolean

#

smaller_font?

#

Returns:

  • (Boolean)

470
471
472
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 470

def smaller_font?
  SMALLER_FONT
end

#sync_forward_and_reverse_primerObject

#

sync_forward_and_reverse_primer

#

251
252
253
254
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 251

def sync_forward_and_reverse_primer
  sync_forward_primer
  sync_reverse_primer
end

#sync_forward_primerObject Also known as: sync_the_forward_primer

#

sync_forward_primer

#

259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 259

def sync_forward_primer
  _ = @forward_primer.text?
  longer_nucleotide_sequence = remove_ends(@bottom_strand.text?)
  array = ["      5'-", :tomato]
  _.chars.each_with_index {|char, index|
    if char == Bioroebe.should_match_to?(longer_nucleotide_sequence[index])
      # This is a match.
      array << [char, :darkgreen]
    else
      # This is NOT a match.
      array << [char, COLOUR_FOR_NON_MATCHES]
    end
    array.flatten!
  }
  array << ["-3'→".ljust(@forward_sequence.size+(9-_.size)), :tomato]
  array.flatten!
  @bottom_primer.simple_markup(array)
end

#sync_reverse_primerObject Also known as: sync_the_reverse_primer

#

sync_reverse_primer

#

281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/bioroebe/gui/gtk3/primer_design_widget/primer_design_widget.rb', line 281

def sync_reverse_primer
  _ = @reverse_primer.text?
  longer_nucleotide_sequence = remove_ends(@top_strand.text?.reverse)
  @top_primer.set_text(
    _.rjust(@forward_sequence.size+6)
  )
  array = ["←3'-".rjust(33), :tomato]
  _.chars.reverse.each_with_index {|char, index|
    if char == Bioroebe.should_match_to?(longer_nucleotide_sequence[index])
      # This is a match.
      array << [char, :darkgreen]
    else
      # This is NOT a match.
      array << [char, COLOUR_FOR_NON_MATCHES]
    end
    array.flatten!
  }
  array << ["-5'".ljust(@forward_sequence.size+6), :tomato]
  array.flatten!
  @top_primer.simple_markup(array)
end