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

[Source]

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

Public Instance methods

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

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

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:         ma_len = ma.size
258:         ma.each do |row|
259:           row_size = row.size
260:           if row_size < ma_len
261:             (row_size..ma_len-1).each do |i|
262:               row[i] = ma[i][row_size-1]
263:             end
264:           end
265:         end
266:         mat = Matrix[*ma]
267:         @data['matrix'] = mat
268:       end
269:     end

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

[Source]

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

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]