Class: Bioroebe::GUI::Gtk::RandomSequence
- Inherits:
-
Gtk::Box
- Object
- Gtk::Box
- Bioroebe::GUI::Gtk::RandomSequence
show all
- Includes:
- Bioroebe::GUI, Bioroebe::GUI::Gtk, Gtk::BaseModule
- Defined in:
- lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb
Overview
Bioroebe::GUI::Gtk::RandomSequence
Constant Summary
collapse
- NAMESPACE =
inspect
- TITLE =
'Random Sequence - for DNA, RNA and aminoacids'
- WIDTH =
'45% or minimum 1200px'
- HEIGHT =
'45% or minimum 980px'
['one-letter abbreviation', 'n times']
- GENERATE_N_AMINOACIDS_BY_DEFAULT =
#
GENERATE_N_AMINOACIDS_BY_DEFAULT
#
15
- USE_THIS_FONT =
:dejavu_condensed_22
ARRAY_ALL_GTK_WIDGETS, FONT_SIZE, OLD_VERBOSE_VALUE, USE_THIS_FONT_FAMILY_FOR_GUI_APPLICATIONS
Class Method Summary
collapse
Instance Method Summary
collapse
#disable_warnings, #enable_warnings, #log_dir?
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ RandomSequence
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 71
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
.start_gui_application(i = ARGV) ⇒ Object
#
Bioroebe::GUI::Gtk::RandomSequence.start_gui_application
#
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 554
def self.start_gui_application(
i = ARGV
)
require 'gtk_paradise/run'
_ = ::Bioroebe::GUI::Gtk::RandomSequence.new(i)
r = ::Gtk.run
r << _
r.automatic_size_then_automatic_title
r.background_colour :white
r.easy_exit
r.top_left_then_run
end
|
Instance Method Details
#aminoacid_sequence? ⇒ Boolean
Also known as:
sequence?, main_sequence?
119
120
121
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 119
def aminoacid_sequence?
@entry_containing_the_sequence.text?.to_s
end
|
#border_size? ⇒ Boolean
112
113
114
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 112
def border_size?
4
end
|
#connect_skeleton ⇒ Object
#
connect_skeleton (connect tag)
#
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 338
def connect_skeleton
abort_on_exception
minimal(@top_bar, 3)
minimal(@entry_containing_the_sequence, 3)
minimal(@button_for_generating_a_new_random_sequence, 3)
minimal(@entry_for_n_entries_in_the_sequence, 3)
hbox_for_the_button_copy_to_clipboard = gtk_hbox
hbox_for_the_button_copy_to_clipboard.minimal(@button_copy_to_clipboard)
hbox_for_the_button_copy_to_clipboard.align_into_the_center
minimal(hbox_for_the_button_copy_to_clipboard, 3)
minimal(@statistical_widget_top_panel, 0)
maximal(@statistical_widget, 3)
show_all
end
|
#create_skeleton ⇒ Object
#
create_skeleton (create tag)
#
474
475
476
477
478
479
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 474
def create_skeleton
create_the_buttons create_statistical_information create_the_top_bar
create_the_entries
end
|
#
This method will fill up the “table”.
#
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
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 407
def create_statistical_information
create_statistical_top_panel
@statistical_widget = gtk_vbox
array1 = ::Bioroebe.return_array_of_common_aminoacids
array2 = Array.new(array1.size, '0')
array = array1.zip(array2) array.prepend(USE_THIS_HEADER)
@tree_view, @list_store = tree_widget_with_two_columns_per_row(array)
do_properly_setup_the_tree_view
scrolled_window = gtk_scrolled_window(@tree_view)
scrolled_window.set_border_width(10)
scrolled_window.bblack1
@statistical_widget.maximal(scrolled_window, 5)
hbox1 = gtk_hbox
hbox1.minimal(@clear_button)
hbox1.align_into_the_center
@statistical_widget.minimal(hbox1, 2)
enable_proper_sorting_for_the_list_store
on_right_click_in_the_tree_view_deselect_the_selection
end
|
#create_statistical_top_panel ⇒ Object
#
create_statistical_top_panel
#
206
207
208
209
210
211
212
213
214
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 206
def create_statistical_top_panel
@statistical_widget_top_panel = bold_label(
'Showing statistical information about the '\
'assigned aminoacid sequence next'
)
end
|
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 172
def create_the_buttons
@clear_button = bold_button('_Clear the table above')
@clear_button.hint = 'Clear the above dataset / table'
@clear_button.on_clicked {
do_clear_the_list_store
}
@clear_button.set_name('button1')
@button_for_generating_a_new_random_sequence = bold_button(
'_Generate a random aminoacid sequence'
) {{ tooltip: 'Clicking on this button will <b>generate a random '\
'aminoacid sequence</b>. Do not set a too high value '\
'as that may take a long time, and consume a '\
'lot of memory/RAM.'
}}
@button_for_generating_a_new_random_sequence.on_click_event {
do_generate_a_random_sequence(n_aminoacids?)
}
@button_for_generating_a_new_random_sequence.set_name('button1')
create_the_copy_to_clipboard_button
end
|
458
459
460
461
462
463
464
465
466
467
468
469
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 458
def create_the_copy_to_clipboard_button
@button_copy_to_clipboard = bold_button('_Copy to the xorg-clipboard')
@button_copy_to_clipboard.hint = 'This will <b>copy the aminoacid '\
'sequence</b> to the <b>xorg-clipboard</b>.'
@button_copy_to_clipboard.on_clicked {
do_copy_to_the_clipboard
}
@button_copy_to_clipboard.set_name('button1')
end
|
#create_the_entries ⇒ Object
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 377
def create_the_entries
@entry_containing_the_sequence = gtk_entry
@entry_containing_the_sequence.on_click_select_everything
@entry_containing_the_sequence.yellow_background
@entry_containing_the_sequence.bblack1
@entry_for_n_entries_in_the_sequence = gtk_entry { :align_center }
@entry_for_n_entries_in_the_sequence.set_text(GENERATE_N_AMINOACIDS_BY_DEFAULT.to_s)
@entry_for_n_entries_in_the_sequence.yellow_background
@entry_for_n_entries_in_the_sequence.on_click_select_everything
@entry_for_n_entries_in_the_sequence.bblack1
@entry_for_n_entries_in_the_sequence.on_enter {
do_generate_a_random_sequence_using_the_value_from_the_proper_entry
}
@entry_for_n_entries_in_the_sequence.hint = 'Input here how many random '\
'amino acids should be generated.'
end
|
#create_the_top_bar ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 240
def create_the_top_bar
@top_bar = gtk_top_bar
button_open_file = gtk_button('_Open File')
button_open_file.hint = 'Click on this button to open a local FASTA '\
'file.'
button_open_file.on_clicked {
do_open_a_file_and_then_set_the_correct_values
}
button_open_file.bblack1
@top_bar.add(button_open_file)
@combo_box_for_the_sequence_type = gtk_combo_box_entry(
%w( aminoacid DNA RNA )
)
@combo_box_for_the_sequence_type.first_is_active
@combo_box_for_the_sequence_type.on_changed {
_ = @combo_box_for_the_sequence_type.text?
@button_for_generating_a_new_random_sequence.set_text(
"Generate a random #{_} sequence"
)
@button_for_generating_a_new_random_sequence.make_bold
@statistical_widget_top_panel.set_text(
"Showing statistical information about the "\
"assigned #{_} sequence next"
)
@statistical_widget_top_panel.make_bold
@tree_view.model = nil
@list_store = nil
@list_store = gtk_list_store(String, String)
case mode?
when 'DNA','RNA'
if mode? == 'DNA'
array1 = %w( A T C G )
else
array1 = %w( A U C G )
end
array2 = Array.new(array1.size, '0')
zipped = array1.zip(array2) zipped.each {|a, b|
iter = @list_store.append
iter.set_value(0, a)
iter.set_value(1, b)
}
else end
@tree_view.model = @list_store
}
@top_bar.add(@combo_box_for_the_sequence_type)
end
|
#do_clear_the_list_store ⇒ Object
#
do_clear_the_list_store
#
219
220
221
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 219
def do_clear_the_list_store
@list_store.clear
end
|
#do_copy_to_the_clipboard ⇒ Object
#
do_copy_to_the_clipboard
#
356
357
358
359
360
361
362
363
364
365
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 356
def do_copy_to_the_clipboard
begin
require 'xorg_buffer'
rescue LoadError; end
if Object.const_defined? :XorgBuffer
XorgBuffer.copy_this_text_to_the_clipboard(aminoacid_sequence?)
else
e 'The gem xorg_buffer is not installed, or could not be found.'
end
end
|
#do_evaluate_the_sequence(use_this_sequence = main_sequence?
) ⇒ Object
#
do_evaluate_the_sequence
#
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 298
def do_evaluate_the_sequence(
use_this_sequence = main_sequence?
)
do_clear_the_list_store
case mode?
when 'DNA','RNA'
@tree_view.remove_the_columns
column1 = ::Gtk::TreeViewColumn.new('DNA-Nucleotide', gtk_cell_renderer_text, { text: 0 })
column2 = ::Gtk::TreeViewColumn.new('n times', gtk_cell_renderer_text, { text: 1 })
@tree_view.append_column(column1)
@tree_view.append_column(column2)
@tree_view.is_sortable
if mode? == 'DNA'
array1 = %w( A T C G )
else
array1 = %w( A U C G )
end
array2 = Array.new(array1.size, '0')
array2 = Bioroebe.return_DNA_composition_hash(use_this_sequence).values.map(&:to_s)
array = array1.zip(array2)
when 'aminoacids'
array1 = ::Bioroebe.return_array_of_common_aminoacids
array2 = Bioroebe::CountAmountOfAminoacids.return_composition_hash(use_this_sequence).values.map(&:to_s)
array = array1.zip(array2) end
::Gtk.populate_this_liststore(@list_store, array)
end
|
#do_generate_a_random_sequence(n_aminoacids = :default) ⇒ Object
#
do_generate_a_random_sequence
This is the method that will be run whenever a new random aminoacid sequence is to be generated.
#
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
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
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 496
def do_generate_a_random_sequence(
n_aminoacids = :default
)
case n_aminoacids
when nil, :default
n_aminoacids = GENERATE_N_AMINOACIDS_BY_DEFAULT
end
n_aminoacids = n_aminoacids.to_s
case mode?
when /RNA/i,
/DNA/i
use_this_as_the_new_sequence = :: Bioroebe.generate_random_dna_sequence(n_aminoacids).to_s
array1 = Bioroebe::DNA_NUCLEOTIDES
if mode?.to_s == 'RNA'
use_this_as_the_new_sequence = ::Bioroebe.generate_random_rna_sequence(n_aminoacids).to_s
array1 = Bioroebe::RNA_NUCLEOTIDES
end
hash = {}
array1.each {|this_key|
hash[this_key] = 0
}
use_this_as_the_new_sequence.chars.each {|this_nucleotide|
hash[this_nucleotide.to_s] += 1
}
array2 = hash.values.map {|entry| entry.to_s }
else use_this_as_the_new_sequence = ::Bioroebe.create_random_aminoacids(n_aminoacids).to_s
array1 = ::Bioroebe.return_array_of_common_aminoacids
array2 = Bioroebe::CountAmountOfAminoacids.return_composition_hash(use_this_as_the_new_sequence).values.map(&:to_s)
end
@entry_containing_the_sequence.set_content(use_this_as_the_new_sequence)
array = array1.zip(array2) array = array.sort_by {|a, b| b }.reverse ::Gtk.populate_this_liststore(@list_store, array)
end
|
#do_generate_a_random_sequence_using_the_value_from_the_proper_entry(i = n_aminoacids?
) ⇒ Object
#
do_generate_a_random_sequence_using_the_value_from_the_proper_entry
This variant will be guaranteed to use the value determined by the gtk entry.
#
449
450
451
452
453
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 449
def do_generate_a_random_sequence_using_the_value_from_the_proper_entry(
i = n_aminoacids?
)
do_generate_a_random_sequence(i)
end
|
#do_open_a_file_and_then_set_the_correct_values ⇒ Object
#
do_open_a_file_and_then_set_the_correct_values
#
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 127
def do_open_a_file_and_then_set_the_correct_values
filename = ::Gtk.select_file(self) {{ show_hidden: true,
add_these_shortcut_folders: ::Bioroebe.log_dir?,
current_folder: ::Bioroebe.log_dir?
}}
if File.exist? filename
_ = filename
if _.end_with? '.fasta'
require 'bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb'
sequence = Bioroebe.parse_fasta_file(_).sequence?
set_main_input(sequence)
do_evaluate_the_sequence
else
set_main_input(File.read(_).strip)
end
end
end
|
#do_properly_setup_the_tree_view ⇒ Object
#
do_properly_setup_the_tree_view
#
438
439
440
441
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 438
def do_properly_setup_the_tree_view
@tree_view.linear_sorting
@tree_view.
end
|
#enable_proper_sorting_for_the_list_store ⇒ Object
#
enable_proper_sorting_for_the_list_store
#
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 149
def enable_proper_sorting_for_the_list_store
@list_store.set_sort_func(1) { |_model, iter1, iter2|
iter2[1].to_i <=> iter1[1].to_i
}
end
|
#handle_CSS ⇒ Object
484
485
486
487
488
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 484
def handle_CSS
use_gtk_paradise_project_css_file
use_project_css_file
apply_the_CSS
end
|
#mode? ⇒ Boolean
233
234
235
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 233
def mode?
@combo_box_for_the_sequence_type.text?
end
|
#n_aminoacids? ⇒ Boolean
370
371
372
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 370
def n_aminoacids?
@entry_for_n_entries_in_the_sequence.text?.to_s
end
|
#on_right_click_in_the_tree_view_deselect_the_selection ⇒ Object
#
on_right_click_in_the_tree_view_deselect_the_selection
#
163
164
165
166
167
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 163
def on_right_click_in_the_tree_view_deselect_the_selection
@tree_view.on_right_mouse_button_clicked {|widget, event|
@tree_view.deselect_everything
}
end
|
#padding? ⇒ Boolean
105
106
107
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 105
def padding?
8
end
|
#reset ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 87
def reset
reset_the_internal_variables
@configuration = [true, __dir__, NAMESPACE]
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
@list_store = nil
handle_CSS
infer_the_size_automatically
end
|
#run ⇒ Object
547
548
549
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 547
def run
super()
end
|
#set_main_input(i) ⇒ Object
226
227
228
|
# File 'lib/bioroebe/gui/gtk3/random_sequence/random_sequence.rb', line 226
def set_main_input(i)
@entry_containing_the_sequence.set_text(i.to_s)
end
|