Class: Bioroebe::DeduceAminoacidSequence

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb

Overview

Bioroebe::DeduceAminoacidSequence

Constant Summary collapse

DEFAULT_SEQUENCE =
#

DEFAULT_SEQUENCE

This constant specifies a default aminoacid sequence that could be used.

#
'M-K-S-P-S-L-N-A-A-K'

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(commandline_arguments = DEFAULT_SEQUENCE, format_how = :dna, run_already = true) ⇒ DeduceAminoacidSequence

#

initialize

#


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 53

def initialize(
    commandline_arguments = DEFAULT_SEQUENCE,
    format_how            = :dna,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  set_format_how(format_how)
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Bioroebe::DeduceAminoacidSequence[]

#


456
457
458
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 456

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#aminoacid_sequence?Boolean Also known as: input?, array_aminoacid_sequence?, main_array?

#

aminoacid_sequence?

#

Returns:

  • (Boolean)


382
383
384
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 382

def aminoacid_sequence?
  @internal_hash[:aminoacid_sequence]
end

#aminoacid_to_possible_codons(this_aminoacid) ⇒ Object Also known as: possible_codons_for_this_aminoacid, show_possible_codons_for_this_aminoacid

#

aminoacid_to_possible_codons

Internally this method depends on class PossibleCodonsForThisAminoacid.

#


374
375
376
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 374

def aminoacid_to_possible_codons(this_aminoacid)
  return ::Bioroebe.aminoacid_to_possible_codons(this_aminoacid).sort # .sort was added on 25.09.2019
end

#array_all_discovered_codons?Boolean Also known as: all_codons?, codons_to_use?, discovered_codons?

#

array_all_discovered_codons?

#

Returns:

  • (Boolean)


228
229
230
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 228

def array_all_discovered_codons?
  @internal_hash[:array_all_discovered_codons]
end

#determine_the_aminoacid_sequence(from_this_given_input = first? ) ⇒ Object

#

determine_the_aminoacid_sequence

#


152
153
154
155
156
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 152

def determine_the_aminoacid_sequence(
    from_this_given_input = first?
  )
  set_aminoacid_sequence(from_this_given_input)
end

#display_separator(n_aminoacids = n_aminoacids? ) ⇒ Object

#

display_separator (middle tag)

#


277
278
279
280
281
282
283
284
285
286
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 277

def display_separator(
    n_aminoacids = n_aminoacids?
  )
  distance = UNICODE_HORIZONTAL_BAR*5# + '┬'
  e ' '+swarn(
    (
      (distance * n_aminoacids)+'----'
    ).chop
  )
end

#do_show_a_possible_sequence(array = first_row_of_the_codons_to_use? ) ⇒ Object

#

do_show_a_possible_sequence

This will simply show the very first sequence that would code for the given codon at hand.

#


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
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 247

def do_show_a_possible_sequence(
    array = first_row_of_the_codons_to_use?
  )
  erev 'One likely possible '+
       colourize_dna_sequence('sequence ')+
       'on the DNA/RNA level '\
       'may thus be:'
  e
  _ = array
  sequence = '  '+_.join('-')
  ruler = ::Bioroebe.ruler_return_as_string_without_colours(sequence.strip.delete('-'))
  ruler = ruler.scan(/.{3}|.+/).join('-')
  n_nucleotides = springgreen(
    ruler.strip.delete('-').size.to_s
  )
  erev '     '+ruler+' # ('+n_nucleotides+rev+' nucleotides)'
  result = colourize_this_dna_sequence(sequence.strip)
  if show_the_rna_sequence?
    result.tr!('T','U')
  end
  erev "  5'-"+result+"-3'"
  e '     '+
      result.delete('-')+
      rev+' (← standalone sequence)'
  e
end

#do_show_the_rna_sequenceObject

#

do_show_the_rna_sequence

#


145
146
147
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 145

def do_show_the_rna_sequence
  set_show_the_rna_sequence :rna
end

#first_row_of_the_codons_to_use?Boolean

#

first_row_of_the_codons_to_use?

#

Returns:

  • (Boolean)


237
238
239
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 237

def first_row_of_the_codons_to_use?
  return codons_to_use?.map {|inner_array| inner_array[0] }.compact
end

#map_each_aminoacid_to_an_array_of_corresponding_codons(_ = aminoacid_sequence? ) ⇒ Object

#

map_each_aminoacid_to_an_array_of_corresponding_codons

#


357
358
359
360
361
362
363
364
365
366
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 357

def map_each_aminoacid_to_an_array_of_corresponding_codons(
    _ = aminoacid_sequence?
  )
  array_of_corresponding_codons = []
  _.each_char {|this_aminoacid|
    array = aminoacid_to_possible_codons(this_aminoacid)
    array_of_corresponding_codons << array
  }
  return array_of_corresponding_codons
end
#

menu (menu tag)

#


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
341
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 316

def menu(
    i = return_commandline_arguments_starting_with_hyphens
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === --help
    # ===================================================================== #
    when /^-?-?help$/i
      show_help
      exit
    # ===================================================================== #
    # === --RNA
    #
    # Usage example:
    #
    #   deduce WDENNM --RNA
    #
    # ===================================================================== #
    when /--RNA$/i
      do_show_the_rna_sequence
    end
  end
end

#n_aminoacids?Boolean

#

n_aminoacids?

Return the amount (an integer value) of aminoacids.

#

Returns:

  • (Boolean)


203
204
205
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 203

def n_aminoacids?
  aminoacid_sequence?.delete('-').size
end

#report(array_containing_all_discovered_codons = array_all_discovered_codons? ) ⇒ Object

#

report (report tag)

This is the primary method for reporting the codon sequence at hand.

#


428
429
430
431
432
433
434
435
436
437
438
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 428

def report(
    array_containing_all_discovered_codons =
      array_all_discovered_codons?
  )
  show_the_header # This has the long intro-text.
  show_the_aminoacid_sequence_in_steelblue_and_orange_colour
  show_all_possible_codons
  if show_a_possible_sequence?
    do_show_a_possible_sequence
  end
end

#resetObject

#

reset (reset tag)

#


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 69

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === :aminoacid_sequence
  #
  # This will contain the aminoacid sequence.
  # ======================================================================= #
  @internal_hash[:aminoacid_sequence] = nil
  # ======================================================================= #
  # === :show_rna_or_dna
  #
  # This variable keeps track as to whether we will show a DNA sequence
  # or a RNA sequence. This functionality exists mostly due to
  # convenience.
  # ======================================================================= #
  @internal_hash[:show_rna_or_dna] = :dna
  # ======================================================================= #
  # === :show_a_possible_sequence
  # ======================================================================= #
  @internal_hash[:show_a_possible_sequence] = true
  # ======================================================================= #
  # === @left_pad
  # ======================================================================= #
  @left_pad = ' '
  set_show_the_rna_sequence(:no)
end

#reset_the_classObject

#

reset_the_class

#


221
222
223
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 221

def reset_the_class
  @internal_hash[:array_all_discovered_codons] = [] # Reset it to empty again.
end

#runObject

#

run (run tag)

#


443
444
445
446
447
448
449
450
451
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 443

def run
  reset_the_class
  determine_the_aminoacid_sequence
  set_array_all_discovered_codons(
    map_each_aminoacid_to_an_array_of_corresponding_codons
  )
  menu
  report
end

#set_aminoacid_sequence(i = :default) ⇒ Object

#

set_aminoacid_sequence

#


161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 161

def set_aminoacid_sequence(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    i = DEFAULT_SEQUENCE
  end if i.is_a? Symbol
  if i.is_a? Array
    i = i.join(' ').strip
  end
  i = i.to_s.dup # Have a String past this point.
  if i.empty?
    i = DEFAULT_SEQUENCE
  end
  i.tr!('?','-') if i.include? '?'
  # ======================================================================= #
  # Handle input that has no '-'.
  # ======================================================================= #
  if i.include?('-') and !i[0,3].include?('-')
    # ===================================================================== #
    # Assume input such as: "ARG-ALA-SER-LEU" here.
    # ===================================================================== #
    splitted = i.split('-')
    splitted.map! {|entry|
      three_aminoacid_letter_code_to_one_aminoacid_letter_code(entry.capitalize) # Added .capitalize as of 25.09.2019.
    }
    i = splitted.join
  end
  # ======================================================================= #
  # Finally assign it to the main variable:
  # ======================================================================= #
  @internal_hash[:aminoacid_sequence] = i
end

#set_array_all_discovered_codons(i) ⇒ Object

#

set_array_all_discovered_codons

#


309
310
311
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 309

def set_array_all_discovered_codons(i)
  @internal_hash[:array_all_discovered_codons] = i
end

#set_format_how(format_how = :default) ⇒ Object

#

set_format_how

#


100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 100

def set_format_how(
    format_how = :default
  )
  case format_how
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    format_how = :dna
  end
  @internal_hash[:show_rna_or_dna] = format_how
end

#set_show_the_rna_sequence(i = :rna) ⇒ Object

#

set_show_the_rna_sequence

#


123
124
125
126
127
128
129
130
131
132
133
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 123

def set_show_the_rna_sequence(
    i = :rna
  )
  case i
  when :yes
    i = :rna
  when :no
    i = :dna
  end
  @internal_hash[:show_rna_or_dna] = i
end

#show_a_possible_sequence?Boolean

#

show_a_possible_sequence?

#

Returns:

  • (Boolean)


116
117
118
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 116

def show_a_possible_sequence?
  @internal_hash[:show_a_possible_sequence]
end

#show_all_possible_codons(n_aminoacids = n_aminoacids?, , codons_to_use = all_codons? ) ⇒ Object

#

show_all_possible_codons

#


391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 391

def show_all_possible_codons(
    n_aminoacids  = n_aminoacids?,
    codons_to_use = all_codons?
  )
  display_separator(n_aminoacids)
  n_aminoacids.times {|index|
    array = codons_to_use.map {|entry| entry[index] }
    unless array.all? {|entry| entry.nil? }
      # =================================================================== #
      # This array may contain some nil values. We will
      # replace all these nil values via '   ' strings.
      # =================================================================== #
      array.map! {|entry|
        entry = ' ' * 3 if entry.nil?
        entry
      }
      if show_the_rna_sequence?
        array.map! {|entry| entry.tr('T','U') }
      end
      e @left_pad+rev+
        array.map {|entry|
          entry.to_s.ljust(3)
        }.join(
          swarn(" #{VERTICAL_UNICODE_BAR} ")+rev
        )
    end
  }
  display_separator(n_aminoacids)
  e # And a newline for prettier output. \o/
end

#show_helpObject

#

show_help (help tag)

#


346
347
348
349
350
351
352
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 346

def show_help
  e 'The following help options are available for this class:'
  e
  ecomment '  --RNA  # show the codon table in RNA rather than DNA'
  ecomment '  --full # show all possible codons'
  e
end

#show_the_aminoacid_sequence_in_steelblue_and_orange_colour(i = aminoacid_sequence? ) ⇒ Object

#

show_the_aminoacid_sequence_in_steelblue_and_orange_colour

#


291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 291

def show_the_aminoacid_sequence_in_steelblue_and_orange_colour(
    i = aminoacid_sequence?
  )
  i = i.join(' ').strip if i.is_a? Array
  i = i.delete('-')
  splitted = i.split(//)
  mapped = splitted.map {|entry|
    steelblue(entry)
  }
  joined = mapped[0 .. -2].join(orange(' --- '))+
           orange(' --- ')+
           steelblue(splitted.last)
  e @left_pad+joined
end

#show_the_headerObject Also known as: show_header

#

show_the_header

#


210
211
212
213
214
215
216
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 210

def show_the_header
  e
  erev 'This amino acid sequence ('+sfancy(n_aminoacids?.to_s)+rev+
       ' aminoacids) has the following possible'
  erev 'codons:'
  e
end

#show_the_rna_sequence?Boolean

#

show_the_rna_sequence?

#

Returns:

  • (Boolean)


138
139
140
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 138

def show_the_rna_sequence?
  @internal_hash[:show_rna_or_dna] == :rna
end