Class: Bioroebe::GUI::Gtk::NucleotideAnalyser

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

Overview

Bioroebe::GUI::Gtk::NucleotideAnalyser

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Nucleotide Analyser'
WIDTH =
#

WIDTH

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

HEIGHT

#
580
USE_THIS_FONT =
#

USE_THIS_FONT

#
:hack_16

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

#

initialize

#

54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 54

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

Class Method Details

.run(i = ARGV) ⇒ Object

#

Bioroebe::GUI::Gtk::NucleotideAnalyser.run

#

461
462
463
464
465
466
467
468
469
470
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 461

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

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)

122
123
124
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 122

def border_size?
  2
end

#clear_tableObject

#

clear_table

#

162
163
164
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 162

def clear_table
  @list_store.clear
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 303

def connect_skeleton
  abort_on_exception
  _ = first_argument?.to_s
  minimal(@entry_input_sequence, 2)
  @entry_input_sequence.set_text(@sequence.to_s)
  minimal(@text_this_sequence_contains, 2)
  minimal(gtk_horizontal_spacer)
  @tree_view.all_are_sortable # Make them all sortable.
  scrolled_window = gtk_scrolled_window(@tree_view) { :never_always }
  scrolled_window.set_size_request(420, 260)
  minimal(scrolled_window, 5)
  minimal(gtk_horizontal_spacer)
  update_the_labels
  minimal(@label_GC_content)
  minimal(@label_AT_content)
  hbox = gtk_hbox
  hbox.maximal(@button_reset,                    1)
  hbox.maximal(@button_reset_the_input_sequence, 1)
  hbox.maximal(@button_open_file,                1)
  minimal(hbox, 2)
end

#create_buttonsObject

#

create_buttons (buttons tag, button tag)

#

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 202

def create_buttons
  # ======================================================================= #
  # === @button_reset
  # ======================================================================= #
  @button_reset = button('_Reset the table')
  @button_reset.hint = 'This button will clear the table-result '\
                       'shown above.'
  @button_reset.on_clicked {
    clear_table
  }
  # ======================================================================= #
  # === @button_reset_the_input_sequence
  # ======================================================================= #
  @button_reset_the_input_sequence = button('Reset the _input sequence')
  @button_reset_the_input_sequence.enable_markup
  @button_reset_the_input_sequence.hint = 'This button will '\
    'reset (aka clear) the input sequence. The input sequence is kept '\
    'on top of this widget, as a gtk-entry.'
  @button_reset_the_input_sequence.on_clicked {
    do_reset_the_input_sequence
  }
  # ======================================================================= #
  # === @button_open_file
  # ======================================================================= #
  @button_open_file = button('_Open file')
  @button_open_file.enable_markup
  @button_open_file.hint = 'This button can be used to open a local'\
                           'file, typically a FASTA (.fasta) file.'
  @button_open_file.on_clicked {
    do_open_a_local_file
  }
end

#create_entryObject

#

create_entry (entry tag)

#

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 371

def create_entry
  # ======================================================================= #
  # === @entry_input_sequence
  # ======================================================================= #
  @entry_input_sequence = entry
  @entry_input_sequence.default_values
  @entry_input_sequence.hint = 'The sequence will be evaluated '\
    'whenever it is changed, as-is. Hit the <b>enter</b> key '\
    'to change it, for convenience.'
  @entry_input_sequence.on_changed {
    update_the_main_sequence_variable
    update_this_sequence_contains_n_nucleotides
    update_the_table_dataset
    update_the_labels
  }
  # ======================================================================= #
  # Act on when the user hits the enter-key.
  # ======================================================================= #
  @entry_input_sequence.on_enter_key {
    sanitize_the_sequence
    do_analyse_the_sequence
    update_this_sequence_contains_n_nucleotides(
      return_how_many_nucleotides_this_sequence_contains
    )
  }
end

#create_skeletonObject

#

create_skeleton (create tag)

#

129
130
131
132
133
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 129

def create_skeleton
  create_buttons
  create_the_labels
  create_entry
end

#create_the_labelsObject

#

create_the_labels

#

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 346

def create_the_labels
  # ======================================================================= #
  # === @label_GC_content
  # ======================================================================= #
  @label_GC_content = left_aligned_label
  @label_GC_content.make_selectable
  # ======================================================================= #
  # === @label_AT_content
  # ======================================================================= #
  _ = ::Bioroebe.gc_content(@sequence, 1) # => 50.0
  @label_AT_content = left_aligned_label(
    'The <b>AT content</b> (A+T) is: <b>'+
    (100.0 - _.to_f).round(1).to_s+'%</b>'
  )
  @label_AT_content.make_selectable
  # ======================================================================= #
  # === @text_this_sequence_contains
  # ======================================================================= #
  @text_this_sequence_contains = left_aligned_label
  @text_this_sequence_contains.make_selectable
end

#dna_sequence?Boolean

#

dna_sequence?

#

Returns:

  • (Boolean)

408
409
410
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 408

def dna_sequence?
  @entry_input_sequence.text?
end

#do_analyse_the_sequenceObject Also known as: update_the_table_dataset

#

do_analyse_the_sequence

#

147
148
149
150
151
152
153
154
155
156
157
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 147

def do_analyse_the_sequence
  clear_table
  _ = return_dataset_based_on_this_sequence.each_slice(3).to_a
  # ======================================================================= #
  # The first element contains the header, which is not necessary.
  # ======================================================================= #
  _.shift 
  populate_this_list_store3(
    @list_store, _.compact
  )
end

#do_open_a_local_fileObject

#

do_open_a_local_file

#

184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 184

def do_open_a_local_file
  _ = open_local_file # Find a local file. (open tag)
  if File.exist?(_) and File.file?(_)
    # ===================================================================== #
    # Handle FASTA files a bit differently next:
    # ===================================================================== #
    if _.end_with?('.fasta') or _.end_with?('.fa')
      content_of_the_file = Bioroebe.parse_fasta(_).body?
    else
      content_of_the_file = File.read(_).to_s
    end
    set_main_entry(content_of_the_file)
  end
end

#do_reset_the_input_sequenceObject

#

do_reset_the_input_sequence

#

275
276
277
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 275

def do_reset_the_input_sequence
  @entry_input_sequence.clear
end

#do_style_all_buttons_in_a_uniform_mannerObject

#

do_style_all_buttons_in_a_uniform_manner

#

138
139
140
141
142
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 138

def do_style_all_buttons_in_a_uniform_manner
  return_all_buttons.each {|this_button|
    this_button.bblack1
  }
end

#entry_input_sequence?Boolean Also known as: main_entry?

#

entry_input_sequence?

#

Returns:

  • (Boolean)

401
402
403
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 401

def entry_input_sequence?
  @entry_input_sequence
end

#handle_CSS_rulesObject

#

handle_CSS_rules (CSS tag)

#

328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 328

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_CSS_file
  append_these_custom_CSS_rules '
#custom_treeview.view header button {
color: royalblue;
font-weight: bold;
font-size: larger;
padding: 8px;
}

'
  apply_the_CSS_rules
end

#initialize_dataset_based_on_the_main_sequence_and_create_the_associated_widgets(i = @sequence) ⇒ Object

#

initialize_dataset_based_on_the_main_sequence_and_create_the_associated_widgets

#

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 91

def initialize_dataset_based_on_the_main_sequence_and_create_the_associated_widgets(
    i = @sequence
  )
  # ======================================================================= #
  # Specify the dataset that we wish to use for the gtk_table3() call.
  # ======================================================================= #
  @dataset = return_dataset_based_on_this_sequence(i)
  @tree_view, @list_store = gtk_table3(
    @dataset
  ) {{
    cell_renderer_text1: :align_to_the_middle,
    cell_renderer_text2: :align_to_the_middle
  }}
  @tree_view.bblack2
  @tree_view.pad10px
  @tree_view.set_name('custom_treeview')
  @tree_view.first_column?.center
  @tree_view.second_column?.center
  @tree_view.the_headers_can_be_moved
end

#open_local_fileObject

#

open_local_file

#

169
170
171
172
173
174
175
176
177
178
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 169

def open_local_file
  # ======================================================================= #
  # We will actively filter for .mp3 files only.
  # ======================================================================= #
  widget = ::Gtk::SelectFile.new(self) {{
    current_folder: ::Bioroebe.log_dir?
  }}
  this_file = widget.do_pick_file.text.to_s
  return this_file
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)

115
116
117
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 115

def padding?
  2
end

#resetObject

#

reset (reset tag)

#

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 69

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(10)
  # ======================================================================= #
  # === @sequence
  # ======================================================================= #
  @sequence = 'GCTATGCATGCATGCTTTTTTTTTTTAGTCAGTCAGTCGATGCATGC'\
              'ATGCTAGTCAGTCAGTCGATGTGCATGCTAGTCAGTCAGTCGATGCA'
  # ^^^ overrule for now.
  initialize_dataset_based_on_the_main_sequence_and_create_the_associated_widgets
  handle_CSS_rules
end

#return_dataset_based_on_this_sequence(sequence = @entry_input_sequence.text?) ⇒ Object

#

return_dataset_based_on_this_sequence

#

249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 249

def return_dataset_based_on_this_sequence(
    sequence = @entry_input_sequence.text?
  )
  total = sequence.size
  dataset = [ # First three entries are the header.
    'Nucleotide','amount','Percentage',
    'A', sequence.count('A').to_s, ((sequence.count('A').to_f * 100) / total).round(1).to_s+'%',
    'T', sequence.count('T').to_s, ((sequence.count('T').to_f * 100) / total).round(1).to_s+'%',
    'C', sequence.count('C').to_s, ((sequence.count('C').to_f * 100) / total).round(1).to_s+'%',
    'G', sequence.count('G').to_s, ((sequence.count('G').to_f * 100) / total).round(1).to_s+'%'
  ]
  return dataset
end

#return_how_many_nucleotides_this_sequence_contains(i = @entry_input_sequence.text?) ⇒ Object

#

return_how_many_nucleotides_this_sequence_contains

#

266
267
268
269
270
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 266

def return_how_many_nucleotides_this_sequence_contains(
    i = @entry_input_sequence.text?
  )
  "This sequence contains <b>#{i.size.to_s}</b> nucleotides."
end

#runObject

#

run (run tag)

#

453
454
455
456
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 453

def run
  create_skeleton_then_connect_skeleton
  do_style_all_buttons_in_a_uniform_manner
end

#sanitize_the_sequenceObject

#

sanitize_the_sequence

#

282
283
284
285
286
287
288
289
290
291
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 282

def sanitize_the_sequence
  if @entry_input_sequence.text?
    if @entry_input_sequence.text?.include? '-'
      new_sequence = @entry_input_sequence.text?.delete('-')
      @sequence = new_sequence
      @entry_input_sequence.set_text(new_sequence)
      @dataset = return_dataset_based_on_this_sequence(@entry_input_sequence.text?)
    end
  end
end

#set_main_entry(i) ⇒ Object Also known as: set_dna_sequence

#

set_main_entry

#

446
447
448
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 446

def set_main_entry(i)
  @entry_input_sequence.set_text(i.to_s)
end

#update_the_AT_content_labelObject

#

update_the_AT_content_label

#

434
435
436
437
438
439
440
441
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 434

def 
  _ = ::Bioroebe.gc_content(@sequence, 1) # => 50.0
  @label_AT_content.set_text(
    "The <b>AT content</b> (A+T) is: <b>"\
    "#{(100.0 - _.to_f).round(1).to_s}%</b>"
  )
  @label_AT_content.do_markify
end

#update_the_GC_content_labelObject

#

update_the_GC_content_label

#

415
416
417
418
419
420
421
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 415

def 
  _ = ::Bioroebe.gc_content(@sequence, 1) # => 50.0
  @label_GC_content.set_text(
    'The <b>GC content</b> (G+C) is: <b>'+_.to_s+'%</b>'
  )
  @label_GC_content.do_markify
end

#update_the_labelsObject

#

update_the_labels

#

426
427
428
429
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 426

def update_the_labels
  
  
end

#update_the_main_sequence_variableObject

#

update_the_main_sequence_variable

#

296
297
298
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 296

def update_the_main_sequence_variable
  @sequence = @entry_input_sequence.text?.delete('-')
end

#update_this_sequence_contains_n_nucleotides(i = return_how_many_nucleotides_this_sequence_contains) ⇒ Object

#

update_this_sequence_contains_n_nucleotides

#

238
239
240
241
242
243
244
# File 'lib/bioroebe/gui/gtk3/nucleotide_analyser/nucleotide_analyser.rb', line 238

def update_this_sequence_contains_n_nucleotides(
    i = 
      return_how_many_nucleotides_this_sequence_contains
  )
  @text_this_sequence_contains.set_text(i.to_s)
  @text_this_sequence_contains.do_markify
end