Class: Bioroebe::ColourizeSequence

Inherits:
Base
  • Object
show all
Defined in:
lib/bioroebe/colours/colourize_sequence.rb

Overview

Bioroebe::ColourizeSequence

Constant Summary collapse

DEFAULT_NUCLEOTIDE_SEQUENCE =
#

DEFAULT_NUCLEOTIDE_SEQUENCE

#
'ATGCGCGGACCAGCAGTCACGACTACGTACGTCAGATCGACTGCTAGCTAGTCAGTCAGTCAGTACGATC'\
'GGCGAGCGACTGGCGAGGGTAGTAGATAGAATAGATGTAGCTGCTAGCTAGTCAGTCAGTCAGTACGATT'

Constants inherited from Base

Base::NAMESPACE

Constants included from ColoursForBase

Bioroebe::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?, #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 BaseModule

#absolute_path, #default_file_read, #file_readlines

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from ColoursForBase

#colourize_this_aminoacid_sequence_for_the_commandline, #colourize_this_nucleotide_sequence, #disable_colours, #ecomment, #efancy, #egold, #enable_colours, #eorange, #eparse, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #sdir, #set_will_we_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(i = DEFAULT_NUCLEOTIDE_SEQUENCE, run_already = true) ⇒ ColourizeSequence

#

initialize

#


37
38
39
40
41
42
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
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 37

def initialize(
    i           = DEFAULT_NUCLEOTIDE_SEQUENCE,
    run_already = true
  )
  reset
  set_sequence(i)
  # === Handle blocks next
  if block_given?
    yielded = yield
    case yielded
    when :start_and_stop_codon
      # =================================================================== #
      # Denote which colour to use for the start-codon:
      # =================================================================== #
      @colourize_start_codon_in_this_colour = :turquoise
      # =================================================================== #
      # Denote which colour to use for the stop-codons:
      # =================================================================== #
      @colourize_stop_codon_in_this_colour  = :orange
    else
      if yielded.is_a? Hash
        # ================================================================= #
        # === :colour_for_the_startcodon
        # ================================================================= #
        if yielded.has_key? :colour_for_the_startcodon
          set_colourize_start_codon_in_this_colour(
            yielded.delete(:colour_for_the_startcodon)
          )
        end
      end
    end
  end
  case run_already
  # === :do_not_run_yet
  when :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Bioroebe::ColourizeSequence[]

#


253
254
255
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 253

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

.return_sequence(i) ⇒ Object

#

Bioroebe::ColourizeSequence.return_sequence

This method can be used to simply return the colourized string rather than display it.

#


241
242
243
244
245
246
247
248
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 241

def self.return_sequence(i)
  yielded = yield
  _ = self.new(i, :do_not_run_yet) { yielded }
  _.do_not_show_the_main_sequence
  _.run
  colourized_sequence = _.sequence?
  return colourized_sequence
end

Instance Method Details

#colourize_this_sequence_in_that_colour(sequence, string_to_be_colourized = 'TAA', use_this_colour = @colourize_stop_codon_in_this_colour) ⇒ Object

#

colourize_this_sequence_in_that_colour

#


206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 206

def colourize_this_sequence_in_that_colour(
    sequence,
    string_to_be_colourized = 'TAA',
    use_this_colour         = @colourize_stop_codon_in_this_colour
  )
  if sequence.include? string_to_be_colourized.to_s
    sequence.gsub!(/#{string_to_be_colourized}/,
      Colours.send(use_this_colour, string_to_be_colourized)+
      rev_for_coding_sequence
    )
  end
end

#do_not_show_the_main_sequenceObject

#

do_not_show_the_main_sequence

#


119
120
121
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 119

def do_not_show_the_main_sequence
  @show_sequence = false
end

#erev(i) ⇒ Object

#

erev

#


222
223
224
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 222

def erev(i)
  ::Bioroebe.erev(i)
end

#modify_sequenceObject

#

modify_sequence

Before this method is called, the class checks whether colours are used at all.

#


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 136

def modify_sequence
  _ = sequence?
  # ======================================================================= #
  # === Start codon first
  # ======================================================================= #
  if @colourize_start_codon_in_this_colour
    colourize_this_sequence_in_that_colour(
      _, @use_this_start_codon, @colourize_start_codon_in_this_colour
    )
  end
  # ======================================================================= #
  # === Stop codons next
  # ======================================================================= #
  if @colourize_stop_codon_in_this_colour
    colourize_this_sequence_in_that_colour(_, 'TAG', @colourize_stop_codon_in_this_colour)
    colourize_this_sequence_in_that_colour(_, 'TGA', @colourize_stop_codon_in_this_colour)
    colourize_this_sequence_in_that_colour(_, 'TAA', @colourize_stop_codon_in_this_colour)
  end
end

#resetObject

#

reset (reset tag)

#


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 80

def reset
  super()
  # ======================================================================= #
  # === @use_colours
  # ======================================================================= #
  @use_colours = true
  # ======================================================================= #
  # === @colourize_start_codon_in_this_colour
  # ======================================================================= #
  @colourize_start_codon_in_this_colour = nil
  # ======================================================================= #
  # === @colourize_stop_codon_in_this_colour
  # ======================================================================= #
  @colourize_stop_codon_in_this_colour  = nil
  # ======================================================================= #
  # === @show_sequence
  # ======================================================================= #
  @show_sequence                        = true
  # ======================================================================= #
  # === @use_this_start_codon
  # ======================================================================= #
  @use_this_start_codon                 = 'ATG'
end

#rev_for_coding_sequenceObject Also known as: rev

#

rev_for_coding_sequence

#


195
196
197
198
199
200
201
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 195

def rev_for_coding_sequence
  ::Bioroebe.rev
  # The old code was:
  #   use_this_colour = ::Bioroebe::ShowNucleotideSequence::USE_THIS_COLOUR
  #   ::Colours.send(use_this_colour, '')
  # But that does not appar to work as desired.
end

#runObject

#

run (run tag)

#


229
230
231
232
233
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 229

def run
  modify_sequence if @use_colours
  show_sequence if @show_sequence
  show_explanation
end

#sequence?Boolean Also known as: input?

#

sequence?

#

Returns:

  • (Boolean)


126
127
128
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 126

def sequence?
  @sequence
end

#set_colourize_start_codon_in_this_colour(i) ⇒ Object

#

set_colourize_start_codon_in_this_colour

#


166
167
168
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 166

def set_colourize_start_codon_in_this_colour(i)
  @colourize_start_codon_in_this_colour = i
end

#set_sequence(i = DEFAULT_NUCLEOTIDE_SEQUENCE) ⇒ Object

#

set_sequence

#


107
108
109
110
111
112
113
114
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 107

def set_sequence(
    i = DEFAULT_NUCLEOTIDE_SEQUENCE
  )
  i = i.first if i.is_a? Array
  i = DEFAULT_NUCLEOTIDE_SEQUENCE if i.nil?
  i = i.to_s.dup
  @sequence = i
end

#show_explanationObject

#

show_explanation

#


173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 173

def show_explanation
  if @colourize_start_codon_in_this_colour
    e
    erev '  Start codon: '+Colours.send(
        @colourize_start_codon_in_this_colour,
        @use_this_start_codon
      )+
      rev
    e
  end
  if @colourize_stop_codon_in_this_colour
    erev '  Stop codons: '+Colours.send(
        @colourize_stop_codon_in_this_colour,
        'TAG, TGA, TAA'
      )+rev
    e
  end
end

#show_sequenceObject

#

show_sequence

#


159
160
161
# File 'lib/bioroebe/colours/colourize_sequence.rb', line 159

def show_sequence
  erev "#{@sequence}#{rev_for_coding_sequence}"
end