Class: Bioroebe::DetectMinimalCodon

Inherits:
Base
  • Object
show all
Defined in:
lib/bioroebe/codons/detect_minimal_codon.rb

Overview

Bioroebe::DetectMinimalCodon

Constant Summary collapse

DEFAULT_ARRAY =
#

DEFAULT_ARRAY

You can switch here between different variants.

#

DEFAULT_ARRAY = %w( TTT TTC )

%w( GGT GGC GGA GGG )

Constants inherited from Base

Base::NAMESPACE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Class Method Summary collapse

Instance Method Summary collapse

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

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?

Constructor Details

#initialize(i = nil, run_already = true) ⇒ DetectMinimalCodon

#

initialize

The first argument is the codons that you wish to match to.

#

50
51
52
53
54
55
56
57
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 50

def initialize(
    i           = nil, # This should be an Array.
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Bioroebe::DetectMinimalCodon[]

This variant will just return the result

Usage example:

Bioroebe::DetectMinimalCodon[%w( GGT GGC GGA GGG )] # => ["GGT", "GGC", "GGA", "GGG"]
Bioroebe::DetectMinimalCodon[["TTT", "TTC"]]        # => ["TTY"]
#

168
169
170
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 168

def self.[](i = '')
  new(i).result?.uniq
end

Instance Method Details

#all_purines?(i) ⇒ Boolean

#

all_purines

Will return true if the given input has only purines.

#

Returns:

  • (Boolean)

96
97
98
99
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 96

def all_purines?(i)
  i = i.chars if i.is_a? String
  i.all? {|entry| entry == 'A' or entry == 'G' }
end

#all_pyrimidines?(i) ⇒ Boolean

#

all_pyrimidines?

Will return true if the given input has only pyrimidines.

#

Returns:

  • (Boolean)

106
107
108
109
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 106

def all_pyrimidines?(i)
  i = i.chars if i.is_a? String
  i.all? {|entry| entry == 'T' or entry == 'C' }
end

#compare_and_change_last_tokens(i = input?) ) ⇒ Object

#

compare_and_change_last_tokens

This method can rewrite given input too.

#

71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 71

def compare_and_change_last_tokens(i = input?)
  i = i.map {|entry| entry.dup }
  array_last = i.map {|entry| entry[-1,1] }
  if all_purines? array_last
    _ = i.map {|entry| entry[-1,1] = 'R'; entry }
    set_result(_.uniq)
  end
  if all_pyrimidines? array_last
    _ = i.map {|entry| entry[-1,1] = 'Y'; entry }
    set_result(_.uniq)
  end
end

#input?Boolean

#

input?

#

Returns:

  • (Boolean)

124
125
126
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 124

def input?
  @input
end

#report_resultObject Also known as: report

#

report_result

#

138
139
140
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 138

def report_result
  pp @result
end

#resetObject

#

reset (reset tag)

#

62
63
64
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 62

def reset
  super()
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)

145
146
147
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 145

def result?
  @result
end

#runObject

#

run (run tag)

#

152
153
154
155
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 152

def run
  sync_input_to_result
  compare_and_change_last_tokens
end

#set_input(i = DEFAULT_ARRAY) ⇒ Object

#

set_input

#

114
115
116
117
118
119
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 114

def set_input(i = DEFAULT_ARRAY)
  i = DEFAULT_ARRAY if i.nil?
  i = DEFAULT_ARRAY if i.empty?
  i = [i] unless i.is_a? Array
  @input = i
end

#set_result(i) ⇒ Object

#

set_result

#

87
88
89
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 87

def set_result(i)
  @result = i
end

#sync_input_to_resultObject

#

sync_input_to_result

#

131
132
133
# File 'lib/bioroebe/codons/detect_minimal_codon.rb', line 131

def sync_input_to_result
  set_result(input?)
end