Class for AAindex2 format.
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
Returns col labels.
# 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.
# 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
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
Generated with the Darkfish Rdoc Generator 2.