class Bio::AAindex1
Class for AAindex1 format.
Public Class Methods
new(entry)
click to toggle source
Calls superclass method
Bio::AAindex.new
# File lib/bio/db/aaindex.rb, line 142 def initialize(entry) super(entry) end
Public Instance Methods
correlation_coefficient()
click to toggle source
Returns #correlation_coefficient (Hash) in the C line.
cf.) {'ABCD12010203' => 0.999, 'CDEF123456' => 0.543, …}
# File lib/bio/db/aaindex.rb, line 149 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)
click to toggle source
Returns the index (Array) in the I line.
an argument: :string, :float, :zscore or :integer
# File lib/bio/db/aaindex.rb, line 166 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