Class: Bioroebe::GUI::UniversalWidgets::ShowCodonUsage

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

Overview

Bioroebe::GUI::UniversalWidgets::ShowCodonUsage

Constant Summary collapse

TITLE =
#

TITLE

Specify which title to use for this small widget.

#
'Show Codon Usage'
WIDTH =
#

WIDTH

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

HEIGHT

#
'55% or 400px 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
TEST_SEQUENCE =
#

TEST_SEQUENCE

#
'AGACGTACGTACGTCAGTCAGTACGTACTGATCGTAGCTAGCTACGTGACC'

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

#

initialize

#


77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 77

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

#


372
373
374
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 372

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

.run(i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::ShowCodonUsage.run

#


379
380
381
382
383
384
385
386
387
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 379

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

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


125
126
127
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 125

def border_size?
  2
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag, skeleton tag)

#


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
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 329

def connect_the_skeleton
  abort_on_exception

  vbox = create_vbox

  handle_the_commandline_arguments
  vbox.minimal(@entry1)
  update_the_main_label_denoting_how_many_nucleotides_can_be_found_in_the_main_sequence
  vbox.minimal(@label_showing_n_nucleotides)
  vbox.minimal(hspacer)
  create_box_top_five_codons
  @box_top_five_codons.minimal(@label_top_five_codons, 10)
  draggable_pane = gtk_drag_top_to_bottom(
    @scrolled_window,
    @box_top_five_codons
  )
  vbox.maximal(draggable_pane)

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

  ::UniversalWidgets.set_main_window(window)
  upon_delete_event_quit_the_application
  
  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?)
  handle_the_commandline_arguments # This must come after the GUI skeleton was created.
  Thread.new {
    sleep 0.02
    do_the_conversion_then_update_the_label_as_well
    @entry1.deselect
  }
  window.top_left
  run_main
end

#create_box_top_five_codonsObject

#

create_box_top_five_codons

#


131
132
133
134
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 131

def create_box_top_five_codons
  @box_top_five_codons = create_vbox
  @box_top_five_codons.set_font(:hack_20)
end

#create_the_label_showing_n_nucleotidesObject

#

create_the_label_showing_n_nucleotides

#


146
147
148
149
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 146

def create_the_label_showing_n_nucleotides
  @label_showing_n_nucleotides = label
  @label_showing_n_nucleotides.set_font('Bitstream Vera Sans 22')
end

#create_the_label_top_five_codonsObject

#

create_the_label_top_five_codons

#


139
140
141
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 139

def create_the_label_top_five_codons
  @label_top_five_codons = label
end

#create_the_main_entryObject

#

create_the_main_entry (entry tag)

#


154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 154

def create_the_main_entry
  # ======================================================================= #
  # === @entry1
  # ======================================================================= #
  @entry1 = create_entry
  @entry1.set_text(@use_this_as_the_input_sequence)
  @entry1.set_font(:hack_20)
  @entry1.hint =
    "This entry should contain the nucleotide sequence that "\
    "the user wants to analyse. \n\nAs soon as the user has "\
    "finished the sequence, the '<b>enter</b>' key can be used "\
    "to analyse the sequence."
  @entry1.on_enter {
    do_the_conversion_then_update_the_label_as_well
  } if @entry1.respond_to? :on_enter
end

#create_the_scrolled_windowObject

#

create_the_scrolled_window (scrolled tag)

#


289
290
291
292
293
294
295
296
297
298
299
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 289

def create_the_scrolled_window
  # ======================================================================= #
  # === @scrolled_window
  # ======================================================================= #
  @scrolled_window = create_scrolled_window(@text_view) { :only_top_and_bottom_scrollbar }
  @scrolled_window.set_font(:hack_20)
  @scrolled_window.read_only
  @scrolled_window.pad8px
  @scrolled_window.set_border_width(5)
  @scrolled_window.set_size_request(550, 300)
end

#create_the_skeletonObject

#

create_the_skeleton (create tag, skeleton tag)

#


304
305
306
307
308
309
310
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 304

def create_the_skeleton
  create_the_label_showing_n_nucleotides
  create_the_main_entry
  create_the_label_top_five_codons
  create_the_text_view # Must be created before the scrolled window.
  create_the_scrolled_window
end

#create_the_text_viewObject

#

create_the_text_view

#


315
316
317
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 315

def create_the_text_view
  @text_view = create_text_view
end

#do_the_conversion(i = @entry1.text?) ⇒ Object

#

do_the_conversion

#


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
241
242
243
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 210

def do_the_conversion(
    i = @entry1.text?
  )
  # ======================================================================= #
  # First, we remove any numbers from the given input at hand:
  # ======================================================================= #
  shortened_sequence = ::Bioroebe.remove_numbers_from(i)
  unless i == shortened_sequence
    i = shortened_sequence
    @entry1.set_text(i)
  end
  hash = Bioroebe::ShowCodonUsage.new(i) { :be_quiet }.result?
  _ = ''.dup     
  hash.each_pair {|key, value|
    _ << "#{key}: #{value}\n"
  }
  text_for_the_label = "The <b>top 5 codons</b> are:\n\n".dup
  keys = hash.keys[0 .. 4] # Grab the first 5 entries.
  hash.each_pair {|key, value|
    if keys.include? key
      if use_gtk3?
        text_for_the_label << '<b>'+key.to_s+'</b>: '+value.to_s+"\n"
      else
        text_for_the_label << key.to_s+': '+value.to_s+"\n"
      end
    end
  }
  @label_top_five_codons.set_text(
    text_for_the_label
  )
  @label_top_five_codons.make_selectable
  @label_top_five_codons.do_markify # Apply any markup rules here.
  @text_view.set_text(_.strip)
end

#do_the_conversion_then_update_the_label_as_wellObject

#

do_the_conversion_then_update_the_label_as_well

#


202
203
204
205
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 202

def do_the_conversion_then_update_the_label_as_well
  do_the_conversion
  update_the_label_as_well
end

#handle_CSS_rulesObject Also known as: handle_CSS

#

handle_CSS_rules (CSS tag, css tag)

#


277
278
279
280
281
282
283
284
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 277

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  add_these_custom_CSS_rules '

  '
  apply_the_CSS_rules
end

#handle_the_commandline_arguments(i = commandline_arguments? ) ⇒ Object

#

handle_the_commandline_arguments

#


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

def handle_the_commandline_arguments(
    i = commandline_arguments?
  )
  i.each {|entry|
    if File.file? entry
      @use_this_as_the_input_sequence = File.read(entry).
                                        strip.delete("\n").delete(' ')
      sync_the_input_sequence_onto_the_main_entry
    end
  }
end

#main_font?Boolean

#

main_font?

#

Returns:

  • (Boolean)


263
264
265
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 263

def main_font?
  USE_THIS_FONT
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


118
119
120
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 118

def padding?
  8
end

#resetObject

#

reset (reset tag)

#


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 92

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?
  # ======================================================================= #
  # === @use_this_as_the_input_sequence
  #
  # Assign a dummy-sequence for startup. This can be changed via the
  # commandline-input.
  # ======================================================================= #
  @use_this_as_the_input_sequence = TEST_SEQUENCE
end

#runObject

#

run (run tag)

#


322
323
324
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 322

def run
  run_super
end

#slightly_smaller_font?Boolean

#

slightly_smaller_font?

#

Returns:

  • (Boolean)


270
271
272
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 270

def slightly_smaller_font?
  USE_THIS_SLIGHTLY_SMALLER_FONT
end

#sync_the_input_sequence_onto_the_main_entry(i = @use_this_as_the_input_sequence) ⇒ Object

#

sync_the_input_sequence_onto_the_main_entry

#


189
190
191
192
193
194
195
196
197
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 189

def sync_the_input_sequence_onto_the_main_entry(
    i = @use_this_as_the_input_sequence
  )
  if i
    @entry1.set_text(i)
    update_the_main_label_denoting_how_many_nucleotides_can_be_found_in_the_main_sequence(i)
    do_the_conversion_then_update_the_label_as_well unless i.empty?
  end
end

#update_the_main_label_denoting_how_many_nucleotides_can_be_found_in_the_main_sequence(i = @entry1.text?.size.to_s) ⇒ Object Also known as: update_the_label_as_well

#

update_the_main_label_denoting_how_many_nucleotides_can_be_found_in_the_main_sequence

#


174
175
176
177
178
179
180
181
182
183
184
# File 'lib/bioroebe/gui/universal_widgets/show_codon_usage/show_codon_usage.rb', line 174

def update_the_main_label_denoting_how_many_nucleotides_can_be_found_in_the_main_sequence(
    i = @entry1.text?.size.to_s
  )
  if use_gtk3?
    _ = "n nucleotides: <b>#{i}</b>"
  else
    _ = "n nucleotides: #{i}"
  end
  @label_showing_n_nucleotides.set_text(_)
  @label_showing_n_nucleotides.do_markify
end