class Bio::AAindex2

Class for AAindex2 format.

Public Class Methods

new(entry) click to toggle source
Calls superclass method Bio::AAindex.new
# File lib/bio/db/aaindex.rb, line 217
def initialize(entry)
  super(entry)
end

Public Instance Methods

[](aa1 = nil, aa2 = nil) click to toggle source

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

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

Returns col labels.

# File lib/bio/db/aaindex.rb, line 232
def cols
  if @data['cols']
    @data['cols']
  else 
    label_data
    @cols
  end
end
matrix(aa1 = nil, aa2 = nil) click to toggle source

Returns amino acids matrix in Matrix.

# 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
    ma_len = ma.size
    ma.each do |row|
      row_size = row.size
      if row_size < ma_len
        (row_size..ma_len-1).each do |i|
          row[i] = ma[i][row_size-1]
        end
      end
    end
    mat = Matrix[*ma]
    @data['matrix'] = mat
  end
end
old_matrix() click to toggle source

Returns amino acids matrix in Matrix for the old format (<= ver 5.0).

# File lib/bio/db/aaindex.rb, line 272
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
rows() click to toggle source

Returns row labels.

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