Class: Bio::AAindex1

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

Overview

Description

Parser class for AAindex1, Amino Acid Index Database.

Examples

# auto-detection of data format by using Bio::AAindex class
aax1 = Bio::AAindex.auto("PRAM900102.aaindex1")

# parse a file and get contents
aax1 = Bio::AAindex1.new("PRAM900102.aaindex1")
aax1.entry_id
aax1.index

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) ⇒ AAindex1

Returns a new instance of AAindex1.



190
191
192
# File 'lib/bio/db/aaindex.rb', line 190

def initialize(entry)
  super(entry)
end

Instance Method Details

#correlation_coefficientObject

Returns correlation_coefficient (Hash) in the C line.

cf.) => 0.999, ‘CDEF123456’ => 0.543, …



197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/bio/db/aaindex.rb', line 197

def correlation_coefficient
  if @data['correlation_coefficient']
    @data['correlation_coefficient']
  else
    hash = {}
    ary = field_fetch('C').split(' ')
    ary.each do |x|
      next unless x =~ /^[A-Z]/
      hash[x] = ary[ary.index(x) + 1].to_f
    end
    @data['correlation_coefficient'] = hash
  end
end

#index(type = :float) ⇒ Object

Returns the index (Array) in the I line.

an argument: :string, :float, :zscore or :integer



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/bio/db/aaindex.rb', line 214

def index(type = :float)
  aa = %w( A R N D C Q E G H I L K M F P S T W Y V )
  values = field_fetch('I', 1).split(' ')

  if values.size != 20
    raise "Invalid format in #{entry_id} : #{values.inspect}"
  end

  if type == :zscore and values.size > 0
    sum = 0.0
    values.each do |a|
      sum += a.to_f
    end
    mean = sum / values.size # / 20
    var = 0.0
    values.each do |a|
      var += (a.to_f - mean) ** 2
    end
    sd = Math.sqrt(var)
  end

  if type == :integer
    figure = 0
    values.each do |a|
      figure = [ figure, a[/\..*/].length - 1 ].max
    end
  end

  hash = {}

  aa.each_with_index do |a, i|
    case type
    when :string
      hash[a] = values[i]
    when :float
      hash[a] = values[i].to_f
    when :zscore
      hash[a] = (values[i].to_f - mean) / sd
    when :integer
      hash[a] = (values[i].to_f * 10 ** figure).to_i
    end
  end
  return hash
end