Class Bio::AAindex1
In: lib/bio/db/aaindex.rb
Parent: AAindex

Class for AAindex1 format.

Methods

Public Class methods

[Source]

     # File lib/bio/db/aaindex.rb, line 142
142:     def initialize(entry)
143:       super(entry)
144:     end

Public Instance methods

Returns correlation_coefficient (Hash) in the C line.

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

[Source]

     # File lib/bio/db/aaindex.rb, line 149
149:     def correlation_coefficient
150:       if @data['correlation_coefficient']
151:         @data['correlation_coefficient']
152:       else
153:         hash = {}
154:         ary = field_fetch('C').split(' ')
155:         ary.each do |x|
156:           next unless x =~ /^[A-Z]/
157:           hash[x] = ary[ary.index(x) + 1].to_f
158:         end
159:         @data['correlation_coefficient'] = hash
160:       end
161:     end

Returns the index (Array) in the I line.

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

[Source]

     # File lib/bio/db/aaindex.rb, line 166
166:     def index(type = :float)
167:       aa = %w( A R N D C Q E G H I L K M F P S T W Y V )
168:       values = field_fetch('I', 1).split(' ')
169: 
170:       if values.size != 20
171:         raise "Invalid format in #{entry_id} : #{values.inspect}"
172:       end
173: 
174:       if type == :zscore and values.size > 0
175:         sum = 0.0
176:         values.each do |a|
177:           sum += a.to_f
178:         end
179:         mean = sum / values.size # / 20
180:         var = 0.0
181:         values.each do |a|
182:           var += (a.to_f - mean) ** 2
183:         end
184:         sd = Math.sqrt(var)
185:       end
186: 
187:       if type == :integer
188:         figure = 0
189:         values.each do |a|
190:           figure = [ figure, a[/\..*/].length - 1 ].max
191:         end
192:       end
193: 
194:       hash = {}
195: 
196:       aa.each_with_index do |a, i|
197:         case type
198:         when :string
199:           hash[a] = values[i]
200:         when :float
201:           hash[a] = values[i].to_f
202:         when :zscore
203:           hash[a] = (values[i].to_f - mean) / sd
204:         when :integer
205:           hash[a] = (values[i].to_f * 10 ** figure).to_i
206:         end
207:       end
208:       return hash
209:     end

[Validate]