Class: Bioroebe::ConvertAminoacidToDNA

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

Overview

Bioroebe::ConvertAminoacidToDNA

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

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

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

#

initialize

Input should be the aminoacid sequence.

#

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
82
83
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 45

def initialize(
    aminoacid_sequence = DEFAULT_SEQUENCE,
    run_already        = true
  )
  reset
  case run_already
  # ======================================================================= #
  # === :be_quiet
  # ======================================================================= #
  when :be_quiet,
       :quiet
    @be_verbose = false
    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
      @be_verbose = false
    end
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Bioroebe::ConvertAminoacidToDNA[]

#

279
280
281
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 279

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

Instance Method Details

#dna_sequence?Boolean

#

dna_sequence?

This method will return the DNA string.

#

Returns:

  • (Boolean)

220
221
222
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 220

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.

#

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 181

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)

169
170
171
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 169

def hash_codon_to_aminoacid?
  ::Bioroebe.codon_table_dataset?
end

#is_first_codon?Boolean

#

is_first_codon?

#

Returns:

  • (Boolean)

141
142
143
144
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 141

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)

#

227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 227

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

#

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

def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = 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.

#

153
154
155
156
157
158
159
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 153

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

#runObject

#

run

#

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 252

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.

#

124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 124

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
    opnn; erev "We will work on the aminoacid sequence: `#{sfancy(i)}`"
  end
  @aminoacid_sequence = i
end

#to_strObject

#

to_str

#

245
246
247
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 245

def to_str
  to_rna(dna_sequence?)
end

#use_shortcuts_for_purines_and_pyrimidines?Boolean

#

use_shortcuts_for_purines_and_pyrimidines?

#

Returns:

  • (Boolean)

115
116
117
# File 'lib/bioroebe/conversions/convert_aminoacid_to_dna.rb', line 115

def use_shortcuts_for_purines_and_pyrimidines?
  @use_shortcuts_for_purines_and_pyrimidines
end