Module: Bioroebe::GUI::LibUI::HammingDistance

Includes:
LibuiParadise::Extensions
Defined in:
lib/bioroebe/gui/libui/hamming_distance/hamming_distance.rb

Overview

Bioroebe::GUI::LibUI::HammingDistance

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject

#

Bioroebe::GUI::LibUI::HammingDistance.run

#

125
126
127
128
129
# File 'lib/bioroebe/gui/libui/hamming_distance/hamming_distance.rb', line 125

def self.run
  object = Object.new
  object.extend(HammingDistance)
  object.run
end

Instance Method Details

#compare_the_two_sequences(seq1, seq2, entry) ⇒ Object Also known as: do_compare, do_calculate_the_differences

#

compare_the_two_sequences

This is the method that will compare the two sequences.

#

113
114
115
116
117
118
119
# File 'lib/bioroebe/gui/libui/hamming_distance/hamming_distance.rb', line 113

def compare_the_two_sequences(
    seq1, seq2, entry
  )
  hamming_distance_object = ::Bioroebe::HammingDistance.new("#{seq1} #{seq2}") { :be_quiet }
  _ = hamming_distance_object.n_differences?.to_s
  UI.entry_set_text(entry, _)
end

#create_skeletonObject

#

create_skeleton (create tag)

#

34
35
36
37
38
39
# File 'lib/bioroebe/gui/libui/hamming_distance/hamming_distance.rb', line 34

def create_skeleton
  # ======================================================================= #
  # === @entry_n_differences
  # ======================================================================= #
  @entry_n_differences = UI.entry
end

#initializeObject

#

initialize

#

28
29
# File 'lib/bioroebe/gui/libui/hamming_distance/hamming_distance.rb', line 28

def initialize
end

#runObject

#

run

#

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/bioroebe/gui/libui/hamming_distance/hamming_distance.rb', line 44

def run
  create_skeleton
  main_window = ui_margined_window('Hamming Distance', 1200, 200, 0)
  # ======================================================================= #
  # Next add the two hboxes that will contain the two sequences.
  # ======================================================================= #
  text_changed_callback = proc { |ptr|
    text = text?(ptr)
    upcased_text = text.upcase
    UI.entry_set_text(ptr, upcased_text)
  }

  hbox1  = ui_padded_hbox
  text1  = text(1)
  @entry1 = ui_entry('ATG')
  UI.entry_on_changed(@entry1, text_changed_callback, nil)
  hbox1.add(text1, 1)
  hbox1.add(@entry1, 1)
  hbox1.set_padded(1)

  hbox2  = ui_padded_hbox
  text2  = text(2)
  @entry2 = ui_entry('ATT')
  UI.entry_on_changed(@entry2, text_changed_callback, nil)
  hbox2.add(text2, 1)
  hbox2.add(@entry2, 1)
  hbox2.set_padded(1)

  hbox_compare_the_two_sequences = ui_hbox
  # ======================================================================= #
  # The hbox that has the "n differences found".
  # ======================================================================= #
  hbox_n_differences_found = ui_hbox
  button_compare_the_two_sequences = ui_button('Compare the two sequences')
  button_compare_the_two_sequences.on_clicked {
    text1 = UI.entry_text(@entry1)
    text2 = UI.entry_text(@entry2)
    compare_the_two_sequences(text1, text2, @entry_n_differences)
    0
  }
  hbox_compare_the_two_sequences.add(button_compare_the_two_sequences, 1)
  hbox_n_differences_found.add(text('n differences found'), 1)
  hbox_n_differences_found.add(@entry_n_differences, 1)
  # ======================================================================= #
  # This is the main vbox.
  # ======================================================================= #
  vbox = ui_padded_vbox
  vbox.maximal(text('Hamming Distance'))
  vbox.maximal(
    text(
      "The Hamming distance - a number - measures the number of "\
      "\npositions at which two strings of equal length are "\
      "different."
    )
  )
  vbox.maximal(hbox1)
  vbox.add(hbox2, 1)
  vbox.add(hbox_compare_the_two_sequences, 1)
  vbox.add(hbox_n_differences_found, 1)
  main_window.child = vbox
  main_window.control_show
  main_window.elegant_exit
end