Class: Bioroebe::ShowThisCodonTable

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

Constant Summary collapse

LPAD =
#

LPAD

#
'  '
MPAD =
#

MPAD

#
'      '
CYAN =
#

CYAN

#
Colours::CYAN
CYAN_U =
CYAN+'U'
CYAN_A =
CYAN+'A'
CYAN_G =
CYAN+'G'
CYAN_C =
CYAN+'C'
ARRAY_ALL_CODONS =
#

CodonTable::ARRAY_ALL_CODONS (array tag)

This Array will be used to batch-define the necessary methods.

#
%w(

  TTT? TTC? TTA? TTG?
  TCT? TCC? TCA? TCG?
  TAT? TAC? TAA? TAG?
  TGT? TGC? TGA? TGG?

  CTT? CCT? CAT? CGT?
  CTC? CCC? CAC? CGC?
  CTA? CCA? CAA? CGA?
  CTG? CCG? CAG? CGG?

  ATT? ACT? AAT? AGT?
  ATC? ACC? AAC? AGC?
  ATA? ACA? AAA? AGA?
  ATG? ACG? AAG? AGG?

  GTT? GCT? GAT? GGT?
  GTC? GCC? GAC? GGC?
  GTA? GCA? GAA? GGA?
  GTG? GCG? GAG? GGG?

)
STOP =
#

STOP

The stop codon.

#
Colours::RED+'STOP'+Colours::GREEN
DEFAULT_CODON_TABLE_TO_USE =
#

DEFAULT_CODON_TABLE_TO_USE

#
:human

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

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, #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?, #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, #egold, #enable_colours, #eorange, #eparse, #erev, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #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, #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, #write_what_into

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ ShowThisCodonTable

#

initialize

#


99
100
101
102
103
104
105
106
107
108
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 99

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Instance Method Details

#colourized_line(i) ⇒ Object

#

colourized_line

#


345
346
347
348
349
350
351
352
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 345

def colourized_line(i)
  result = i.dup.gsub(/\*/, stop?).
                 gsub(/START/, '*').
                 squeeze('*').
                 gsub(/\*/,tomato('*')+rev)
  e result
  i
end

#consider_using_a_specific_codon_table(i = first_argument?) ) ⇒ Object

#

consider_using_a_specific_codon_table

#


206
207
208
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 206

def consider_using_a_specific_codon_table(i = first_argument?)
  set_use_this_codon_table(i)
end

#cyanObject

#

cyan

#


199
200
201
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 199

def cyan
  CYAN # This will work, as CYAN has been defined in this file.
end

#cyanaObject Also known as: cyan_a, cyan_A

#

cyana

#


183
184
185
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 183

def cyana
  cyan+'A'+rev
end

#cyancObject Also known as: cyan_c, cyan_C

#

cyanc

#


486
487
488
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 486

def cyanc
  cyan+'C'+rev
end

#cyangObject Also known as: cyan_g, cyan_G

#

cyang

#


191
192
193
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 191

def cyang
  cyan+'G'+rev
end

#cyanuObject Also known as: cyan_U, cyan_u, cyan_T

#

cyanu

This will either show a U or a T.

#


466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 466

def cyanu
  case @show_rna_or_dna
  # ======================================================================= #
  # === :rna
  # ======================================================================= #
  when :rna
    "#{cyan}U#{rev}"
  # ======================================================================= #
  # === :dna
  # ======================================================================= #
  when :dna
    "#{cyan}T#{rev}"
  end
end

#dataset?Boolean

#

dataset?

#

Returns:

  • (Boolean)


249
250
251
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 249

def dataset?
  ::Bioroebe.codon_table_dataset?
end

#determine_all_codon_methods(dataset = dataset? ) ⇒ Object

#

determine_all_codon_methods

Dynamically define the proper methods.

#


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 303

def determine_all_codon_methods(
    dataset = dataset?
  )
  start_codons = dataset['START']
  if start_codons.include? '|'
    start_codons = start_codons.split('|').map(&:strip)
  end
  if @autogenerate_codon_related_methods
    dataset = dataset?
    ARRAY_ALL_CODONS.each {|entry|
      entry = entry.to_sym
      # =================================================================== #
      # We will only define these methods once.
      # =================================================================== #
      unless self.respond_to? entry
        # ================================================================= #
        # We define methods on this class, such as .GGG? and similar.
        # ================================================================= #
        self.class.instance_eval {
          define_method(entry) {
            name_of_the_codon = __method__.to_s.chop
            if dataset.has_key? name_of_the_codon
              result = dataset.fetch(name_of_the_codon)
              result = stop? if result == '*'
              if start_codons.include? name_of_the_codon
                result << 'START'
              end
            else
              result = 'UNKNOWN (from '+name_of_the_codon+')'
            end
            return result
          }
        }
      end
    }
    @autogenerate_codon_related_methods = false
  end
end

#determine_datasetObject

#

determine_dataset

This method will determine the correct codon-dataset. It has to make sure that the codon table actually exists, though.

#


430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 430

def determine_dataset
  # ======================================================================= #
  # We must set the correct title to use, if no argument was provided.
  # ======================================================================= #
  if title?.nil? and first_argument?.nil?
    set_title("Standard (Eukaryote) Codon Table")
    set_codon_table(1)
  end
  this_codon_table = use_which_codon_table?
  if this_codon_table.is_a?(String) and (this_codon_table =~ /^\d+$/)
    title = ::Bioroebe::CodonTables.definitions?[this_codon_table.to_i]
    set_title(title)  
  end
end

#display_titleObject

#

display_title

This method will show the title of the codon table in question.

#


416
417
418
419
420
421
422
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 416

def display_title
  title = title?
  if title
    erev title+' (codon table number: '+
         steelblue(codon_table?.to_s)+rev+'):'
  end
end

#greenObject Also known as: rev

#

green

#


169
170
171
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 169

def green
  Colours::GREEN
end

#is_this_codon_table_available?(i) ⇒ Boolean

#

is_this_codon_table_available?

#

Returns:

  • (Boolean)


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

def is_this_codon_table_available?(i)
  target = directory_to_the_codon_tables?+"#{i}.yml"
  return File.exist?(target)
end

#left_padObject

#

left_pad

#


515
516
517
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 515

def left_pad
  print '  ' 
end

#lpad(i) ⇒ Object

#

lpad

#


221
222
223
224
225
226
227
228
229
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 221

def lpad(i)
  if i.include? 'STOP'
    i+'   '
  elsif i.include? 'START'
    i+'     '
  else
    i+'      '
  end
end

#lpad?Boolean

#

lpad?

#

Returns:

  • (Boolean)


234
235
236
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 234

def lpad?
  LPAD
end

#lpad_on(*i) ⇒ Object

#

lpad_on

This method combines several calls such as this:

lpad(TTC?)+lpad(TCC?)+lpad(TAC?)+lpad(TGC?)

It was too long, so it was changed to.

lpad_on(TTT?, TCT?, TAT?, TGT?)
#


294
295
296
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 294

def lpad_on(*i)
  i.map {|entry| lpad(entry) }.join
end
#

menu (menu tag)

#


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 357

def menu(
    i = @commandline_arguments
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === codontable --rna
    #
    # This variant will display the table as "RNA".
    #
    # Invocation examples:
    #
    #   ctable --rna
    #   ctable 1 --rna
    #
    # ===================================================================== #
    when /^-?-?rna$/i
      @show_rna_or_dna = :rna
      @commandline_arguments.reject! {|entry| entry.to_s =~ /^-?-?rna$/i }
    else
      if i.to_s =~ /^(\d{1,2})-(\d{1,2})$/
        # ================================================================= #
        #   ctable 1-3
        # ================================================================= #
        $1.to_i.upto($2.to_i) {|n|
          consider_using_a_specific_codon_table(n)
          determine_dataset
          determine_all_codon_methods
          display_codon_table
        }
        exit
      elsif i.to_s =~ /^\d{1,2}$/
        # ================================================================= #
        # Need to convert into a real number.
        #
        # Usage Examples:
        #
        #   ctable 1
        #   ctable 3
        #   ctable 1-2
        #
        # ================================================================= #
        require 'bioroebe/codons/codon_tables.rb'
        @commandline_arguments[0] = i.to_i
        set_title(
          Bioroebe::CodonTables.title_for_entry_number?(i.to_i)
        )
      end
    end
  end
end

#notify_the_user_that_no_such_codon_table_could_be_foundObject

#

notify_the_user_that_no_such_codon_table_could_be_found

#


448
449
450
451
452
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 448

def notify_the_user_that_no_such_codon_table_could_be_found
  erev 'No codon table matching this input ('+
       steelblue(first_argument?.to_s)+
       rev+') could be found.'
end

#resetObject

#

reset

#


113
114
115
116
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
142
143
144
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 113

def reset
  super()
  @internal_hash = {}
  # ======================================================================= #
  # === :title
  # ======================================================================= #
  @internal_hash[:title] = nil
  # ======================================================================= #
  # === @is_available
  #
  # This instance variable keeps track as to whether the given coden
  # table is available or whether it is not, based on a number. For
  # some reasons, probably historic reasons, some numbers are missing.
  #
  # By default this variable is true, but it will be set to false if
  # the input can not be correlated to an existing codon table.
  # ======================================================================= #
  @is_available = false
  # ======================================================================= #
  # === @show_rna_or_dna
  #
  # This variable can be either :dna or :rna.
  #
  # The default is :dna. If you wish to set this to :rna on the commandline
  # then you can use "codontable --rna".
  # ======================================================================= #
  @show_rna_or_dna = :dna
  # ======================================================================= #
  # === @autogenerate_codon_related_methods
  # ======================================================================= #
  @autogenerate_codon_related_methods = true
end

#return_dataset_from_codon_table(this_codon_table = use_which_codon_table? ) ⇒ Object

#

return_dataset_from_codon_table

This method will return the dataset from the codon table.

#


258
259
260
261
262
263
264
265
266
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 258

def return_dataset_from_codon_table(
    this_codon_table = use_which_codon_table?
  )
  if this_codon_table.is_a?(String) and (this_codon_table =~ /^\d+$/)
    this_codon_table = this_codon_table.to_i
    set_codon_table(this_codon_table)
  end
  ::Bioroebe.codon_table_dataset?
end

#runObject

#

run

#


556
557
558
559
560
561
562
563
564
565
566
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 556

def run
  menu
  consider_using_a_specific_codon_table
  determine_dataset
  determine_all_codon_methods
  if @is_available
    display_codon_table
  else
    notify_the_user_that_no_such_codon_table_could_be_found
  end
end

#set_codon_table(i) ⇒ Object

#

set_codon_table

#


271
272
273
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 271

def set_codon_table(i)
  ::Bioroebe.set_codon_table(i)
end

#set_title(i = nil) ⇒ Object

#

set_title

#


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 149

def set_title(
    i = nil
  )
  if i and i.is_a?(String)
    i = i.dup if i.frozen?
    i << ' Codon Table' unless i.end_with?(' Codon Table')
  end
  # ======================================================================= #
  # === :title
  #
  # @title will keep track of the title of the specific codon table.
  # That is, every codon table has a specific name such as "Standard
  # Eukaryotic Table".
  # ======================================================================= #
  @internal_hash[:title] = i
end

#set_use_this_codon_table(i = DEFAULT_CODON_TABLE_TO_USE) ⇒ Object

#

set_use_this_codon_table

This will initially hold the codon table internally.

#


496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 496

def set_use_this_codon_table(
    i = DEFAULT_CODON_TABLE_TO_USE
  )
  i = i.first if i.is_a? Array
  case i
  when 'human'
    i = 1
  when nil
    i = DEFAULT_CODON_TABLE_TO_USE
  end
  if is_this_codon_table_available?(i)
    @is_available = true
    ::Bioroebe.set_use_this_codon_table(i)
  end
end

#stop?Boolean

#

stop?

#

Returns:

  • (Boolean)


176
177
178
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 176

def stop?
  STOP
end

#title?Boolean

#

title?

#

Returns:

  • (Boolean)


278
279
280
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 278

def title?
  @internal_hash[:title]
end

#top_row_headerObject

#

top_row_header

#


457
458
459
# File 'lib/bioroebe/codons/show_this_codon_table.rb', line 457

def top_row_header
  e cyan+N+LPAD+'      '+cyanu+MPAD+cyanc+MPAD+cyana+MPAD+cyang
end

#use_this_codon_table?Boolean Also known as: use_which_codon_table?, codon_table?

#

use_this_codon_table?

#

Returns:

  • (Boolean)


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

def use_this_codon_table?
  ::Bioroebe.codon_table?
end