Class: Bioroebe::PalindromeFinder
- Inherits:
-
CommandlineApplication
- Object
- Base
- CommandlineApplication
- Bioroebe::PalindromeFinder
- Defined in:
- lib/bioroebe/palindromes/palindrome_finder.rb
Constant Summary collapse
- DEFAULT_SEARCH_STRING =
#
DEFAULT_SEARCH_STRING
#
'RENTNER reliefpfeiler anna ATCTA'
Constants inherited from CommandlineApplication
CommandlineApplication::OLD_VERBOSE_VALUE
Constants included from ColoursForBase
ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Constants inherited from Base
Instance Method Summary collapse
-
#display_results ⇒ Object
# === display_results ========================================================================= #.
-
#find_complex_palindromes ⇒ Object
# === find_complex_palindromes.
-
#find_seeds ⇒ Object
# === find_seeds.
-
#find_simple_palindromes ⇒ Object
# === find_palindrome.
-
#initialize(string_to_search = 'RENTNER reliefpfeiler anna ATCTA', do_display_results = false) ⇒ PalindromeFinder
constructor
# === initialize.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#set_string_to_search(i = DEFAULT_SEARCH_STRING) ⇒ Object
# === set_string_to_search ========================================================================= #.
Methods inherited from CommandlineApplication
#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
Methods included from CommandlineArguments
#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
Methods included from ColoursForBase
#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(string_to_search = 'RENTNER reliefpfeiler anna ATCTA', do_display_results = false) ⇒ PalindromeFinder
#
initialize
Can also invoke it via rpalindrome. Currently we can find only palindromes which have odd numbers
#
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 31 def initialize( string_to_search = 'RENTNER reliefpfeiler anna ATCTA', do_display_results = false ) case do_display_results when :display_results do_display_results = true end set_string_to_search( string_to_search ) reset run if do_display_results end |
Instance Method Details
#display_results ⇒ Object
#
display_results
#
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 179 def display_results e "#{rev}Looking for results in the string "\ "`#{sfancy(@string_to_search)}#{rev}`:" if @array_found_palindrome.empty? erev 'No Palindrome was found in this string.' else @array_found_palindrome.each_with_index { |palindrome, index| erev 'Palindrome '+steelblue(index.to_s) erev " #{palindrome.first}" } end end |
#find_complex_palindromes ⇒ Object
#
find_complex_palindromes
Please invoke this method only after find_simple_palindromes has been invoked. This is not very smart right now, but i dont wanna change it yet. :P
May be half deprecated hmmm.
#
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 122 def find_complex_palindromes @array_found_palindrome.each { |palindrome| palindrome_start_pos = palindrome[1] palindrome_content = palindrome[0] if @string_to_search[palindrome_start_pos-1,1] == @string_to_search[palindrome_start_pos+palindrome_content.size+1,1] e sfancy( @string_to_search[palindrome_start_pos - 1, 1]+ palindrome_content+ @string_to_search[palindrome_start_pos+palindrome_content.size+1,1] ) end } end |
#find_seeds ⇒ Object
#
find_seeds
This method finds every seed to a palindrome in a given string.
It will return an array with their respective positions.
#
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 95 def find_seeds index = 0 array = [] @string_to_search.each_char { |char| current_char = char next_char = @string_to_search[index+1, 1] last_char = @string_to_search[index-1, 1] if next_char == ' ' or last_char == ' ' or current_char == ' ' # Skip empty lines index += 1 next else array << index if next_char == last_char index += 1 end } return array end |
#find_simple_palindromes ⇒ Object
#
find_palindrome
What is the property of a palindrome?
anna, otto, abcba, eeegeee, RENTNER, Reliefpfeiler
Basically a property.
The “middle” part is normally static.
#
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 147 def find_simple_palindromes index = 1 string_size = @string_to_search.size loop { if @string_to_search[index, 1] == ' ' # safe guard to intercept (and ignore) empty positions (i.e. space char) elsif @string_to_search[index-1, 1] == ' ' and @string_to_search[index+1,1] == ' ' # Here too. else @last_char = @string_to_search[index-1,1] @current_char = @string_to_search[index,1] @next_char = @string_to_search[index+1,1] if @next_char == @last_char palindrome = @last_char+@current_char+@next_char pp palindrome # The format for @array_found_palindrome is: # 0 sequence # 1 start_position # 2 end_position @array_found_palindrome << [ palindrome, index-1 ] end end index += 1 break if string_size == index } e end |
#reset ⇒ Object
#
reset (reset tag)
#
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 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 49 def reset super() # ======================================================================= # # === @array_found_palindrome # # This array will keep the palindromes. # ======================================================================= # @array_found_palindrome = [] # ======================================================================= # # === @last_char # ======================================================================= # @last_char = '' # ======================================================================= # # === @current_char # ======================================================================= # @current_char = '' # ======================================================================= # # === @next_char # ======================================================================= # @next_char = '' # ======================================================================= # # === @longest_palindrome # ======================================================================= # @longest_palindrome = nil # if we did found a palindrome, this counter # tells us how many chars it has. end |
#run ⇒ Object
#
run
#
195 196 197 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 195 def run display_results end |
#set_string_to_search(i = DEFAULT_SEARCH_STRING) ⇒ Object
#
set_string_to_search
#
79 80 81 82 83 84 85 86 |
# File 'lib/bioroebe/palindromes/palindrome_finder.rb', line 79 def set_string_to_search( i = DEFAULT_SEARCH_STRING ) i = i.first if i.is_a? Array i = DEFAULT_SEARCH_STRING if i.nil? i = DEFAULT_SEARCH_STRING if i.is_a?(Array) and i.empty? @string_to_search = i end |