Class: Bioroebe::ColourSchemeDemo
- 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
Constants included from ColoursForBase
Bioroebe::ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Class Method Summary collapse
-
.create_demo_file(at_this_location = "#{log_dir?}#{DEFAULT_FASTA_FILE_NAME}") ⇒ Object
# === Bioroebe::ColourSchemeDemo.create_demo_file.
-
.rev ⇒ Object
# === Bioroebe::ColourSchemeDemo.rev ========================================================================= #.
Instance Method Summary collapse
-
#br(i, width = MAXIMAL_N_NUCLEOTIDES_PER_ROW) ⇒ Object
# === br.
-
#display(sequence, cs) ⇒ Object
# === display.
-
#display_scheme(scheme, nucleotide_sequence, aminoacid_sequence) ⇒ Object
# === display_scheme.
-
#initialize(nucleotide_sequence, aminoacid_sequence = nil) ⇒ ColourSchemeDemo
constructor
# === initialize.
-
#report_result ⇒ Object
# === report_result ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#result? ⇒ Boolean
# === result? ========================================================================= #.
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(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.
#
80 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 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 80 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.
#
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 221 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 |
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.
#
141 142 143 144 145 146 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 141 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.
#
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 179 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.
#
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 156 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_result ⇒ Object
#
report_result
#
210 211 212 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 210 def report_result e result? # Call it by default. end |
#reset ⇒ Object
#
reset
#
126 127 128 129 130 131 132 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 126 def reset super() # ======================================================================= # # === @be_verbose # ======================================================================= # @be_verbose = true end |
#result? ⇒ Boolean
#
result?
#
201 202 203 204 205 |
# File 'lib/bioroebe/colours/colour_schemes/colour_scheme_demo.rb', line 201 def result? _ = @result _ = _.join("\n") if _.is_a? Array return _ end |