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, #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(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[]

#

430
431
432
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 430

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)

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

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.

#

409
410
411
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 409

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)

239
240
241
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 239

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

#

161
162
163
164
165
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 161

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)

#

320
321
322
323
324
325
326
327
328
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 320

def display_separator(
    n_aminoacids = n_aminoacids?
  )
  e swarn(
    (
      (('-' * 4) * n_aminoacids.size)+'----'
    ).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.

#

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 290

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)

280
281
282
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 280

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

#

392
393
394
395
396
397
398
399
400
401
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 392

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)

#

358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 358

def menu(
    i = return_commandline_arguments_starting_with_hyphens
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === --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)

212
213
214
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 212

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

#report(array_containing_all_discovered_codons = array_all_discovered_codons? ) ⇒ Object

#

report (report tag)

#

377
378
379
380
381
382
383
384
385
386
387
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 377

def report(
    array_containing_all_discovered_codons =
      array_all_discovered_codons?
  )
  show_the_header
  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
  # ======================================================================= #
  # === @internal_hash
  # ======================================================================= #
  @internal_hash = {}
  # ======================================================================= #
  # === :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
  set_show_the_rna_sequence(:no)
end

#reset_the_classObject

#

reset_the_class

#

232
233
234
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 232

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

#runObject

#

run (run tag)

#

417
418
419
420
421
422
423
424
425
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 417

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

#

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
197
198
199
200
201
202
203
204
205
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 170

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

#

351
352
353
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 351

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

#

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

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 rev+
        array.map {|entry| entry.to_s.ljust(3) }.
             join(swarn(' | ')+rev)+
        swarn(' |')
    end
  }
  display_separator(n_aminoacids)
  e # And a newline for prettier output. \o/
end

#show_the_aminoacid_sequence_in_steelblue_and_orange_colour(i = aminoacid_sequence? ) ⇒ Object

#

show_the_aminoacid_sequence_in_steelblue_and_orange_colour

#

333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 333

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 joined
end

#show_the_headerObject Also known as: show_header

#

show_the_header

#

219
220
221
222
223
224
225
226
227
# File 'lib/bioroebe/aminoacids/deduce_aminoacid_sequence.rb', line 219

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