[BioRuby-cvs] bioruby/lib/bio/shell/plugin codon.rb,1.4,1.5

Katayama Toshiaki k at pub.open-bio.org
Fri Nov 25 11:01:30 EST 2005


Update of /home/repository/bioruby/bioruby/lib/bio/shell/plugin
In directory pub.open-bio.org:/tmp/cvs-serv24495/lib/bio/shell/plugin

Modified Files:
	codon.rb 
Log Message:
* changed to use Bio::NucleicAcid.names for full name of the nucleic acids
* added functionality to display codon usage in the codon table


Index: codon.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/shell/plugin/codon.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** codon.rb	24 Nov 2005 19:30:08 -0000	1.4
--- codon.rb	25 Nov 2005 16:01:28 -0000	1.5
***************
*** 56,63 ****
      }
  
!     def initialize(number, color = true)
        @aacode = Bio::AminoAcid.names
        @table  = Bio::CodonTable[number]
        @number = number
        if color
          generate_colored_text
--- 56,64 ----
      }
  
!     def initialize(number, color = true, cuhash = nil)
        @aacode = Bio::AminoAcid.names
        @table  = Bio::CodonTable[number]
        @number = number
+       @cuhash = cuhash
        if color
          generate_colored_text
***************
*** 72,80 ****
          if aa == '*'
            code = "STOP"
!           aa = ''
          else
            code = @aacode[aa]
          end
!         eval("@#{codon} = ' #{code} #{aa} '")
        end
  
--- 73,86 ----
          if aa == '*'
            code = "STOP"
!           aa = '' unless @cuhash
          else
            code = @aacode[aa]
          end
!         if @cuhash
!           percent = @cuhash[codon].to_s.rjust(6)
!           eval("@#{codon} = '#{aa}#{percent}'")
!         else
!           eval("@#{codon} = ' #{code} #{aa} '")
!         end
        end
  
***************
*** 90,105 ****
        @table.each do |codon, aa|
          property, = @@properties.detect {|key, list| list.include?(aa)}
          if aa == '*'
            color_code = "#{@@colors[:stop]}STOP"
!           color_aa = ""
          else
            color_code = "#{@@colors[property]}#{@aacode[aa]}"
            if @table.start_codon?(codon)
!             color_aa = "#{@@colors[:start]}#{aa}"
            else
!             color_aa = "#{@@colors[:aa]}#{aa}"
            end
          end
!         eval("@#{codon} = ' #{color_code} #{color_aa}#{@@colors[:text]} '")
        end
  
--- 96,130 ----
        @table.each do |codon, aa|
          property, = @@properties.detect {|key, list| list.include?(aa)}
+ 
          if aa == '*'
            color_code = "#{@@colors[:stop]}STOP"
!           if @cuhash
!             color_aa = "#{@@colors[:stop]}#{aa}"
!           else
!             color_aa = ''
!           end
          else
            color_code = "#{@@colors[property]}#{@aacode[aa]}"
            if @table.start_codon?(codon)
!             if @cuhash
!               color_aa = "#{@@colors[:aa]}#{aa}"
!             else
!               color_aa = "#{@@colors[:start]}#{aa}"
!             end
            else
!             if @cuhash
!               color_aa = "#{@@colors[property]}#{aa}"
!             else
!               color_aa = "#{@@colors[:aa]}#{aa}"
!             end
            end
          end
! 
!         if @cuhash
!           percent = @cuhash[codon].to_s.rjust(6)
!           eval("@#{codon} = '#{color_aa}#{@@colors[:text]}#{percent}'")
!         else
!           eval("@#{codon} = ' #{color_code} #{color_aa}#{@@colors[:text]} '")
!         end
        end
  
***************
*** 113,117 ****
  
      def output
!       text = <<-END
          #
          # = Codon table #{@number} : #{@table.definition}
--- 138,142 ----
  
      def output
!       header = <<-END
          #
          # = Codon table #{@number} : #{@table.definition}
***************
*** 119,122 ****
--- 144,149 ----
          #   hydrophilic: #{@hydrophilic}
          #   hydrophobic: #{@hydrophobic}
+       END
+       table = <<-END
          #
          # *---------------------------------------------*
***************
*** 147,150 ****
--- 174,182 ----
          #
        END
+       if @cuhash
+         text = table
+       else
+         text = header + table
+       end
        text.gsub(/^\s+#/, @@colors[:text])
      end
***************
*** 154,159 ****
    private
  
    def codontable(num = 1)
!     cct = ColoredCodonTable.new(num, Bio::Shell.config(:color))
      display cct.output
      return cct.table
--- 186,195 ----
    private
  
+   def codon_usage_table(num = 1, codon_usage = nil)
+     ColoredCodonTable.new(num, Bio::Shell.config(:color), codon_usage)
+   end    
+ 
    def codontable(num = 1)
!     cct = codon_usage_table(num)
      display cct.output
      return cct.table
***************
*** 177,201 ****
  
    def nucleicacids
!     [
!       [ 'A', 'Adenine'  ],
!       [ 'T', 'Thymine'  ],
!       [ 'G', 'Guanine'  ],
!       [ 'C', 'Cytosine' ],
!       [ 'U', 'Uracil'   ],
!       [ 'r', '[ag]', 'puRine' ],
!       [ 'y', '[tc]', 'pYrimidine' ],
!       [ 'w', '[at]', 'Weak' ],
!       [ 's', '[gc]', 'Strong' ],
!       [ 'k', '[tg]', 'Keto' ],
!       [ 'm', '[ac]', 'aroMatic' ],
!       [ 'b', '[tgc]', 'not A' ],
!       [ 'v', '[agc]', 'not T' ],
!       [ 'h', '[atc]', 'not G' ],
!       [ 'd', '[atg]', 'not C' ],
!       [ 'n', '[atgc]', 'any' ],
!     ].each do |list|
!       puts list.join("\t")
      end
!     return Bio::NucleicAcid.names
    end
  
--- 213,221 ----
  
    def nucleicacids
!     names = Bio::NucleicAcid.names
!     %w(a t g c u r y w s k m b v h d n).each do |base|
!       puts "#{base}\t#{names[base]}\t#{names[base.upcase]}"
      end
!     return names
    end
  



More information about the bioruby-cvs mailing list