Class: Bioroebe::ColourSchemeDemo

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

Constant Summary collapse

TITLE =
#

TITLE

#
'Bioroebe::ColourScheme for DNA sequences'
CDIV =
#

CDIV

#
'</div>'
BODY_TAG =
#

BODY_TAG

#
'<body style="font-size:1.5em">'
MAXIMAL_N_NUCLEOTIDES_PER_ROW =
#

MAXIMAL_N_NUCLEOTIDES_PER_ROW

#
80
DEFAULT_FASTA_FILE_NAME =
#

DEFAULT_FASTA_FILE_NAME

#
'tardigrada_fasta.ffn'

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, #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 included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(nucleotide_sequence, aminoacid_sequence = nil) ⇒ ColourSchemeDemo

#

initialize

First argument should be the nucleotide sequence.

Second argument should be the aminoacid sequence. But it can be omitted - in that case, we will deduce the aminoacid sequence from the nucleotide sequence.

#


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 81

def initialize(
    nucleotide_sequence,
    aminoacid_sequence = nil
  )
  reset
  case aminoacid_sequence
  when :be_quiet
    aminoacid_sequence = nil
    @be_verbose = false
  end
  # ======================================================================= #
  # === Handle the case when the user did not input an aminoacid sequence
  # ======================================================================= #
  if aminoacid_sequence.nil?
    if nucleotide_sequence.respond_to? :translate
      aminoacid_sequence = nucleotide_sequence.translate # Aminoacid sequence.
    elsif nucleotide_sequence.is_a? String
      aminoacid_sequence = ::Bioroebe::DnaToAminoacidSequence.new(
        nucleotide_sequence, :return_silently
      )
    end
  end
  _ = ['<html>',
       '<header>', '<title>', TITLE, '</title>', '</header>',
       BODY_TAG,  '<h1>', TITLE, '</h1>']
  _ << ['<div>', '<h2>', 'Simple colors', '</h2>']
  %w( Nucleotide ).each { |scheme|
    _ << display_scheme(scheme, nucleotide_sequence, '')
  }
  _ << [CDIV]
  %w( Zappo Taylor ).each { |scheme|
    _ << display_scheme(scheme, '', aminoacid_sequence)
  }
  _ << [CDIV]
  _ << ['<div>', '<h2>', 'Score colors', '</h2>']
  %w( Buried Helix Hydropathy Strand Turn ).each { |score|
    _ << display_scheme(score, "", aminoacid_sequence)
  }
  _ << [CDIV]+['</body>','</html>']
  @result = _
  report_result if @be_verbose
end

Class Method Details

.create_demo_file(at_this_location = "#{log_dir?}#{DEFAULT_FASTA_FILE_NAME}") ⇒ Object

#

Bioroebe::ColourSchemeDemo.create_demo_file

The following class method can be used to create a demo file.

It assumes that a fasta file will exist at the base directory.

#


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 222

def self.create_demo_file(
    at_this_location = "#{log_dir?}#{DEFAULT_FASTA_FILE_NAME}"
  )
  # ======================================================================= #
  # === We must first check whether the file in question exists
  # ======================================================================= #
  if File.exist? at_this_location
    sequence = ::Bioroebe.parse_fasta_file(at_this_location).sequence?
    what = self.new(sequence, :be_quiet).result?
    into = '/Depot/j/colourized_sequence.html'
    write_what_into(what, into)
    return into
  else
    puts 'No file could be found at `'+
          ::Colours.sfile(at_this_location)+rev+'`.'
    return nil
  end
end

.revObject

#

Bioroebe::ColourSchemeDemo.rev

#


244
245
246
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 244

def self.rev
  ::Bioroebe.rev
end

Instance Method Details

#br(i, width = MAXIMAL_N_NUCLEOTIDES_PER_ROW) ⇒ Object

#

br

Returns folded sequence with
HTML tag.

The second argument keeps track when to add a
tag and a newline.

#


142
143
144
145
146
147
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 142

def br(
    i, width = MAXIMAL_N_NUCLEOTIDES_PER_ROW
  )
  return "<br\n>" if i % width == 0
  return '' # Else return an empty string.
end

#display(sequence, cs) ⇒ Object

#

display

This method will return the sequence html doc, which equates to a <p> tag in HTML.

#


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 180

def display(sequence, cs)
  # ======================================================================= #
  # Open the <p> tag first:
  # ======================================================================= #
  html = '<p style="font-family: monospace; padding-left: 1.25em;">'.dup
  close_span_tag = '</span>'
  index = 0 # Index.
  if sequence.is_a? ::Bioroebe::DnaToAminoacidSequence
    sequence = sequence.sequence? # We need the String here.
  end
  sequence.each_byte {|char|
    colour = cs[char.chr]
    open_span_tag = '<span style="background:#'+colour+';">'
    html << open_span_tag+char.chr.to_s+close_span_tag
    html << br(index += 1) # Increment the index too.
  }
  html+'</p>'
end

#display_scheme(scheme, nucleotide_sequence, aminoacid_sequence) ⇒ Object

#

display_scheme

This method will properly show the sequence. It will use a <div> tag for this.

Returns scheme wise html doc.

#


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 157

def display_scheme(
    scheme,
    nucleotide_sequence,
    aminoacid_sequence
  )
  html = ''.dup
  # ======================================================================= #
  # === Obtain the relevant constant next
  # ======================================================================= #
  constant = ::Bioroebe::ColourScheme.const_get(scheme)
  [ nucleotide_sequence, aminoacid_sequence ].each { |sequence|
    html << display(sequence, constant)
  }
  result = ['<div>', "<h3>#{constant}</h3>", html, CDIV]
  return result
end

#report_resultObject

#

report_result

#


211
212
213
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 211

def report_result
  e result? # Call it by default.
end

#resetObject

#

reset

#


127
128
129
130
131
132
133
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 127

def reset
  super()
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose = true
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)


202
203
204
205
206
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 202

def result?
  _ = @result
  _ = _.join("\n") if _.is_a? Array
  return _
end