Class: Bioroebe::GUI::Gtk::AminoacidComposition
- Inherits:
-
Gtk::Box
- Object
- Gtk::Box
- Bioroebe::GUI::Gtk::AminoacidComposition
- Includes:
- Gtk::BaseModule
- Defined in:
- lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb
Overview
Bioroebe::GUI::Gtk::AminoacidComposition
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- TITLE =
#
TITLE
#
'Aminoacid Composition'
- WIDTH =
#
WIDTH
#
'60%'
- HEIGHT =
#
HEIGHT
#
'40%'
- USE_THIS_FONT =
#
USE_THIS_FONT
#
:dejavu_condensed_18
- USE_THIS_SLIGHTLY_SMALLER_FONT =
#
USE_THIS_SLIGHTLY_SMALLER_FONT
#
:dejavu_condensed_16
- FILE_MOLECULAR_WEIGHT =
#
FILE_MOLECULAR_WEIGHT
#
Bioroebe.file_molecular_weight
Class Method Summary collapse
-
.run(i = ARGV) ⇒ Object
# === Bioroebe::GUI::Gtk::AminoacidComposition.run ========================================================================= #.
Instance Method Summary collapse
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#calculated_weight?(i) ⇒ Boolean
# === calculated_weight?.
-
#connect_skeleton ⇒ Object
# === connect_skeleton (connect tag) ========================================================================= #.
-
#create_skeleton ⇒ Object
# === create_skeleton (create tag) ========================================================================= #.
-
#create_the_treeview ⇒ Object
# === create_the_treeview ========================================================================= #.
-
#create_then_add_the_header_bar ⇒ Object
# === create_then_add_the_header_bar ========================================================================= #.
-
#create_user_input ⇒ Object
# === create_user_input ========================================================================= #.
-
#do_create_a_new_fasta_file ⇒ Object
# === do_create_a_new_fasta_file ========================================================================= #.
-
#do_open_a_local_FASTA_file(this_widget = @parent_widget) ⇒ Object
# === do_open_a_local_FASTA_file ========================================================================= #.
-
#fill_the_table_data_with_this_sequence(i = @entry_input_sequence.text?) ⇒ Object
(also: #fill_with_this)
# === fill_the_table_data_with_this_sequence ========================================================================= #.
-
#handle_CSS_rules ⇒ Object
# === handle_CSS_rules (CSS tag, css tag) ========================================================================= #.
-
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ AminoacidComposition
constructor
# === initialize ========================================================================= #.
-
#main_font? ⇒ Boolean
# === main_font? ========================================================================= #.
-
#menu(i = commandline_arguments? ) ⇒ Object
# === menu (menu tag) ========================================================================= #.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#path_to_the_fasta_file? ⇒ Boolean
# === path_to_the_fasta_file? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_widget_containing_the_toolbox_images ⇒ Object
# === return_widget_containing_the_toolbox_images ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#set_main_entry(i) ⇒ Object
(also: #set_main_input_sequence)
# === set_main_entry ========================================================================= #.
-
#set_main_input_sequence_and_evaluate_it(i) ⇒ Object
# === set_main_input_sequence_and_evaluate_it ========================================================================= #.
-
#set_parent_widget(i) ⇒ Object
# === set_parent_widget ========================================================================= #.
-
#simulate_enter_click(_ = @entry_input_sequence.text?) ⇒ Object
(also: #update_information_deduced_from_the_aminoacid_sequence, #do_update_the_widget_on_the_right_side)
# === simulate_enter_click ========================================================================= #.
-
#slightly_smaller_font? ⇒ Boolean
# === slightly_smaller_font? ========================================================================= #.
-
#update_label_cursor_position ⇒ Object
# === update_label_cursor_position ========================================================================= #.
Constructor Details
#initialize(commandline_arguments = ARGV, run_already = true) ⇒ AminoacidComposition
#
initialize
#
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.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
.run(i = ARGV) ⇒ Object
#
Bioroebe::GUI::Gtk::AminoacidComposition.run
#
304 305 306 307 308 309 310 311 312 313 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 304 def self.run( i = ARGV ) require 'gtk_paradise/run' _ = ::Bioroebe::GUI::Gtk::AminoacidComposition.new(i) r = ::Gtk.run r << _ r.automatic r.top_left_then_run end |
Instance Method Details
#border_size? ⇒ Boolean
#
border_size?
#
100 101 102 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 100 def border_size? 2 end |
#calculated_weight?(i) ⇒ Boolean
#
calculated_weight?
This method will calculate the weight.
#
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 269 def calculated_weight?(i) dataset = YAML.load_file(FILE_MOLECULAR_WEIGHT) weight = 0 if i.is_a?(String) and !i.empty? chars = i.chars.sort chars.each {|this_char| value = dataset[this_char] weight += value if value } end # ======================================================================= # # Must deduct water too. # ======================================================================= # weight -= (18.0 * (i.size - 1)) return weight.round(2) end |
#connect_skeleton ⇒ Object
#
connect_skeleton (connect tag)
#
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 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 432 def connect_skeleton abort_on_exception if first? and !first?.start_with?('--') @entry_input_sequence.set_text(first?.to_s) end # ======================================================================= # # === @list_store # ======================================================================= # @list_store = gtk_liststore(String, String) # ======================================================================= # # Sort the number of aminoacids a bit differently. # ======================================================================= # @list_store.set_sort_func(1) { |_model, iter1, iter2| iter2[1].to_i <=> iter1[1].to_i } create_the_treeview columns = @treeview.columns? columns[0].allow_resizing columns[1].allow_resizing columns[0].sortable_based_on(0) columns[1].sortable_based_on(1) hbox = gtk_hbox hbox.maximal(@entry_input_sequence, 6) event_box = gtk_event_box(image_file_open) event_box.hint = 'Click on this button in order to '\ 'open a local .FASTA file.' event_box.on_clicked { do_open_a_local_FASTA_file } hbox.minimal(event_box, 1) add(hbox) @entry_input_sequence.on_enter { simulate_enter_click } scrolled_window = gtk_scrolled_window(@treeview) { :always } scrolled_window.width_height(300, 600) scrolled_window.bblack1 scrolled_window.css_class('pad2px') @label_n_aminoacids = left_aligned_text small_vbox = gtk_vbox small_vbox.pad4px small_vbox.border_width = 5 small_vbox.minimal(@label_n_aminoacids, 4) @label_molecular_weight = left_aligned_text small_vbox.minimal(@label_molecular_weight, 3) @label_cursor_position = left_aligned_text small_vbox.minimal(@label_cursor_position, 3) small_vbox.minimal(, 5) _ = draggable_from_left_to_right(scrolled_window, small_vbox) _.position = 350 minimal(_, 1) end |
#create_skeleton ⇒ Object
#
create_skeleton (create tag)
#
107 108 109 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 107 def create_skeleton create_user_input end |
#create_the_treeview ⇒ Object
#
create_the_treeview
#
489 490 491 492 493 494 495 496 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 489 def create_the_treeview @treeview = gtk_tree_view(@list_store) { :clickable_headers } @treeview.set_name('custom_treeview') @treeview.headers('Aminoacid','n times') @treeview.clickable_headers @treeview.set_enable_search(true) @treeview.set_reorderable(true) end |
#create_then_add_the_header_bar ⇒ Object
#
create_then_add_the_header_bar
#
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 226 def require 'bioroebe/gui/gtk3/aminoacid_composition/customized_dialog.rb' header = label_description = text(TITLE) label_description.make_bold header.set_custom_title(label_description) header.spacing = 10 header.bblack1 = ('edit-paste-symbolic.symbolic') .hint = 'Click this button to show more information '\ 'about this application.' content = <<-EOF This widget will operate via the following <b>aminoacid weights</b>, in Dalton, without the weight of a H₂O water molecule (18g/mol): EOF content = content.dup YAML.load_file(Bioroebe.file_molecular_weight).each_pair {|key, value| content << " <b>#{key}</b>: "\ "<span color=\"steelblue\">#{value.to_s.rjust(6)}</span>\n" } content << " Compare with this URL:\n <a href=\"https://www.selleckchem.com/peptide-calculator.html\" title=\"Another useful resource\">https://www.selleckchem.com/peptide-calculator.html</a> " = gtk_left_aligned_text(content) .use_this_font = :hack_18 .on_clicked { ::Bioroebe::GUI::Gtk::CustomizedDialog.new( ) } header.pack_start() minimal(header, 2) end |
#create_user_input ⇒ Object
#
create_user_input
#
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 114 def create_user_input # ======================================================================= # # === @entry_input_sequence # ======================================================================= # @entry_input_sequence = gtk_entry @entry_input_sequence.hint = "Input your aminoacid sequence here, then hit the enter-key to "\ "evaluate the given input. Invalid entries (aka <b>non-aminoacids</b>) "\ "will be filtered away, so do not be surprised if the sequence may "\ "be modified (== <b>sanitized</b>).\n\n"\ "The cursor-position will indicate at which aminoacid "\ "position we are at.\n" @entry_input_sequence.yellow_background @entry_input_sequence.css_class('pad4px') @entry_input_sequence.signal_connect(:event) {|, event| if (event) update_information_deduced_from_the_aminoacid_sequence end } end |
#do_create_a_new_fasta_file ⇒ Object
#
do_create_a_new_fasta_file
#
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 377 def do_create_a_new_fasta_file what = @entry_input_sequence.text?.dup what.prepend( "> Random aminoacid sequence generated via a ruby-gtk3 "\ "GUI (#{what.size} aminoacids)\n" ) into = path_to_the_fasta_file? ::Bioroebe.write_what_into(what, into) vbox1 = gtk_vbox use_this_as_the_label = text( "Created a new file at:\n" ) vbox1.minimal(use_this_as_the_label, 5) vbox1.width_height(600, 400) entry1 = gtk_bold_entry(into) entry1.deselect entry1.width_height(300, 30) entry1.light_yellowish_background vbox1.minimal(entry1, 5) use_this_as_the_label.deselect ( @event_box1, vbox1 ).popup end |
#do_open_a_local_FASTA_file(this_widget = @parent_widget) ⇒ Object
#
do_open_a_local_FASTA_file
#
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 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 346 def do_open_a_local_FASTA_file( = @parent_widget ) require 'gtk_paradise/widgets/gtk3/select_file/select_file.rb' # ======================================================================= # # We will actively filter for .mp3 files only. # ======================================================================= # = ::Gtk::SelectFile.new() {{ filter_for_these_file_types: '.fasta', current_folder: ::Bioroebe.log_dir?+'fasta/' }} this_file = .do_pick_file.text.to_s if File.exist?(this_file) and File.file?(this_file) # Ensure that it really is a file. require 'bioroebe/fasta_and_fastq/parse_fasta/parse_fasta.rb' dataset = File.read(this_file) _ = Bioroebe::ParseFasta.new unless dataset.start_with?('--') _.set_data(dataset) # This will use the default file. _.split_into_proper_sections set_main_entry(_.body?) fill_with_this(_.body?) end end return this_file end |
#fill_the_table_data_with_this_sequence(i = @entry_input_sequence.text?) ⇒ Object Also known as: fill_with_this
#
fill_the_table_data_with_this_sequence
#
145 146 147 148 149 150 151 152 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 145 def fill_the_table_data_with_this_sequence( i = @entry_input_sequence.text? ) @list_store.clear hash = Bioroebe.return_composition_from_this_aminoacid_sequence(i) array = hash.to_a.map {|inner_array| inner_array.map {|entry| entry.to_s }} ::Gtk.populate_this_liststore(@list_store, array) end |
#handle_CSS_rules ⇒ Object
#
handle_CSS_rules (CSS tag, css tag)
#
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 208 def handle_CSS_rules use_gtk_paradise_project_css_file append_project_css_file add_these_custom_CSS_rules ' #custom_treeview.view header button { background-color: white; color: royalblue; font-weight: bold; font-size: larger; padding: 8px; }' apply_the_CSS end |
#main_font? ⇒ Boolean
#
main_font?
#
180 181 182 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 180 def main_font? USE_THIS_FONT end |
#menu(i = commandline_arguments? ) ⇒ Object
#
menu (menu tag)
#
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 157 def ( i = commandline_arguments? ) if i.is_a? Array i.each {|entry| (entry) } else case i # ===================================================================== # # === gtk_aminoacid_composition --ubi # ===================================================================== # when /^-?-?ubiquitin$/i, /^-?-?ubi$/i set_main_entry( Bioroebe.return_ubiquitin_sequence ) simulate_enter_click end end end |
#padding? ⇒ Boolean
#
padding?
#
93 94 95 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 93 def padding? 6 end |
#path_to_the_fasta_file? ⇒ Boolean
#
path_to_the_fasta_file?
#
318 319 320 321 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 318 def path_to_the_fasta_file? ::Bioroebe.log_dir?+ 'fasta/aminoacid_sequence.fasta' end |
#reset ⇒ Object
#
reset (reset tag)
#
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 79 def reset reset_the_internal_variables # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT) handle_CSS_rules infer_the_size_automatically end |
#return_widget_containing_the_toolbox_images ⇒ Object
#
return_widget_containing_the_toolbox_images
#
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 326 def hbox = gtk_hbox @event_box1 = gtk_event_box( image_folder_visiting_symbolic ) @event_box1.hint = 'Click on this image to create a new local '\ '.fasta file with that sequence. The location will be '\ 'at: <b>'+ path_to_the_fasta_file?+ '</b>' @event_box1.on_clicked { do_create_a_new_fasta_file } hbox.minimal(@event_box1, 4) return hbox end |
#run ⇒ Object
#
run (run tag)
#
501 502 503 504 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 501 def run super() end |
#set_main_entry(i) ⇒ Object Also known as: set_main_input_sequence
#
set_main_entry
#
194 195 196 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 194 def set_main_entry(i) @entry_input_sequence.set_text(i.to_s) end |
#set_main_input_sequence_and_evaluate_it(i) ⇒ Object
#
set_main_input_sequence_and_evaluate_it
#
201 202 203 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 201 def set_main_input_sequence_and_evaluate_it(i) simulate_enter_click(i) end |
#set_parent_widget(i) ⇒ Object
#
set_parent_widget
#
138 139 140 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 138 def (i) @parent_widget = i end |
#simulate_enter_click(_ = @entry_input_sequence.text?) ⇒ Object Also known as: update_information_deduced_from_the_aminoacid_sequence, do_update_the_widget_on_the_right_side
#
simulate_enter_click
#
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 406 def simulate_enter_click( _ = @entry_input_sequence.text? ) _.upcase! # ======================================================================= # # First weed out all invalid aminoacids: # ======================================================================= # _ = ::Bioroebe.filter_away_invalid_aminoacids(_) @entry_input_sequence.set_text(_) fill_the_table_data_with_this_sequence(_) @label_n_aminoacids.set_text( "This sequence has <b>#{_.size}</b> aminoacids." ) @label_n_aminoacids.do_markify @label_molecular_weight.set_text( 'The molecular weight of these aminoacids is: <b>'+ calculated_weight?(_).to_s+'</b> Dalton' ) @label_molecular_weight.do_markify update_label_cursor_position end |
#slightly_smaller_font? ⇒ Boolean
#
slightly_smaller_font?
#
187 188 189 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 187 def slightly_smaller_font? USE_THIS_SLIGHTLY_SMALLER_FONT end |
#update_label_cursor_position ⇒ Object
#
update_label_cursor_position
#
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/bioroebe/gui/gtk3/aminoacid_composition/aminoacid_composition.rb', line 289 def update_label_cursor_position cursor_position = @entry_input_sequence.cursor_position character = @entry_input_sequence.text?[cursor_position, 1].to_s unless character.empty? _ = 'The aminoacid at position <b>'+ (cursor_position+1).to_s+ '</b> is: <b>'+character.to_s+'</b>.' @label_cursor_position.set_text(_) @label_cursor_position.do_markify end end |