Module: Bioroebe::GUI::ShowCodonUsageModule

Included in:
Gtk::ShowCodonUsage, LibUI::ShowCodonUsage
Defined in:
lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb

Constant Summary collapse

TITLE =
#

TITLE

#
'Show Codon Usage'
WIDTH =
#

WIDTH

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

HEIGHT

#
'50%'
TEST_SEQUENCE =
#

TEST_SEQUENCE

#
'AGACGTACGTACGTCAGTCAGTACGTACTGATCGTAGCTAGCTACGTGACC'
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_20

Instance Method Summary collapse

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)

69
70
71
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 69

def border_size?
  4
end

#create_box_top_five_codonsObject

#

create_box_top_five_codons

#

162
163
164
165
166
167
168
169
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 162

def create_box_top_five_codons
  if use_gtk3?
    @box_top_five_codons = gtk_box # This is a Gtk::Box. It will contain @label_top_five_codons.
  else
    @box_top_five_codons = padded_vbox
  end
  @box_top_five_codons.set_font(:hack_20)
end

#create_the_label_showing_n_nucleotidesObject

#

create_the_label_showing_n_nucleotides

#

188
189
190
191
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 188

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

#

174
175
176
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 174

def create_the_label_top_five_codons
  @label_top_five_codons = label
end

#create_the_main_entryObject

#

create_the_main_entry (entry tag)

#

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 196

def create_the_main_entry
  # ======================================================================= #
  # === @entry1
  # ======================================================================= #
  @entry1 = 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_text_viewObject

#

create_the_text_view

#

181
182
183
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 181

def create_the_text_view
  @text_view = text_view
end

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

#

do_the_conversion

#

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 112

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.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

#

104
105
106
107
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 104

def do_the_conversion_then_update_the_label_as_well
  do_the_conversion
  update_the_label_as_well
end

#handle_the_commandline_arguments(i = @commandline_arguments) ⇒ Object

#

handle_the_commandline_arguments

#

149
150
151
152
153
154
155
156
157
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 149

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

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)

62
63
64
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 62

def padding?
  8
end

#reset_the_shared_moduleObject

#

reset_the_shared_module

#

49
50
51
52
53
54
55
56
57
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 49

def reset_the_shared_module
  # ======================================================================= #
  # === @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

#sync_the_input_sequence_onto_the_main_entry(i = @use_this_as_the_input_sequence) ⇒ Object

#

sync_the_input_sequence_onto_the_main_entry

#

91
92
93
94
95
96
97
98
99
# File 'lib/bioroebe/gui/shared_code/show_codon_usage/show_codon_usage_module.rb', line 91

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

#

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

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