Class: Bioroebe::SimpleStringComparer
Overview
Bioroebe::SimpleStringComparer
Constant Summary
collapse
- STRING1 =
'gelfand'
- STRING2 =
'gandalf'
- VERTICAL_BAR =
'|'
- DEFAULT_MATCH_TOKEN =
#
DEFAULT_MATCH_TOKEN
This token is used to indicate a matching position. By default it will be the ‘|’ character.
#
VERTICAL_BAR
CommandlineApplication::OLD_VERBOSE_VALUE
ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Constants inherited
from Base
Base::NAMESPACE
Instance Method Summary
collapse
#all_aminoacids?, #append_what_into, #at_home?, #be_silent, #be_verbose?, #cat, #ccliner, #change_directory, #cliner, #codon_table_dataset?, #codon_to_aminoacid, #codons_for?, #colourize_this_dna_sequence, #complement, #cp, #disable_warnings, #download_dir?, #editor?, #enable_warnings, #ensure_that_the_base_directories_exist, #esystem, #extract, #is_this_a_start_codon?, #is_this_a_stop_codon?, #leading_five_prime, #load_bioroebe_yaml_file, #log_directory?, #one_letter_to_long_name, #one_to_three, #only_numbers?, #open_in_browser, #opnerev, #opnn, #pad_with_double_quotes, #pad_with_single_quotes, #partner_nucleotide, #remove_numbers, #remove_trailing_ansii_escape_code, #return_all_possible_start_codons, #return_array_of_one_letter_aminoacids, #return_cheerful_person, #return_chunked_display, #return_ubiquitin_sequence, #runmode?, #set_be_verbose, #set_runmode, #start_codon?, #stop_codons?, #strict_filter_away_invalid_aminoacids, #taxonomy_download_directory?, #three_to_one, #to_rna, #trailing_three_prime, #use_opn?, #verbose_truth, #was_or_were, #without_extname, #write_what_into
Methods included from BaseModule
#absolute_path, #default_file_read, #file_readlines
#commandline_arguments?, #commandline_arguments_that_are_files?, #e, #first?, #first_non_hyphen_argument?, #remove_hyphens_from_the_commandline_arguments, #return_commandline_arguments_as_string, #return_commandline_arguments_that_are_not_files, #return_entries_without_two_leading_hyphens, #select_commandline_arguments, #select_entries_starting_with_two_hyphens, #set_commandline_arguments
#colourize_this_aminoacid_sequence_for_the_commandline, #colourize_this_nucleotide_sequence, #disable_colours, #ecomment, #efancy, #egold, #enable_colours, #eorange, #eparse, #erev, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #rev, #sdir, #set_will_we_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?
Methods inherited from Base
#append_what_into, #can_base_pair?, #convert_global_env, #delete_file, #directory_to_the_codon_tables?, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #no_file_exists_at, #no_newlines, #project_yaml_directory?, #rds, #register_sigint, #return_pwd, #return_the_first_line_of_this_file, #word_wrap, #write_what_into
#internal_hash?, #reset_the_internal_hash
#infer_the_namespace, #namespace?
Constructor Details
#initialize(i = nil, run_already = true, &block) ⇒ SimpleStringComparer
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
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 60
def initialize(
i = nil,
run_already = true,
&block
)
reset
set_commandline_arguments(i)
case i
when nil when :dont_run_yet
i = nil
run_already = false
else
guess_from_this_input(i)
end
if block_given?
yielded = yield
case yielded
when :disable_colours
disable_colours
when :use_vertical_bar
set_match_token :vertical_bar
end
end
run if run_already
end
|
Instance Method Details
#consider_notifying_the_user_if_the_sequences_are_not_equal_in_length ⇒ Object
#
consider_notifying_the_user_if_the_sequences_are_not_equal_in_length
#
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 292
def consider_notifying_the_user_if_the_sequences_are_not_equal_in_length
if @string1.size == @string2.size
else
e
e '(Note that the two sequences are not equal in length. This class'
e 'will only try to align from the starting position of both'
e 'sequences as-is.)'
end
end
|
#do_compare ⇒ Object
Also known as:
compare
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
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 243
def do_compare
e rev chars1 = string1?.chars
array1 = chars1.each_slice(80).to_a.map {|entry|
entry.join
}
chars2 = string2?.chars
array2 = chars2.each_slice(80).to_a.map {|entry|
entry.join
}
array3 = chars1.zip(chars2).map {|entry|
match_or_no_match_for(entry[0], entry[1])
}.each_slice(80).to_a.map {|entry|
entry.join
}.map {|line|
line.gsub(
/\|/,
send(@colour_for_a_match.to_sym, match_token?)+
rev
) }
0.upto(array1.size-1) {|index|
e array1[index]
e array3[index] e array2[index]
}
consider_notifying_the_user_if_the_sequences_are_not_equal_in_length
e
end
|
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
145
146
147
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 119
def guess_from_this_input(i)
i.flatten! if i.is_a? Array
if i.is_a? Array and i.empty?
splitted = [STRING1, STRING2]
else
splitted = i
end
if splitted and splitted.first.include?('|')
splitted = splitted.first
end
splitted = splitted.split(N) unless splitted.is_a? Array
splitted.map!(&:strip) if splitted.is_a? Array
case splitted.size
when 1
if splitted.first.include? '|'
splitted = splitted.first.split('|')
end
end
end
set_string_one(splitted.first)
set_string_last(splitted.last)
end
|
#match_or_no_match_for(char1, char2) ⇒ Object
#
match_or_no_match_for
#
205
206
207
208
209
210
211
212
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 205
def match_or_no_match_for(char1, char2)
if char1 == char2
@n_matches += 1
return_match_token
else
return_non_match_token
end
end
|
#match_token? ⇒ Boolean
236
237
238
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 236
def match_token?
@match_token
end
|
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 307
def (
i = commandline_arguments_with_leading_hyphens?
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when /^-?-?colour(-|_| )?for(-|_| )?a(-|_| )?match=(.+)$/ set_colour_for_a_match($4.to_s.dup)
end
end
end
|
#n_matches? ⇒ Boolean
198
199
200
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 198
def n_matches?
@n_matches
end
|
#reset ⇒ Object
#
reset (reset tag)
Set default values for the two Strings.
#
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 98
def reset
super()
set_string1 STRING1
set_string2 STRING2
@n_matches = 0
set_match_token
@non_match_token = '.' set_colour_for_a_match
end
|
#return_match_token ⇒ Object
191
192
193
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 191
def return_match_token
@match_token
end
|
#return_non_match_token ⇒ Object
#
return_non_match_token
#
183
184
185
186
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 183
def return_non_match_token
return swarn(@non_match_token)+rev if use_colours? @non_match_token end
|
#run ⇒ Object
326
327
328
329
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 326
def run
(commandline_arguments_with_leading_hyphens?)
do_compare
end
|
#set_colour_for_a_match(i = :default) ⇒ Object
#
set_colour_for_a_match
#
279
280
281
282
283
284
285
286
287
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 279
def set_colour_for_a_match(
i = :default
)
case i
when :default
i = :seagreen
end
@colour_for_a_match = i
end
|
#set_match_token(i = DEFAULT_MATCH_TOKEN) ⇒ Object
Also known as:
set_main_alignment_token_to
#
set_match_token
You can define another match token here. The default is ‘+’, another popular variant would be ‘|’.
#
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 220
def set_match_token(
i = DEFAULT_MATCH_TOKEN
)
case i
when :vertical_bar
i = VERTICAL_BAR
end
@match_token = i
end
|
#set_string1(i) ⇒ Object
Also known as:
string1=, set_string_one
152
153
154
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 152
def set_string1(i)
@string1 = i
end
|
#set_string2(i) ⇒ Object
Also known as:
string2=, set_string_two, set_string_last
160
161
162
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 160
def set_string2(i)
@string2 = i
end
|
#string1? ⇒ Boolean
Also known as:
input?
169
170
171
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 169
def string1?
@string1
end
|
#string2? ⇒ Boolean
Also known as:
string2
176
177
178
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 176
def string2?
@string2
end
|