Class | Bio::AAindex2
In: | lib/bio/db/aaindex.rb
Parent: | AAindex

Class for AAindex2 format.

### Methods

[] cols matrix new old_matrix rows

### Public Class methods

new(entry)

[Source]

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

### Public Instance methods

[](aa1 = nil, aa2 = nil)

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

[Source]

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

cols()

Returns col labels.

[Source]

         # File lib/bio/db/aaindex.rb, line 232
    232:     def cols
    233:       if @data['cols']
    234:         @data['cols']
    235:       else
    236:         label_data
    237:         @cols
    238:       end
    239:     end

matrix(aa1 = nil, aa2 = nil)

Returns amino acids matrix in Matrix.

[Source]

         # File lib/bio/db/aaindex.rb, line 247
    247:     def matrix(aa1 = nil, aa2 = nil)
    248:       return self[aa1, aa2] if aa1 and aa2
    249:
    250:       if @data['matrix']
    251:         @data['matrix']
    252:       else
    253:         ma = []
    254:         label_data.each_line do |line|
    255:           ma << line.strip.split(/\s+/).map {|x| x.to_f }
    256:         end
    257:         @data['matrix'] = Matrix[*ma]
    258:       end
    259:     end

old_matrix(

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

[Source]

         # File lib/bio/db/aaindex.rb, line 262
    262:     def old_matrix # for AAindex <= ver 5.0
    263:       return @data['matrix'] if @data['matrix']
    264:
    265:       @aa = {}
    266:       # used to determine row/column of the aa
    267:       attr_reader :aa
    268:       alias_method :aa, :rows
    269:       alias_method :aa, :cols
    270:
    271:       field = field_fetch('I')
    272:
    273:       case field
    274:       when / (ARNDCQEGHILKMFPSTWYV)\s+(.*)/ # 20x19/2 matrix
    275:         aalist = $1
    276:         values = $2.split(/\s+/)
    277:
    278:         0.upto(aalist.length - 1) do |i|
    279:           @aa[aalist[i].chr] = i
    280:         end
    281:
    282:         ma = Array.new
    283:         20.times do
    284:           ma.push(Array.new(20)) # 2D array of 20x(20)
    285:         end
    286:
    287:         for i in 0 .. 19 do
    288:           for j in i .. 19 do
    289:             ma[i][j] = values[i + j*(j+1)/2].to_f
    290:             ma[j][i] = ma[i][j]
    291:           end
    292:         end
    293:         @data['matrix'] = Matrix[*ma]
    294:       when / -ARNDCQEGHILKMFPSTWYV / # 21x20/2 matrix (with gap)
    295:         raise NotImplementedError
    296:       when / ACDEFGHIKLMNPQRSTVWYJ- / # 21x21 matrix (with gap)
    297:         raise NotImplementedError
    298:       end
    299:     end

rows()

Returns row labels.

[Source]

         # File lib/bio/db/aaindex.rb, line 222
    222:     def rows
    223:       if @data['rows']
    224:         @data['rows']
    225:       else
    226:         label_data
    227:         @rows
    228:       end
    229:     end

[Validate]