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, #opne, #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, #set_be_verbose, #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
#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_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?, #file_readlines, #infer_the_namespace, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #namespace?, #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
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
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 60
def initialize(
i = nil,
run_already = true,
&block
)
reset
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
#
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 269
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
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
263
264
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 237
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(/\|/, seagreen(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
|
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
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 117
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
splitted = splitted.split(N) unless splitted.is_a? Array
splitted.map!(&:strip) if splitted.is_a? Array
if splitted.size == 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
#
199
200
201
202
203
204
205
206
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 199
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
230
231
232
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 230
def match_token?
@match_token
end
|
#n_matches? ⇒ Boolean
192
193
194
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 192
def n_matches?
@n_matches
end
|
#reset ⇒ Object
#
reset (reset tag)
Set default values for the two Strings.
#
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 97
def reset
super()
set_string1 STRING1
set_string2 STRING2
@n_matches = 0
set_match_token
@non_match_token = '.' end
|
#return_match_token ⇒ Object
185
186
187
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 185
def return_match_token
@match_token
end
|
#return_non_match_token ⇒ Object
#
return_non_match_token
#
177
178
179
180
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 177
def return_non_match_token
return swarn(@non_match_token)+rev if use_colours? @non_match_token end
|
#run ⇒ Object
284
285
286
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 284
def run
do_compare
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 '|'.
#
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 214
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
146
147
148
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 146
def set_string1(i)
@string1 = i
end
|
#set_string2(i) ⇒ Object
Also known as:
string2=, set_string_two, set_string_last
154
155
156
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 154
def set_string2(i)
@string2 = i
end
|
#string1? ⇒ Boolean
Also known as:
input?
163
164
165
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 163
def string1?
@string1
end
|
#string2? ⇒ Boolean
Also known as:
string2
170
171
172
|
# File 'lib/bioroebe/string_matching/simple_string_comparer.rb', line 170
def string2?
@string2
end
|