[BioRuby-cvs] bioruby/lib/bio/data aa.rb,0.12,0.13 na.rb,0.14,0.15

Katayama Toshiaki k at pub.open-bio.org
Fri Nov 4 12:49:12 EST 2005


Update of /home/repository/bioruby/bioruby/lib/bio/data
In directory pub.open-bio.org:/tmp/cvs-serv27389/lib/bio/data

Modified Files:
	aa.rb na.rb 
Log Message:
* converted to RDoc
* weight method is changed to raise a RuntimeError when unsupported alphabet is given


Index: aa.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/data/aa.rb,v
retrieving revision 0.12
retrieving revision 0.13
diff -C2 -d -r0.12 -r0.13
*** aa.rb	26 Sep 2005 13:00:06 -0000	0.12
--- aa.rb	4 Nov 2005 17:49:10 -0000	0.13
***************
*** 1,6 ****
  #
! # bio/data/aa.rb - Amino Acids
  #
! #   Copyright (C) 2001, 2005 KATAYAMA Toshiaki <k at bioruby.org>
  #
  #  This library is free software; you can redistribute it and/or
--- 1,12 ----
  #
! # = bio/data/aa.rb - Amino Acids
  #
! # Copyright::	Copyright (C) 2001, 2005
! #		Toshiaki Katayama <k at bioruby.org>
! # Lisence::	LGPL
! #
! # $Id$
! #
! #--
  #
  #  This library is free software; you can redistribute it and/or
***************
*** 18,273 ****
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #  $Id$
  #
  
  module Bio
  
!   class AminoAcid
  
!     module Data
  
!       # IUPAC code
!       # * http://www.iupac.org/
!       # * http://www.chem.qmw.ac.uk/iubmb/newsletter/1999/item3.html
  
!       Names= {
  
!         'A' => 'Ala',
!         'C' => 'Cys',
!         'D' => 'Asp',
!         'E' => 'Glu',
!         'F' => 'Phe',
!         'G' => 'Gly',
!         'H' => 'His',
!         'I' => 'Ile',
!         'K' => 'Lys',
!         'L' => 'Leu',
!         'M' => 'Met',
!         'N' => 'Asn',
!         'P' => 'Pro',
!         'Q' => 'Gln',
!         'R' => 'Arg',
!         'S' => 'Ser',
!         'T' => 'Thr',
!         'V' => 'Val',
!         'W' => 'Trp',
!         'Y' => 'Tyr',
!         'B' => 'Asx',	# D/N
!         'Z' => 'Glx',	# E/Q
!         'U' => 'Sec',	# 'uga' (stop)
!         '?' => 'Pyl',	# 'uag' (stop)
!        
!         'Ala' => 'alanine',
!         'Cys' => 'cysteine',
!         'Asp' => 'aspartic acid',
!         'Glu' => 'glutamic acid',
!         'Phe' => 'phenylalanine',
!         'Gly' => 'glycine',
!         'His' => 'histidine',
!         'Ile' => 'isoleucine',
!         'Lys' => 'lysine',
!         'Leu' => 'leucine',
!         'Met' => 'methionine',
!         'Asn' => 'asparagine',
!         'Pro' => 'proline',
!         'Gln' => 'glutamine',
!         'Arg' => 'arginine',
!         'Ser' => 'serine',
!         'Thr' => 'threonine',
!         'Val' => 'valine',
!         'Trp' => 'tryptophan',
!         'Tyr' => 'tyrosine',
!         'Asx' => 'asparagine/aspartic acid',
!         'Glx' => 'glutamine/glutamic acid',
!         'Sec' => 'selenocysteine',
!         'Pyl' => 'pyrrolysine',
  
!       }
  
!       # AAindex FASG760101 - Molecular weight (Fasman, 1976)
!       #   Fasman, G.D., ed.
!       #   Handbook of Biochemistry and Molecular Biology", 3rd ed.,
!       #   Proteins - Volume 1, CRC Press, Cleveland (1976)
  
!       Weight = {
  
!         'A' => 89.09,
!         'C' => 121.15,	# 121.16 according to the Wikipedia
!         'D' => 133.10,
!         'E' => 147.13,
!         'F' => 165.19,
!         'G' => 75.07,
!         'H' => 155.16,
!         'I' => 131.17,
!         'K' => 146.19,
!         'L' => 131.17,
!         'M' => 149.21,
!         'N' => 132.12,
!         'P' => 115.13,
!         'Q' => 146.15,
!         'R' => 174.20,
!         'S' => 105.09,
!         'T' => 119.12,
!         'U' => 168.06,
!         'V' => 117.15,
!         'W' => 204.23,
!         'Y' => 181.19,
!       }
  
!       def weight(x = nil)
!         if x
!           if x.length > 1
!             total = 0.0
!             x.each_byte do |byte|
!               aa = byte.chr.upcase
                total += Weight[aa]
              end
-             total -= NucleicAcid.weight[:water] * (x.length - 1)
-           else
-             Weight[x]
            end
          else
!           Weight
          end
        end
  
!       def [](x)
!         Names[x]
!       end
  
!       # backward compatibility
!       def names
!         Names
!       end
!       alias aa names
  
!       def name(x)
!         str = Names[x]
!         if str and str.length == 3
!           Names[str]
!         else
!           str
!         end
        end
  
!       def to_1(x)
!         case x.to_s.length
!         when 1
!           x
!         when 3
!           three2one(x)
!         else
!           name2one(x)
!         end
        end
!       alias one to_1
  
!       def to_3(x)
!         case x.to_s.length
!         when 1
!           one2three(x)
!         when 3
!           x
!         else
!           name2three(x)
!         end
        end
!       alias three to_3
  
!       def one2three(x)
!         if x and x.length != 1
!           raise ArgumentError
!         else
!           Names[x]
!         end
        end
  
!       def three2one(x)
!         if x and x.length != 3
!           raise ArgumentError
!         else
!           reverse[x]
!         end
        end
  
!       def one2name(x)
!         if x and x.length != 1
!           raise ArgumentError
!         else
!           three2name(Names[x])
!         end
        end
  
!       def name2one(x)
!         str = reverse[x.to_s.downcase]
!         if str and str.length == 3
!           three2one(str)
!         else
!           str
!         end
        end
  
!       def three2name(x)
!         if x and x.length != 3
!           raise ArgumentError
!         else
!           Names[x]
!         end
        end
  
!       def name2three(x)
!         reverse[x.downcase]
!       end
  
!       def to_re(seq)
!         str = seq.to_s.upcase
!         str.gsub!(/[^BZACDEFGHIKLMNPQRSTVWYU]/, ".")
!         str.gsub!("B", "[DN]")
!         str.gsub!("Z", "[EQ]")
!         Regexp.new(str)
!       end
  
  
!       private
  
  
!       def reverse
!         hash = Hash.new
!         Names.each do |k, v|
!           hash[v] = k
!         end
!         hash
        end
! 
      end
  
  
-     # as instance methods
-     include Data
  
!     # as class methods
!     extend Data
  
  
!     # backward compatibility
!     Names = Data::Names
!     Weight = Data::Weight
  
  
!     private
  
  
!     # override when used as an instance method to improve performance
!     alias orig_reverse reverse
!     def reverse
!       unless @reverse
!         @reverse = orig_reverse
!       end
!       @reverse
      end
! 
    end
  
  end
  
  
--- 24,283 ----
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #++
  #
  
  module Bio
  
! class AminoAcid
  
!   module Data
  
!     # IUPAC code
!     # * http://www.iupac.org/
!     # * http://www.chem.qmw.ac.uk/iubmb/newsletter/1999/item3.html
  
!     Names= {
  
!       'A' => 'Ala',
!       'C' => 'Cys',
!       'D' => 'Asp',
!       'E' => 'Glu',
!       'F' => 'Phe',
!       'G' => 'Gly',
!       'H' => 'His',
!       'I' => 'Ile',
!       'K' => 'Lys',
!       'L' => 'Leu',
!       'M' => 'Met',
!       'N' => 'Asn',
!       'P' => 'Pro',
!       'Q' => 'Gln',
!       'R' => 'Arg',
!       'S' => 'Ser',
!       'T' => 'Thr',
!       'V' => 'Val',
!       'W' => 'Trp',
!       'Y' => 'Tyr',
!       'B' => 'Asx',	# D/N
!       'Z' => 'Glx',	# E/Q
!       'U' => 'Sec',	# 'uga' (stop)
!       '?' => 'Pyl',	# 'uag' (stop)
!      
!       'Ala' => 'alanine',
!       'Cys' => 'cysteine',
!       'Asp' => 'aspartic acid',
!       'Glu' => 'glutamic acid',
!       'Phe' => 'phenylalanine',
!       'Gly' => 'glycine',
!       'His' => 'histidine',
!       'Ile' => 'isoleucine',
!       'Lys' => 'lysine',
!       'Leu' => 'leucine',
!       'Met' => 'methionine',
!       'Asn' => 'asparagine',
!       'Pro' => 'proline',
!       'Gln' => 'glutamine',
!       'Arg' => 'arginine',
!       'Ser' => 'serine',
!       'Thr' => 'threonine',
!       'Val' => 'valine',
!       'Trp' => 'tryptophan',
!       'Tyr' => 'tyrosine',
!       'Asx' => 'asparagine/aspartic acid',
!       'Glx' => 'glutamine/glutamic acid',
!       'Sec' => 'selenocysteine',
!       'Pyl' => 'pyrrolysine',
  
!     }
  
!     # AAindex FASG760101 - Molecular weight (Fasman, 1976)
!     #   Fasman, G.D., ed.
!     #   Handbook of Biochemistry and Molecular Biology", 3rd ed.,
!     #   Proteins - Volume 1, CRC Press, Cleveland (1976)
  
!     Weight = {
  
!       'A' => 89.09,
!       'C' => 121.15,	# 121.16 according to the Wikipedia
!       'D' => 133.10,
!       'E' => 147.13,
!       'F' => 165.19,
!       'G' => 75.07,
!       'H' => 155.16,
!       'I' => 131.17,
!       'K' => 146.19,
!       'L' => 131.17,
!       'M' => 149.21,
!       'N' => 132.12,
!       'P' => 115.13,
!       'Q' => 146.15,
!       'R' => 174.20,
!       'S' => 105.09,
!       'T' => 119.12,
!       'U' => 168.06,
!       'V' => 117.15,
!       'W' => 204.23,
!       'Y' => 181.19,
!     }
  
!     def weight(x = nil)
!       if x
!         if x.length > 1
!           total = 0.0
!           x.each_byte do |byte|
!             aa = byte.chr.upcase
!             if Weight[aa]
                total += Weight[aa]
+             else
+               raise "Error: invalid amino acid '#{aa}'"
              end
            end
+           total -= NucleicAcid.weight[:water] * (x.length - 1)
          else
!           Weight[x]
          end
+       else
+         Weight
        end
+     end
  
!     def [](x)
!       Names[x]
!     end
  
!     # backward compatibility
!     def names
!       Names
!     end
!     alias aa names
  
!     def name(x)
!       str = Names[x]
!       if str and str.length == 3
!         Names[str]
!       else
!         str
        end
+     end
  
!     def to_1(x)
!       case x.to_s.length
!       when 1
!         x
!       when 3
!         three2one(x)
!       else
!         name2one(x)
        end
!     end
!     alias one to_1
  
!     def to_3(x)
!       case x.to_s.length
!       when 1
!         one2three(x)
!       when 3
!         x
!       else
!         name2three(x)
        end
!     end
!     alias three to_3
  
!     def one2three(x)
!       if x and x.length != 1
!         raise ArgumentError
!       else
!         Names[x]
        end
+     end
  
!     def three2one(x)
!       if x and x.length != 3
!         raise ArgumentError
!       else
!         reverse[x]
        end
+     end
  
!     def one2name(x)
!       if x and x.length != 1
!         raise ArgumentError
!       else
!         three2name(Names[x])
        end
+     end
  
!     def name2one(x)
!       str = reverse[x.to_s.downcase]
!       if str and str.length == 3
!         three2one(str)
!       else
!         str
        end
+     end
  
!     def three2name(x)
!       if x and x.length != 3
!         raise ArgumentError
!       else
!         Names[x]
        end
+     end
  
!     def name2three(x)
!       reverse[x.downcase]
!     end
  
!     def to_re(seq)
!       str = seq.to_s.upcase
!       str.gsub!(/[^BZACDEFGHIKLMNPQRSTVWYU]/, ".")
!       str.gsub!("B", "[DN]")
!       str.gsub!("Z", "[EQ]")
!       Regexp.new(str)
!     end
  
  
!     private
  
  
!     def reverse
!       hash = Hash.new
!       Names.each do |k, v|
!         hash[v] = k
        end
!       hash
      end
  
+   end
  
  
!   # as instance methods
!   include Data
! 
!   # as class methods
!   extend Data
  
  
!   # backward compatibility
!   Names = Data::Names
!   Weight = Data::Weight
  
  
!   private
  
  
!   # override when used as an instance method to improve performance
!   alias orig_reverse reverse
!   def reverse
!     unless @reverse
!       @reverse = orig_reverse
      end
!     @reverse
    end
  
  end
+ 
+ end # module Bio
  
  

Index: na.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/data/na.rb,v
retrieving revision 0.14
retrieving revision 0.15
diff -C2 -d -r0.14 -r0.15
*** na.rb	26 Sep 2005 13:00:06 -0000	0.14
--- na.rb	4 Nov 2005 17:49:10 -0000	0.15
***************
*** 1,6 ****
  #
! # bio/data/na.rb - Nucleic Acids
  #
! #   Copyright (C) 2001, 2005 KATAYAMA Toshiaki <k at bioruby.org>
  #
  #  This library is free software; you can redistribute it and/or
--- 1,12 ----
  #
! # = bio/data/na.rb - Nucleic Acids
  #
! # Copyright::	Copyright (C) 2001, 2005
! #		Toshiaki Katayama <k at bioruby.org>
! # Lisence::	LGPL
! #
! # $Id$
! #
! #--
  #
  #  This library is free software; you can redistribute it and/or
***************
*** 18,160 ****
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #  $Id$
  #
  
  module Bio
  
!   class NucleicAcid
  
!     module Data
  
!       # IUPAC code
!       # * Faisst and Meyer (Nucleic Acids Res. 20:3-26, 1992)
!       # * http://www.ncbi.nlm.nih.gov/collab/FT/
  
!       Names = {
  
!         'y'	=> '[tc]',	# pYrimidine
!         'r'	=> '[ag]',	# puRine
!         'w'	=> '[at]',	# Weak
!         's'	=> '[gc]',	# Strong
!         'k'	=> '[tg]',	# Keto
!         'm'	=> '[ac]',	# aMino
  
!         'b'	=> '[tgc]',	# not A
!         'd'	=> '[atg]',	# not C
!         'h'	=> '[atc]',	# not G
!         'v'	=> '[agc]',	# not T
  
!         'n'	=> '[atgc]',
  
!         'a'	=> 'a',
!         't'	=> 't',
!         'g'	=> 'g',
!         'c'	=> 'c',
!         'u'	=> 'u',
  
!         'A'	=> 'adenine',
!         'T'	=> 'thymine',
!         'G'	=> 'guanine',
!         'C'	=> 'cytosine',
!         'U'	=> 'uracil',
  
!       }
  
!       Weight = {
  
!         # Calculated by BioPerl's Bio::Tools::SeqStats.pm :-)
  
!         'a'	=> 135.15,
!         't'	=> 126.13,
!         'g'	=> 151.15,
!         'c'	=> 111.12,
!         'u'	=> 112.10,
  
!         :adenine	=> 135.15,
!         :thymine	=> 126.13,
!         :guanine	=> 151.15,
!         :cytosine	=> 111.12,
!         :uracil		=> 112.10,
  
!         :deoxyribose_phosphate	=> 196.11,
!         :ribose_phosphate	=> 212.11,
  
!         :hydrogen	=> 1.00794,
!         :water		=> 18.015,
  
!       }
  
!       def weight(x = nil, rna = nil)
!         if x
!           if x.length > 1
!             if rna
!               phosphate = Weight[:ribose_phosphate]
!             else
!               phosphate = Weight[:deoxyribose_phosphate]
!             end
!             hydrogen    = Weight[:hydrogen]
!             water       = Weight[:water]
  
!             total = 0.0
!             x.each_byte do |byte|
!               base = byte.chr.downcase
                total += Weight[base] + phosphate - hydrogen * 2
              end
-             total -= water * (x.length - 1)
-           else
-             Weight[x.to_s.downcase]
            end
          else
!           Weight
          end
        end
  
!       def [](x)
!         Names[x]
!       end
  
!       # backward compatibility
!       def names
!         Names
!       end
!       alias na names
  
!       def name(x)
!         Names[x.to_s.upcase]
!       end
  
!       def to_re(seq, rna = false)
!         str = ""
!         seq.to_s.downcase.each_byte do |base|
!           if re = Names[base.chr]
!             str += re
!           else
!             str += "."
!           end
!         end
!         if rna
!           str.tr!("t", "u")
          end
-         Regexp.new(str)
        end
! 
      end
  
  
-     # as instance methods
-     include Data
  
!     # as class methods
!     extend Data
  
  
-     # backward compatibility
-     Names = Data::Names
-     Weight = Data::Weight
  
  
-   end
  
  end
  
  
--- 24,170 ----
  #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  #
! #++
  #
  
  module Bio
  
! class NucleicAcid
  
!   module Data
  
!     # IUPAC code
!     # * Faisst and Meyer (Nucleic Acids Res. 20:3-26, 1992)
!     # * http://www.ncbi.nlm.nih.gov/collab/FT/
  
!     Names = {
  
!       'y'	=> '[tc]',	# pYrimidine
!       'r'	=> '[ag]',	# puRine
!       'w'	=> '[at]',	# Weak
!       's'	=> '[gc]',	# Strong
!       'k'	=> '[tg]',	# Keto
!       'm'	=> '[ac]',	# aMino
  
!       'b'	=> '[tgc]',	# not A
!       'd'	=> '[atg]',	# not C
!       'h'	=> '[atc]',	# not G
!       'v'	=> '[agc]',	# not T
  
!       'n'	=> '[atgc]',
  
!       'a'	=> 'a',
!       't'	=> 't',
!       'g'	=> 'g',
!       'c'	=> 'c',
!       'u'	=> 'u',
  
!       'A'	=> 'adenine',
!       'T'	=> 'thymine',
!       'G'	=> 'guanine',
!       'C'	=> 'cytosine',
!       'U'	=> 'uracil',
  
!     }
  
!     Weight = {
  
!       # Calculated by BioPerl's Bio::Tools::SeqStats.pm :-)
  
!       'a'	=> 135.15,
!       't'	=> 126.13,
!       'g'	=> 151.15,
!       'c'	=> 111.12,
!       'u'	=> 112.10,
  
!       :adenine	=> 135.15,
!       :thymine	=> 126.13,
!       :guanine	=> 151.15,
!       :cytosine	=> 111.12,
!       :uracil		=> 112.10,
  
!       :deoxyribose_phosphate	=> 196.11,
!       :ribose_phosphate	=> 212.11,
  
!       :hydrogen	=> 1.00794,
!       :water		=> 18.015,
  
!     }
  
!     def weight(x = nil, rna = nil)
!       if x
!         if x.length > 1
!           if rna
!             phosphate = Weight[:ribose_phosphate]
!           else
!             phosphate = Weight[:deoxyribose_phosphate]
!           end
!           hydrogen    = Weight[:hydrogen]
!           water       = Weight[:water]
  
!           total = 0.0
!           x.each_byte do |byte|
!             base = byte.chr.downcase
!             if Weight[base]
                total += Weight[base] + phosphate - hydrogen * 2
+             else
+               raise "Error: invalid nucleic acid '#{base}'"
              end
            end
+           total -= water * (x.length - 1)
          else
!           Weight[x.to_s.downcase]
          end
+       else
+         Weight
        end
+     end
  
!     def [](x)
!       Names[x]
!     end
  
!     # backward compatibility
!     def names
!       Names
!     end
!     alias na names
  
!     def name(x)
!       Names[x.to_s.upcase]
!     end
  
!     def to_re(seq, rna = false)
!       str = ""
!       seq.to_s.downcase.each_byte do |base|
!         if re = Names[base.chr]
!           str += re
!         else
!           str += "."
          end
        end
!       if rna
!         str.tr!("t", "u")
!       end
!       Regexp.new(str)
      end
  
+   end
  
  
!   # as instance methods
!   include Data
  
+   # as class methods
+   extend Data
  
  
+   # backward compatibility
+   Names = Data::Names
+   Weight = Data::Weight
  
  
  end
+ 
+ end # module Bio
  
  



More information about the bioruby-cvs mailing list