Class: Bioroebe::ConvertAminoacidToDNA

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/conversions/convert_aminoacid_to_dna.rb

Overview

Bioroebe::ConvertAminoacidToDNA

Constant Summary collapse

DEFAULT_SEQUENCE =
#

DEFAULT_SEQUENCE

This denotes the aminoacid that we will use as default. The various ‘-’ tokens are optional.

#
'M-T-T-Y-STOP'
SHALL_WE_DEBUG =
#

SHALL_WE_DEBUG

If this constant is true, then we will show a lot more extra information. This can aid in debugging this class.

#
false

Constants inherited from CommandlineApplication

Bioroebe::CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

Bioroebe::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(aminoacid_sequence = DEFAULT_SEQUENCE, run_already = true) ⇒ ConvertAminoacidToDNA

#

initialize

Input should be the aminoacid sequence.

#


43
44
45
46
47
48
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
75
76
77
78
79
80
81
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 43

def initialize(
    aminoacid_sequence = DEFAULT_SEQUENCE,
    run_already        = true
  )
  reset
  case run_already
  # ======================================================================= #
  # === :be_quiet
  # ======================================================================= #
  when :be_quiet,
       :quiet
    set_be_quiet
    run_already = true # Restore the default.
  # ======================================================================= #
  # === :do_debug
  # ======================================================================= #
  when :do_debug,
       :debug
    @debug = SHALL_WE_DEBUG
    run_already = true
  end
  set_aminoacid_sequence(
    aminoacid_sequence
  )
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    case yield
    # ===================================================================== #
    # === :be_quiet
    # ===================================================================== #
    when :be_quiet,
         :quiet
      set_be_quiet
    end
  end
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Bioroebe::ConvertAminoacidToDNA[]

#


274
275
276
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 274

def self.[](i = ARGV)
  new(i) { :be_quiet }
end

Instance Method Details

#dna_sequence?Boolean

#

dna_sequence?

This method will return the DNA string.

#

Returns:

  • (Boolean)


215
216
217
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 215

def dna_sequence?
  @array_with_the_results.join('-').tr('U','T')
end

#find_possible_nucleotide_matches_for_this_codon(we_seek_this_codon, special_instruction = nil) ⇒ Object

#

find_possible_nucleotide_matches_for_this_codon

If the second argument is :return_only_one_random_codon then we will simply randomly return one possible codon each.

The codon “STOP” is treated in a special manner.

#


176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 176

def find_possible_nucleotide_matches_for_this_codon(
    we_seek_this_codon,
    special_instruction = nil
  )
  case we_seek_this_codon
  when 'STOP'
    we_seek_this_codon = '*'
  end
  array_with_our_codons = hash_codon_to_aminoacid?.select {|_key, value|
    value == we_seek_this_codon
  }
  array_with_our_codons = array_with_our_codons.keys.flatten # This Array holds our possible codons now.
  if special_instruction == :return_only_one_random_codon
    if is_first_codon? and we_seek_this_codon == @start_codon_to_use
      array_with_our_codons.select! {|entry| entry == 'START' }
    else
      array_with_our_codons = array_with_our_codons.sample
    end
  end
  return array_with_our_codons
end

#hash_codon_to_aminoacid?Boolean

#

hash_codon_to_aminoacid?

Convert from a given codon to the respective aminoacid at hand.

We will make this dynamically, via a method call, which allows us to always obtain the most-up-to-date information.

#

Returns:

  • (Boolean)


164
165
166
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 164

def hash_codon_to_aminoacid?
  ::Bioroebe.codon_table_dataset?
end

#is_first_codon?Boolean

#

is_first_codon?

#

Returns:

  • (Boolean)


136
137
138
139
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 136

def is_first_codon?
  return true if @array_with_the_results.empty?
  false
end

#report_resultObject Also known as: report, display_sequence

#

report_result (report tag)

#


222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 222

def report_result
  _ = dna_sequence?
  if be_verbose?
    e
    erev 'The aminoacid sequence '+sfancy(input_sequence?)+rev+
         ' ('+orange(input_sequence?.chars.size.to_s+' aminoacids')+rev+
         ') translates'
    erev 'into this most likely mRNA sequence:'
    e
    e "  #{sfancy(to_rna(_))}" # report the results, also "pad" it with newlines.
    e
  end
end

#resetObject

#

reset

#


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 86

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @start_codon_to_use
  # ======================================================================= #
  @start_codon_to_use = ::Bioroebe.start_codon?
  # ======================================================================= #
  # === @debug
  # ======================================================================= #
  @debug = SHALL_WE_DEBUG
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose = true
  # ======================================================================= #
  # === @use_shortcuts_for_purines_and_pyrimidines
  # ======================================================================= #
  @use_shortcuts_for_purines_and_pyrimidines = false
end

#return_codons(i) ⇒ Object

#

return_codons

The input may be like “M-Y-T-N-R-S-S-R-STOP” or “MYTNRSSR*”.

We have to remain flexible here.

#


148
149
150
151
152
153
154
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 148

def return_codons(i)
  if i.include? '-'
    i.split('-') # Split on '-'.
  else
    i.scan(/./)
  end
end

#runObject

#

run

#


247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 247

def run
  @array_with_the_results = []
  array = return_codons(seq?)
  # ======================================================================= #
  # Next, check if we have a three-letter code. If so then we must
  # convert it first.
  # ======================================================================= #
  if array and array.first and (array.first.size > 1)
    array = ::Bioroebe.three_to_one(array)
    if array.is_a? String
      array = array.split(//)
    end
  end
  array.each {|codon|
    possible_matches = find_possible_nucleotide_matches_for_this_codon(codon, :return_only_one_random_codon)
    if use_shortcuts_for_purines_and_pyrimidines?
      possible_matches = Bioroebe::DetectMinimalCodon[possible_matches].first
    end
    @array_with_the_results << 
      possible_matches
  }
  report_result
end

#set_aminoacid_sequence(i = DEFAULT_SEQUENCE) ⇒ Object Also known as: set_sequence

#

set_aminoacid_sequence

Keep in mind that our aminoacid sequence can also include ‘-’ characters.

#


119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 119

def set_aminoacid_sequence(
    i = DEFAULT_SEQUENCE
  )
  i = i.join if i.is_a? Array
  case i
  when nil
    i = DEFAULT_SEQUENCE
  end
  if @debug
    opnerev "We will work on the aminoacid sequence: `#{sfancy(i)}`"
  end
  @aminoacid_sequence = i
end

#to_strObject

#

to_str

#


240
241
242
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 240

def to_str
  to_rna(dna_sequence?)
end

#use_shortcuts_for_purines_and_pyrimidines?Boolean

#

use_shortcuts_for_purines_and_pyrimidines?

#

Returns:

  • (Boolean)


110
111
112
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 110

def use_shortcuts_for_purines_and_pyrimidines?
  @use_shortcuts_for_purines_and_pyrimidines
end