Class Bio::AAindex2
In: lib/bio/db/aaindex.rb  (CVS)
Parent: AAindex

Class for AAindex2 format.

Methods

[]   cols   matrix   new   old_matrix   rows  

Public Class methods

[Source]

# File lib/bio/db/aaindex.rb, line 217
    def initialize(entry)
      super(entry)
    end

Public Instance methods

Returns the value of amino acids substitution (aa1 -> aa2).

[Source]

# File lib/bio/db/aaindex.rb, line 242
    def [](aa1 = nil, aa2 = nil)
      matrix[cols.index(aa1), rows.index(aa2)]
    end

Returns col labels.

[Source]

# File lib/bio/db/aaindex.rb, line 232
    def cols
      if @data['cols']
        @data['cols']
      else 
        label_data
        @cols
      end
    end

Returns amino acids matrix in Matrix.

[Source]

# File lib/bio/db/aaindex.rb, line 247
    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).

[Source]

# File lib/bio/db/aaindex.rb, line 262
    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')

      case field
      when / (ARNDCQEGHILKMFPSTWYV)\s+(.*)/ # 20x19/2 matrix
        aalist = $1
        values = $2.split(/\s+/)

        0.upto(aalist.length - 1) do |i|
          @aa[aalist[i].chr] = i
        end

        ma = Array.new
        20.times do
          ma.push(Array.new(20)) # 2D array of 20x(20)
        end

        for i in 0 .. 19 do
          for j in i .. 19 do
            ma[i][j] = values[i + j*(j+1)/2].to_f
            ma[j][i] = ma[i][j]
          end
        end
        @data['matrix'] = Matrix[*ma]
      when / -ARNDCQEGHILKMFPSTWYV / # 21x20/2 matrix (with gap)
        raise NotImplementedError
      when / ACDEFGHIKLMNPQRSTVWYJ- / # 21x21 matrix (with gap)
        raise NotImplementedError
      end
    end

Returns row labels.

[Source]

# File lib/bio/db/aaindex.rb, line 222
    def rows
      if @data['rows']
        @data['rows']
      else 
        label_data
        @rows
      end
    end

[Validate]