class Bio::AAindex2

Description

Parser class for AAindex2, Amino Acid Index Database.

Examples

# auto-detection of data format by using Bio::AAindex class
aax2 = Bio::AAindex.auto("DAYM780301.aaindex2")

# parse a file and get contents
aax2 = Bio::AAindex2.new("DAYM780301.aaindex2")
aax2.entry_id
aax2.matrix
aax2.matrix[2,2]
aax2.matrix('R', 'A')
aax2['R', 'A']

References

Public Class Methods

new(entry) click to toggle source
Calls superclass method Bio::AAindex::new
    # File lib/bio/db/aaindex.rb
286 def initialize(entry)
287   super(entry)
288 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
311 def [](aa1 = nil, aa2 = nil)
312   matrix[cols.index(aa1), rows.index(aa2)]
313 end
cols() click to toggle source

Returns col labels.

    # File lib/bio/db/aaindex.rb
301 def cols
302   if @data['cols']
303     @data['cols']
304   else 
305     label_data
306     @cols
307   end
308 end
matrix(aa1 = nil, aa2 = nil) click to toggle source

Returns amino acids matrix in Matrix.

    # File lib/bio/db/aaindex.rb
316 def matrix(aa1 = nil, aa2 = nil)
317   return self[aa1, aa2] if aa1 and aa2
318 
319   if @data['matrix'] 
320     @data['matrix'] 
321   else
322     ma = []
323     label_data.each_line do |line|
324       ma << line.strip.split(/\s+/).map {|x| x.to_f }
325     end
326     ma_len = ma.size
327     ma.each do |row|
328       row_size = row.size
329       if row_size < ma_len
330         (row_size..ma_len-1).each do |i|
331           row[i] = ma[i][row_size-1]
332         end
333       end
334     end
335     mat = Matrix[*ma]
336     @data['matrix'] = mat
337   end
338 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
341 def old_matrix # for AAindex <= ver 5.0
342   return @data['matrix'] if @data['matrix']
343 
344   @aa = {} 
345   # used to determine row/column of the aa
346   attr_reader :aa
347   alias_method :aa, :rows
348   alias_method :aa, :cols
349 
350   field = field_fetch('I')
351 
352   case field
353   when / (ARNDCQEGHILKMFPSTWYV)\s+(.*)/ # 20x19/2 matrix
354     aalist = $1
355     values = $2.split(/\s+/)
356 
357     0.upto(aalist.length - 1) do |i|
358       @aa[aalist[i].chr] = i
359     end
360 
361     ma = Array.new
362     20.times do
363       ma.push(Array.new(20)) # 2D array of 20x(20)
364     end
365 
366     for i in 0 .. 19 do
367       for j in i .. 19 do
368         ma[i][j] = values[i + j*(j+1)/2].to_f
369         ma[j][i] = ma[i][j]
370       end
371     end
372     @data['matrix'] = Matrix[*ma]
373   when / -ARNDCQEGHILKMFPSTWYV / # 21x20/2 matrix (with gap)
374     raise NotImplementedError
375   when / ACDEFGHIKLMNPQRSTVWYJ- / # 21x21 matrix (with gap)
376     raise NotImplementedError
377   end
378 end
rows() click to toggle source

Returns row labels.

    # File lib/bio/db/aaindex.rb
291 def rows
292   if @data['rows']
293     @data['rows']
294   else 
295     label_data
296     @rows
297   end
298 end