Class: Bioroebe::PossibleCodonsForThisAminoacid

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb

Overview

Bioroebe::PossibleCodonsForThisAminoacid

Constant Summary collapse

SHOW_ADDITIONAL_HINTS =
#

SHOW_ADDITIONAL_HINTS

If this constant is set to true, then we will additionally give some hints for the user about grouping purines and pyrimidines.

#
true
CODON_TABLE =
#

CODON_TABLE

#
::Bioroebe.codon_table?
ARRAY_PURINES =
#

ARRAY_PURINES

#
%w( A G )
ARRAY_PYRIMIDINES =
#

ARRAY_PYRIMIDINES

#
%w( T C )
TRY_TO_IDENTIFY_PURINES_AND_PYRIMIDINES =
#

TRY_TO_IDENTIFY_PURINES_AND_PYRIMIDINES

If this constant is set to true then we will attempt to group purines and pyrimidines.

#
true

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

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, #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

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_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

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(i = nil, run_already = true) ⇒ PossibleCodonsForThisAminoacid

#

initialize

#


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 64

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_simplify_purines_and_pyrimidines
    # ===================================================================== #
    when :do_not_simplify_purines_and_pyrimidines
      do_not_simplify_purines_and_pyrimidines
    end
  end
  run if run_already
end

Class Method Details

.[](i = '', replace_purines_and_pyrimidines = true) ⇒ Object

#

Bioroebe::PossibleCodonsForThisAminoacid[]

#


306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 306

def self.[](i = '', replace_purines_and_pyrimidines = true)
  _ = new(i, :do_not_run_yet)
  case replace_purines_and_pyrimidines
  when :use_only_the_four_standard_nucleotide_letters
    replace_purines_and_pyrimidine = false
  end
  unless replace_purines_and_pyrimidine
    _.set_try_to_identify_purines_and_pyrimidines false 
  end
  _.run
  return _.keys
end

.translate(i) ⇒ Object

#

Bioroebe::PossibleCodonsForThisAminoacid.translate

This method will conveniently return the Array that has the corresponding codons.

#


299
300
301
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 299

def self.translate(i)
  new(i).possible_codons?
end

Instance Method Details

#array_like_result?Boolean Also known as: pretty_result

#

array_like_result?

This method will report in an array-like manner.

#

Returns:

  • (Boolean)


241
242
243
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 241

def array_like_result?
  "[#{result?}]"
end

#do_not_simplify_purines_and_pyrimidinesObject

#

do_not_simplify_purines_and_pyrimidines

#


166
167
168
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 166

def do_not_simplify_purines_and_pyrimidines
  set_try_to_identify_purines_and_pyrimidines(false)
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


138
139
140
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 138

def input?
  @input
end

#is_purin?(i) ⇒ Boolean Also known as: is_purine?

#

is_purin?

#

Returns:

  • (Boolean)


152
153
154
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 152

def is_purin?(i)
  ARRAY_PURINES.include? i
end

#is_pyrimidin?(i) ⇒ Boolean Also known as: is_pyrimidine?

#

is_pyrimidin?

#

Returns:

  • (Boolean)


145
146
147
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 145

def is_pyrimidin?(i)
  ARRAY_PYRIMIDINES.include? i
end

#one_letter_to_full_name(i) ⇒ Object

#

one_letter_to_full_name

#


213
214
215
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 213

def one_letter_to_full_name(i)
  ::Bioroebe.convert_one_letter_to_full(i)
end

#original_input?Boolean

#

original_input?

#

Returns:

  • (Boolean)


102
103
104
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 102

def original_input?
  @original_input
end

#possible_codons?Boolean Also known as: keys?, keys, results?, array_as_result

#

possible_codons?

#

Returns:

  • (Boolean)


229
230
231
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 229

def possible_codons?
  @possible_codons
end

#report_resultObject Also known as: report

#

report_result

#


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 173

def report_result
  codon_singular_or_plural = 'codon'.dup
  codon_singular_or_plural << 's' if keys?.size > 1
  # ======================================================================= #
  # Build up the String that we will output.
  # ======================================================================= #
  one_letter_to_full_name = steelblue("#{one_letter_to_full_name(original_input?).capitalize}")+
                            rev
  result = "#{rev}The aminoacid #{simp(original_input?)}#{rev} "\
           "(#{one_letter_to_full_name}) "\
           "may be encoded by ".dup
  if keys?.size > 1
    result << 'these'
  else
    result << 'this'
  end
  result << rev+
            ' '+
            royalblue(keys?.size.to_s)+
            rev+
            ' nucleotide '+codon_singular_or_plural+
            ":\n\n"
  result << "  #{sfancy(array_like_result?)}#{rev}\n\n"

  # ======================================================================= #
  # Display the result next:
  # ======================================================================= #
  e result
  if SHOW_ADDITIONAL_HINTS
    if result?.include? 'Y'
      e '(Note that pyrimidines are denoted by the letter "Y").'
    elsif result?.include? 'R' 
      e '(Note that purines are denoted by the letter "R").'
    end
  end
end

#resetObject

#

reset (reset tag)

#


89
90
91
92
93
94
95
96
97
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 89

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @try_to_identify_purines_and_pyrimidines
  # ======================================================================= #
  @try_to_identify_purines_and_pyrimidines =
    TRY_TO_IDENTIFY_PURINES_AND_PYRIMIDINES
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)


220
221
222
223
224
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 220

def result?
  _ = keys?.join(',')
  _.chop! if _.end_with? ','
  _
end

#runObject

#

run (run tag)

#


283
284
285
286
287
288
289
290
291
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 283

def run
  # ======================================================================= #
  # Grab a handle to the codon table next.
  # ======================================================================= #
  possible_codons = Bioroebe.codon_table_dataset?.select {|key, value|
    key if value == input?
  }
  set_possible_codons(possible_codons.keys)
end

#set_input(i = '') ⇒ Object

#

set_input

#


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 109

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @original_input = i.dup
  # ======================================================================= #
  # The keys are downcased, so we downcase the input as well.
  # ======================================================================= #
  i.downcase!
  # ======================================================================= #
  # The following constant is a Hash, and it will have key->value pairs
  # such as "cysteine"=>"C".
  # ======================================================================= #
  if i.size > 1 # Assume that the user input the long name here.
    if AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER.has_key? i
      i = AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER[i]
    elsif AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER.has_key? i.chop # Try with the last char chopped off.
      i = AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER[i.chop]
    end
  end
  # ======================================================================= #
  # We want the input upcased past this point.
  # ======================================================================= #
  i.upcase!
  @input = i
end

#set_possible_codons(i = nil) ⇒ Object

#

set_possible_codons

#


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
275
276
277
278
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 248

def set_possible_codons(i = nil)
  # ======================================================================= #
  # Replace with shorter variants if the following variable is true.
  # ======================================================================= #
  if @try_to_identify_purines_and_pyrimidines
    i.map! {|entry| entry.to_s.dup }
    # ===================================================================== #
    # First check on purines.
    # ===================================================================== #
    last_characters = i.map {|entry| entry.chars.last }
    if last_characters.all? {|entry| is_purin?(entry) }
      # =================================================================== #
      # Ok, the last ones are all Purines here.
      # =================================================================== #
      i.map! {|entry|
        entry[-1,1] = 'R' # Adenin or Guanin.
        entry
      }
    elsif last_characters.all? {|entry| is_pyrimidin?(entry) }
      # =================================================================== #
      # Ok, the last ones are all Pyrimidines here. Y is the shortcut.
      # =================================================================== #
      i.map! {|entry|
        entry[-1,1] = 'Y' # # Cytosin or Thymin. 
        entry
      }
    end
  end
  i.uniq!
  @possible_codons = i
end

#set_try_to_identify_purines_and_pyrimidines(i) ⇒ Object

#

set_try_to_identify_purines_and_pyrimidines

#


159
160
161
# File 'lib/bioroebe/codons/possible_codons_for_this_aminoacid.rb', line 159

def set_try_to_identify_purines_and_pyrimidines(i)
  @try_to_identify_purines_and_pyrimidines = i
end