Module: Bioroebe::GUI::LevenstheinDistanceModule

Included in:
Gtk::LevenstheinDistance, Bioroebe::GUI::LibUI::LevenstheinDistance
Defined in:
lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb

Constant Summary collapse

TITLE =
#

TITLE

#
'Levensthein Distance'
WIDTH =
#

WIDTH

#
900
HEIGHT =
#

HEIGHT

#
440
USE_THIS_FONT =
#

USE_THIS_FONT

#
:dejavu_condensed_21
USE_THIS_MONOFONT =
#

USE_THIS_MONOFONT

#
:hack_16
USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET =
#

USE_THIS_AS_BACKGROUND_COLOUR_FOR_THE_WIDGET

This constant can be used to designate the background colour to be used for the widget.

#
:white
INPUT_HINT =
#

INPUT_HINT

#
"Hit the enter-key to compare the two sequences. Don't forget to "\
"assign two sequences first, e. g. ATG and then ATT, as an example."
TEXT_COMPARE_THE_TWO_SEQUENCES =
#

Bioroebe::GUI::LevenstheinDistanceModule::TEXT_COMPARE_THE_TWO_SEQUENCES

#
'_Compare the two sequences'

Instance Method Summary collapse

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)

89
90
91
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 89

def border_size?
  2
end

#check_for_commandline_argumentsObject Also known as: parse_the_commandline_arguments

#

check_for_commandline_arguments

#

174
175
176
177
178
179
180
181
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 174

def check_for_commandline_arguments
  if @commandline_arguments and @commandline_arguments.is_a?(Array)
    unless @commandline_arguments.empty?
      set_entry1(@commandline_arguments[0])
      set_entry2(@commandline_arguments[1])
    end
  end
end

#create_the_buttonsObject

#

create_the_buttons

#

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 136

def create_the_buttons
  # ======================================================================= #
  # === @button_compare_the_two_strings
  # ======================================================================= #
  @button_compare_the_two_strings = bold_button(
    TEXT_COMPARE_THE_TWO_SEQUENCES
  )
  @button_compare_the_two_strings.clear_background
  @button_compare_the_two_strings.set_size_request(200, 40)
  @button_compare_the_two_strings.set_border_width(4)
  @button_compare_the_two_strings.bblack2
  @button_compare_the_two_strings.hint =
    'Click to compare the two sequences. Ideally use the '\
    '<b>same length</b> for the two sequences. Make sure to '\
    'click it once more after you are done, as the auto-calculation '\
    'currently does NOT take the second entry into '\
    'consideration.'
  @button_compare_the_two_strings.on_hover(:lightcyan) 
  @button_compare_the_two_strings.on_clicked {
    do_compare_the_two_strings
  }
end

#create_the_entriesObject

#

create_the_entries (entries tag, entry tag)

#

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 186

def create_the_entries
  # ======================================================================= #
  # Next, add the two input-fields for our two nucleotide sequences.
  # ======================================================================= #
  # ======================================================================= #
  # === @input_for_string1
  # ======================================================================= #
  @input_for_string1 = input
  @input_for_string1.light_green_background
  @input_for_string1.bblack1
  @input_for_string1.css_class('pad4px')
  @input_for_string1.on_enter { do_compare_the_two_strings }
  @input_for_string1.use_this_font = USE_THIS_MONOFONT
  @input_for_string1.hint = INPUT_HINT
  # ======================================================================= #
  # === @input_for_string2
  # ======================================================================= #
  @input_for_string2 = input
  @input_for_string2.light_green_background
  @input_for_string2.bblack1
  @input_for_string2.css_class('pad4px')
  @input_for_string2.on_enter { do_compare_the_two_strings }
  @input_for_string2.use_this_font = USE_THIS_MONOFONT
  @input_for_string2.hint = INPUT_HINT
end

#create_the_first_rowObject

#

create_the_first_row

#

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 237

def create_the_first_row
  # ======================================================================= #
  # === @text1
  # ======================================================================= #
  @text1 = bold_text_left_aligned('Score for match (match cost): ')
  # ======================================================================= #
  # === @input_field_for_matches
  # ======================================================================= #
  @input_field_for_matches = spinbutton(-50, 150)
  @input_field_for_matches.bblack1
  @input_field_for_matches.center
  @input_field_for_matches.yellow_background
  @input_field_for_matches.set_size_request(100, 40)
  @input_field_for_matches.set_value(
    levensthein_object?.score_for_match?.to_s.to_i
  )
  @input_field_for_matches.align_to_center
  @input_field_for_matches.on_changed {
    recalculate_the_score
  }
end

#create_the_labelsObject

#

create_the_labels

#

283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 283

def create_the_labels
  # ======================================================================= #
  # === @label_for_the_total_score
  # ======================================================================= #
  @label_for_the_total_score = text('0')
  @label_for_the_total_score.use_this_font = USE_THIS_MONOFONT
  @label_for_the_total_score.make_bold
  @label_for_the_total_score.make_selectable
  # ======================================================================= #
  # === @label_for_the_edit_distance
  # ======================================================================= #
  @label_for_the_edit_distance = return_the_label_for_the_edit_distance
end

#create_the_second_rowObject

#

create_the_second_row

#

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 339

def create_the_second_row
  # ======================================================================= #
  # === Score for mismatch
  # ======================================================================= #
  @text2 = bold_text_left_aligned('Score for mismatch (mismatch cost): ')
  # ======================================================================= #
  # === @input_field_for_mismatches
  # ======================================================================= #
  @input_field_for_mismatches = spinbutton(-50, 150)
  @input_field_for_mismatches.center
  @input_field_for_mismatches.yellow_background
  @input_field_for_mismatches.bblack1
  @input_field_for_mismatches.set_size_request(100, 40)
  @input_field_for_mismatches.set_value(
    levensthein_object?.score_for_mismatch?.to_s.to_i
  )
  @input_field_for_mismatches.align_to_center
  @input_field_for_mismatches.on_changed {
    recalculate_the_score
  }
end

#create_the_third_rowObject

#

create_the_third_row

#

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 215

def create_the_third_row
  # ======================================================================= #
  # === @text3
  # ======================================================================= #
  @text3 = bold_text_left_aligned(
    'Score for gap (gap cost): '
  )
  @input_field_for_gap_cost = spinbutton(-50, 150)
  @input_field_for_gap_cost.yellow_background
  @input_field_for_gap_cost.bblack1
  @input_field_for_gap_cost.set_value(
    levensthein_object?.score_for_gaps?.to_s.to_i
  )
  @input_field_for_gap_cost.align_to_center
  @input_field_for_gap_cost.on_changed {
    recalculate_the_score
  }
end

#do_compare_the_two_strings(text1 = entry1?.text?, text2 = entry2?.text?) ⇒ Object Also known as: do_compare_the_two_sequences, recalculate_the_score

#

do_compare_the_two_strings (click tag)

This is the main action of the widget.

#

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 366

def do_compare_the_two_strings(
    text1 = entry1?.text?,
    text2 = entry2?.text?
  )
  # ======================================================================= #
  # First capitalize the two entries:
  # ======================================================================= #
  entry1?.set_text(text1.upcase)
  entry2?.set_text(text2.upcase)
  @levensthein_object.reset_the_score
  @levensthein_object.set_match_score(@input_field_for_matches.text?)
  @levensthein_object.set_mismatch_score(@input_field_for_mismatches.text?)
  @levensthein_object.set_gap_score(input_field_for_gap_cost?.text?)
  @levensthein_object.set_string1(text1)
  @levensthein_object.set_string2(text2)
  @levensthein_object.run
  set_edit_distance(
    @levensthein_object.edit_distance?
  )
  total_score = @levensthein_object.total_score?.to_s
  @label_for_the_total_score.set_text(total_score)
  @label_for_the_total_score.make_bold
end

#entry1?Boolean

#

entry1?

#

Returns:

  • (Boolean)

307
308
309
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 307

def entry1?
  @input_for_string1
end

#entry2?Boolean

#

entry2?

#

Returns:

  • (Boolean)

314
315
316
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 314

def entry2?
  @input_for_string2
end

#input_field_for_gap_cost?Boolean

#

input_field_for_gap_cost?

#

Returns:

  • (Boolean)

110
111
112
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 110

def input_field_for_gap_cost?
  @input_field_for_gap_cost
end

#instantiate_a_new_levensthein_objectObject

#

instantiate_a_new_levensthein_object

#

70
71
72
73
74
75
76
77
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 70

def instantiate_a_new_levensthein_object
  # ======================================================================= #
  # === @levensthein_object
  # ======================================================================= #
  @levensthein_object = ::Bioroebe::Levensthein.new(:dont_run_yet) {
    :be_quiet
  }
end

#let_the_fist_entry_respond_to_on_changed_events(widget_to_use = @input_for_string1) ⇒ Object

#

let_the_fist_entry_respond_to_on_changed_events

#

321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 321

def let_the_fist_entry_respond_to_on_changed_events(
    widget_to_use = @input_for_string1
  )
  if use_gtk?
    widget_to_use.on_changed {
      do_compare_the_two_sequences
    }
  else # else assume libui
    # widget_to_use.on_changed {
    #   do_compare_the_two_sequences
    # }
    # Does not work right now.
  end
end

#levensthein_object?Boolean Also known as: levensthein

#

levensthein_object?

#

Returns:

  • (Boolean)

96
97
98
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 96

def levensthein_object?
  @levensthein_object
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)

82
83
84
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 82

def padding?
  12
end

#return_hbox4(label_for_the_total_score = @label_for_the_total_score) ⇒ Object

#

return_hbox4

#

262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 262

def return_hbox4(
    label_for_the_total_score = @label_for_the_total_score
  )
  # ======================================================================= #
  # === Total score: label
  # ======================================================================= #
  small_label_for_total_score = bold_label('Total score:     ')
  small_label_for_total_score.make_selectable
  # ======================================================================= #
  # === @hbox4
  # ======================================================================= #
  hbox4 = hbox(
    small_label_for_total_score,
    label_for_the_total_score
  )
  return hbox4 
end

#return_hbox_containing_the_edit_distance(small_label, label_for_the_edit_distance) ⇒ Object

#

return_hbox_containing_the_edit_distance

#

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

def return_hbox_containing_the_edit_distance(
    small_label,
    label_for_the_edit_distance
  )
  return hbox(
    small_label, label_for_the_edit_distance
  )
end

#return_the_edit_distance_labelObject

#

return_the_edit_distance_label

#

394
395
396
397
398
399
400
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 394

def return_the_edit_distance_label
  small_label = bold_label('Edit distance: ')
  small_label.make_selectable
  small_label.hint = 'This number tells us how many differences '\
                     'exist between the two sequences at hand.'
  return small_label
end

#return_the_label_for_the_edit_distanceObject

#

return_the_label_for_the_edit_distance

#

126
127
128
129
130
131
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 126

def return_the_label_for_the_edit_distance
  label_for_the_edit_distance = text('0')
  label_for_the_edit_distance.use_this_font = USE_THIS_MONOFONT
  label_for_the_edit_distance.make_bold
  return label_for_the_edit_distance
end

#set_edit_distance(i) ⇒ Object

#

set_edit_distance

#

117
118
119
120
121
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 117

def set_edit_distance(i)
  i = i.to_s
  @label_for_the_edit_distance.set_text(i.rjust(2))
  @label_for_the_edit_distance.make_bold
end

#set_entry1(i) ⇒ Object

#

set_entry1

#

300
301
302
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 300

def set_entry1(i)
  entry1?.set_text(i.to_s) unless i and i.start_with? '--'
end

#set_entry2(i) ⇒ Object

#

set_entry2

#

103
104
105
# File 'lib/bioroebe/gui/shared_code/levensthein_distance/levensthein_distance_module.rb', line 103

def set_entry2(i)
  entry2?.set_text(i.to_s) unless i and i.start_with? '--'
end