[BioRuby-cvs] bioruby/lib/bio/db aaindex.rb,1.17,1.18

Mitsuteru C. Nakao nakao at pub.open-bio.org
Wed Feb 22 07:35:22 UTC 2006


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

Modified Files:
	aaindex.rb 
Log Message:
* aaindex.rb: Added Bio::AAindex2#[](aa1, aa2) method for accessing the 
              value in the matrix.
              Changed arguments of Bio::AAindex2#matrix(aa1 = nil, aa1 = nil) 
              to access Bio::AAindex2#[](aa1, aa2) method.
              Added a lazy-parsing by using @data.  
* test_aaindex.rb: Changed test codes for Bio::AAindex2#[] and BioAAindex2#matrix. 


Index: aaindex.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/db/aaindex.rb,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** aaindex.rb	18 Feb 2006 14:44:40 -0000	1.17
--- aaindex.rb	22 Feb 2006 07:35:19 -0000	1.18
***************
*** 18,22 ****
  #
  #  aax1 = Bio::AAindex.auto("PRAM900102.aaindex1")
! #  aax2 = Bio::AAindex.auto("HENS920102.aaindex2")
  #
  #  aax1 = Bio::AAindex1.new("PRAM900102.aaindex1")
--- 18,22 ----
  #
  #  aax1 = Bio::AAindex.auto("PRAM900102.aaindex1")
! #  aax2 = Bio::AAindex.auto("DAYM780301.aaindex2")
  #
  #  aax1 = Bio::AAindex1.new("PRAM900102.aaindex1")
***************
*** 24,31 ****
  #  aax1.index
  #
! #  aax2 = Bio::AAindex2.new("HENS920102.aaindex2")
  #  aax2.entry_id
  #  aax2.matrix
  #  aax2.matrix[2,2]
  #
  # == References
--- 24,33 ----
  #  aax1.index
  #
! #  aax2 = Bio::AAindex2.new("DAYM780301.aaindex2")
  #  aax2.entry_id
  #  aax2.matrix
  #  aax2.matrix[2,2]
+ #  aax2.matrix('R', 'A')
+ #  aax2['R', 'A']
  #
  # == References
***************
*** 89,98 ****
      # Returns entry_id in the H line.
      def entry_id
!       field_fetch('H')
      end
  
      # Returns definition in the D line.
      def definition
!       field_fetch('D')
      end
  
--- 91,108 ----
      # Returns entry_id in the H line.
      def entry_id
!       if @data['entry_id']
!         @data['entry_id']
!       else
!         @data['entry_id'] = field_fetch('H')
!       end
      end
  
      # Returns definition in the D line.
      def definition
!       if @data['definition']
!         @data['definition']
!       else
!         @data['definition'] = field_fetch('D')
!       end
      end
  
***************
*** 100,124 ****
      # cf.) ['LIT:123456', 'PMID:12345678']
      def dblinks
!       field_fetch('R').split(' ')
      end
  
      # Returns authors in the A line.
      def author
!       field_fetch('A')
      end
  
      # Returns title in the T line.
      def title
!       field_fetch('T')
      end
  
      # Returns journal name in the J line.
      def journal
!       field_fetch('J')
      end
  
      # Returns comment (if any).
      def comment
!       field_fetch("*")
      end
    end
--- 110,154 ----
      # cf.) ['LIT:123456', 'PMID:12345678']
      def dblinks
!       if @data['ref']
!         @data['ref']
!       else
!         @data['ref'] = field_fetch('R').split(' ')
!       end
      end
  
      # Returns authors in the A line.
      def author
!       if @data['author']
!         @data['author']
!       else
!         @data['author'] = field_fetch('A')
!       end
      end
  
      # Returns title in the T line.
      def title
!       if @data['title']
!         @data['title']
!       else
!         @data['title'] = field_fetch('T')
!       end
      end
  
      # Returns journal name in the J line.
      def journal
!       if @data['journal']
!         @data['journal']
!       else
!         @data['journal'] = field_fetch('J')
!       end
      end
  
      # Returns comment (if any).
      def comment
!       if @data['comment']
!         @data['comment']
!       else
!         @data['comment'] = field_fetch('*')
!       end
      end
    end
***************
*** 136,146 ****
      # cf.) {'ABCD12010203' => 0.999, 'CDEF123456' => 0.543, ...}
      def correlation_coefficient
!       hash = {}
!       ary = field_fetch('C').split(' ')
!       ary.each do |x|
!         next unless x =~ /^[A-Z]/
!         hash[x] = ary[ary.index(x) + 1].to_f
        end
-       hash
      end
  
--- 166,180 ----
      # cf.) {'ABCD12010203' => 0.999, 'CDEF123456' => 0.543, ...}
      def correlation_coefficient
!       if @data['correlation_coefficient']
!         @data['correlation_coefficient']
!       else
!         hash = {}
!         ary = field_fetch('C').split(' ')
!         ary.each do |x|
!           next unless x =~ /^[A-Z]/
!           hash[x] = ary[ary.index(x) + 1].to_f
!         end
!         @data['correlation_coefficient'] = hash
        end
      end
  
***************
*** 205,236 ****
      # Returns row labels.
      def rows
!       label_data
!       @rows
      end
  
      # Returns col labels.
      def cols
!       label_data
!       @cols
      end
  
!     # Returns matrix in Matrix.
!     def matrix
!       ma = Array.new
  
!       data = label_data
!       data.each_line do |line|
!         list = line.strip.split(/\s+/).map{|x| x.to_f}
!         ma.push(list)
!       end
  
!       Matrix[*ma]
      end
  
!     # Returns 
      def old_matrix # for AAindex <= ver 5.0
  
!       @aa = {} # used to determine row/column of the aa
        attr_reader :aa
  
        field = field_fetch('I')
--- 239,289 ----
      # Returns row labels.
      def rows
!       if @data['rows']
!         @data['rows']
!       else 
!         label_data
!         @rows
!       end
      end
  
      # Returns col labels.
      def cols
!       if @data['cols']
!         @data['cols']
!       else 
!         label_data
!         @cols
!       end
      end
  
!     # Returns the value of amino acids substitution (aa1 -> aa2).
!     def [](aa1 = nil, aa2 = nil)
!       matrix[cols.index(aa1), rows.index(aa2)]
!     end
  
!     # Returns amino acids matrix in Matrix.
!     def matrix(aa1 = nil, aa2 = nil)
!       return self[aa1, aa2] if aa1 and aa2
  
!       if @data['matrix'] 
!         @data['matrix'] 
!       else
!         ma = []
!         label_data.each_line do |line|
!           ma << line.strip.split(/\s+/).map {|x| x.to_f }
!         end
!         @data['matrix'] = Matrix[*ma]
!       end
      end
  
!     # Returns amino acids matrix in Matrix  for the old format (<= ver 5.0).
      def old_matrix # for AAindex <= ver 5.0
+       return @data['matrix'] if @data['matrix']
  
!       @aa = {} 
!       # used to determine row/column of the aa
        attr_reader :aa
+       alias_method :aa, :rows
+       alias_method :aa, :cols
  
        field = field_fetch('I')
***************
*** 256,261 ****
            end
          end
!         Matrix[*ma]
! 
        when / -ARNDCQEGHILKMFPSTWYV / # 21x20/2 matrix (with gap)
          raise NotImplementedError
--- 309,313 ----
            end
          end
!         @data['matrix'] = Matrix[*ma]
        when / -ARNDCQEGHILKMFPSTWYV / # 21x20/2 matrix (with gap)
          raise NotImplementedError
***************
*** 268,278 ****
  
      def label_data
!       label, data = get('M').split("\n", 2)
!       if /M rows = (\S+), cols = (\S+)/.match(label)
!         rows, cols = $1, $2
!         @rows = rows.split('')
!         @cols = cols.split('')
        end
-       return data
      end
  
--- 320,334 ----
  
      def label_data
!       if @data['data'] 
!         @data['data'] 
!       else
!         label, data = get('M').split("\n", 2)
!         if /M rows = (\S+), cols = (\S+)/.match(label)
!           rows, cols = $1, $2
!           @rows = rows.split('')
!           @cols = cols.split('')
!         end
!         @data['data'] = data
        end
      end
  
***************
*** 296,301 ****
    p aax1.correlation_coefficient
    p aax1.index
!   puts "### AAindex2 (HENS920102)"
!   aax2 = Bio::AAindex2.new(Bio::Fetch.query('aaindex', 'HENS920102', 'raw'))
    p aax2.entry_id
    p aax2.definition
--- 352,358 ----
    p aax1.correlation_coefficient
    p aax1.index
!   p aax1
!   puts "### AAindex2 (DAYM780301)"
!   aax2 = Bio::AAindex2.new(Bio::Fetch.query('aaindex', 'DAYM780301', 'raw'))
    p aax2.entry_id
    p aax2.definition
***************
*** 309,315 ****
--- 366,375 ----
    p aax2.matrix
    p aax2.matrix[2,2]
+   p aax2.matrix[2,3]
+   p aax2.matrix[4,3]
    p aax2.matrix.determinant
    p aax2.matrix.rank
    p aax2.matrix.transpose
+   p aax2
  end
  




More information about the bioruby-cvs mailing list