Class: Bio::AAindex2

Inherits:
AAindex show all
Defined in:
lib/bio/db/aaindex.rb

Overview

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

Constant Summary

Constants inherited from AAindex

Bio::AAindex::DELIMITER, Bio::AAindex::RS, Bio::AAindex::TAGSIZE

Instance Method Summary collapse

Methods inherited from AAindex

#author, auto, #comment, #dblinks, #definition, #entry_id, #journal, #title

Methods inherited from DB

#entry_id, #exists?, #fetch, #get, open, #tags

Constructor Details

#initialize(entry) ⇒ AAindex2

Returns a new instance of AAindex2.


286
287
288
# File 'lib/bio/db/aaindex.rb', line 286

def initialize(entry)
  super(entry)
end

Instance Method Details

#[](aa1 = nil, aa2 = nil) ⇒ Object

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


311
312
313
# File 'lib/bio/db/aaindex.rb', line 311

def [](aa1 = nil, aa2 = nil)
  matrix[cols.index(aa1), rows.index(aa2)]
end

#colsObject

Returns col labels.


301
302
303
304
305
306
307
308
# File 'lib/bio/db/aaindex.rb', line 301

def cols
  if @data['cols']
    @data['cols']
  else 
    label_data
    @cols
  end
end

#matrix(aa1 = nil, aa2 = nil) ⇒ Object

Returns amino acids matrix in Matrix.


316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/bio/db/aaindex.rb', line 316

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_matrixObject

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


341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/bio/db/aaindex.rb', line 341

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

#rowsObject

Returns row labels.


291
292
293
294
295
296
297
298
# File 'lib/bio/db/aaindex.rb', line 291

def rows
  if @data['rows']
    @data['rows']
  else 
    label_data
    @rows
  end
end