Class | Bio::Shell::ColoredCodonTable
In: | lib/bio/shell/plugin/codon.rb
Parent: | Object

### Methods

generate_colored_text generate_mono_text new output setup_colors

### Attributes

table | [R] |

### Public Class methods

new(number, cuhash = nil)

[Source]

        # File lib/bio/shell/plugin/codon.rb, line 23
    23:     def initialize(number, cuhash = nil)
    24:       @aacode = Bio::AminoAcid.names
    25:       @table  = Bio::CodonTable[number]
    26:       @number = number
    27:       @cuhash = cuhash
    28:       setup_colors
    29:       if Bio::Shell.config[:color]
    30:         generate_colored_text
    31:       else
    32:         generate_mono_text
    33:       end
    34:     end

### Public Instance methods

generate_colored_text()

[Source]

         # File lib/bio/shell/plugin/codon.rb, line 76
     76:     def generate_colored_text
     77:       @table.each do |codon, aa|
     78:         property, = @@properties.detect {|key, list| list.include?(aa)}
     79:
     80:         if aa == '*'
     81:           if @cuhash
     82:             color_code = "#{@colors[:stop]}STOP"
     83:             color_aa = "#{@colors[:stop]}#{aa}"
     84:           else
     85:             color_code = "#{@colors[:stop]}STP"
     86:             case codon
     87:             when 'tga'
     88:               color_aa = "#{@colors[:text]}U"
     89:             when 'tag'
     90:               color_aa = "#{@colors[:text]}O"
     91:             else
     92:               color_aa = "#{@colors[:text]}*"
     93:             end
     94:           end
     95:         else
     96:           color_code = "#{@colors[property]}#{@aacode[aa]}"
     97:           if @table.start_codon?(codon)
     98:             if @cuhash
     99:               color_aa = "#{@colors[:aa]}#{aa}"
    100:             else
    101:               color_aa = "#{@colors[:start]}#{aa}"
    102:             end
    103:           else
    104:             if @cuhash
    105:               color_aa = "#{@colors[property]}#{aa}"
    106:             else
    107:               color_aa = "#{@colors[:aa]}#{aa}"
    108:             end
    109:           end
    110:         end
    111:
    112:         if @cuhash
    113:           percent = @cuhash[codon].to_s.rjust(6)
    114:           eval("@#{codon} = '#{color_aa}#{@colors[:text]}#{percent}'")
    115:         else
    116:           eval("@#{codon} = ' #{color_code} #{color_aa}#{@colors[:text]} '")
    117:         end
    118:       end
    119:
    120:       @hydrophilic = [
    121:         "#{@colors[:basic]}basic#{@colors[:text]},",
    122:         "#{@colors[:polar]}polar#{@colors[:text]},",
    123:         "#{@colors[:acidic]}acidic#{@colors[:text]}"
    124:       ].join(" ")
    125:       @hydrophobic = "#{@colors[:nonpolar]}nonpolar"
    126:     end

generate_mono_text()

[Source]

        # File lib/bio/shell/plugin/codon.rb, line 52
    52:     def generate_mono_text
    53:       @table.each do |codon, aa|
    54:         if aa == '*'
    55:           code = 'STOP'
    56:           aa = '' unless @cuhash
    57:         else
    58:           code = @aacode[aa]
    59:         end
    60:         if @cuhash
    61:           percent = @cuhash[codon].to_s.rjust(6)
    62:           eval("@#{codon} = '#{aa}#{percent}'")
    63:         else
    64:           eval("@#{codon} = ' #{code} #{aa} '")
    65:         end
    66:       end
    67:
    68:       @hydrophilic = [
    69:         @@properties[:basic].join(" "), "(basic),",
    70:         @@properties[:polar].join(" "), "(polar),",
    71:         @@properties[:acidic].join(" "), "(acidic)",
    72:       ].join(" ")
    73:       @hydrophobic = @@properties[:nonpolar].join(" ") + " (nonpolar)"
    74:     end

output()

[Source]

         # File lib/bio/shell/plugin/codon.rb, line 128
    128:     def output
    129:       header = "#\n# = Codon table \#{@number} : \#{@table.definition}\n#\n#   hydrophilic: \#{@hydrophilic}\n#   hydrophobic: \#{@hydrophobic}\n"
    130:       table = "#\n# *---------------------------------------------*\n# |       |              2nd              |     |\n# |  1st  |-------------------------------| 3rd |\n# |       |  U    |  C    |  A    |  G    |     |\n# |-------+-------+-------+-------+-------+-----|\n# | U   U |\#{@ttt}|\#{@tct}|\#{@tat}|\#{@tgt}|  u  |\n# | U   U |\#{@ttc}|\#{@tcc}|\#{@tac}|\#{@tgc}|  c  |\n# | U   U |\#{@tta}|\#{@tca}|\#{@taa}|\#{@tga}|  a  |\n# |  UUU  |\#{@ttg}|\#{@tcg}|\#{@tag}|\#{@tgg}|  g  |\n# |-------+-------+-------+-------+-------+-----|\n# |  CCCC |\#{@ctt}|\#{@cct}|\#{@cat}|\#{@cgt}|  u  |\n# | C     |\#{@ctc}|\#{@ccc}|\#{@cac}|\#{@cgc}|  c  |\n# | C     |\#{@cta}|\#{@cca}|\#{@caa}|\#{@cga}|  a  |\n# |  CCCC |\#{@ctg}|\#{@ccg}|\#{@cag}|\#{@cgg}|  g  |\n# |-------+-------+-------+-------+-------+-----|\n# |   A   |\#{@att}|\#{@act}|\#{@aat}|\#{@agt}|  u  |\n# |  A A  |\#{@atc}|\#{@acc}|\#{@aac}|\#{@agc}|  c  |\n# | AAAAA |\#{@ata}|\#{@aca}|\#{@aaa}|\#{@aga}|  a  |\n# | A   A |\#{@atg}|\#{@acg}|\#{@aag}|\#{@agg}|  g  |\n# |-------+-------+-------+-------+-------+-----|\n# |  GGGG |\#{@gtt}|\#{@gct}|\#{@gat}|\#{@ggt}|  u  |\n# | G     |\#{@gtc}|\#{@gcc}|\#{@gac}|\#{@ggc}|  c  |\n# | G GGG |\#{@gta}|\#{@gca}|\#{@gaa}|\#{@gga}|  a  |\n# |  GG G |\#{@gtg}|\#{@gcg}|\#{@gag}|\#{@ggg}|  g  |\n# *---------------------------------------------*\n#\n"
    131:       if @cuhash
    132:         text = table
    133:       else
    134:         text = header + table
    135:       end
    136:       if Bio::Shell.config[:color]
    137:         text.gsub(/^\s+#/, @colors[:text])
    138:       else
    139:         text.gsub(/^\s+#/, '')
    140:       end
    141:     end

setup_colors()

[Source]

        # File lib/bio/shell/plugin/codon.rb, line 37
    37:     def setup_colors
    38:       c = Bio::Shell.colors
    39:
    40:       @colors = {
    41:         :text           => c[:none],
    42:         :aa             => c[:green],
    43:         :start          => c[:red],
    44:         :stop           => c[:red],
    45:         :basic          => c[:cyan],
    46:         :polar          => c[:blue],
    47:         :acidic         => c[:magenta],
    48:         :nonpolar       => c[:yellow],
    49:       }
    50:     end

[Validate]