Class: Bio::AAindex2

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

Overview

Class for AAindex2 format.

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.



217
218
219
# File 'lib/bio/db/aaindex.rb', line 217

def initialize(entry)
  super(entry)
end

Instance Method Details

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

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



242
243
244
# File 'lib/bio/db/aaindex.rb', line 242

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

#colsObject

Returns col labels.



232
233
234
235
236
237
238
239
# File 'lib/bio/db/aaindex.rb', line 232

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.



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# 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

#old_matrixObject

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



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# 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

#rowsObject

Returns row labels.



222
223
224
225
226
227
228
229
# File 'lib/bio/db/aaindex.rb', line 222

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