class Bio::AAindex1
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
¶ ↑
Public Class Methods
new(entry)
click to toggle source
Calls superclass method
Bio::AAindex::new
# File lib/bio/db/aaindex.rb 190 def initialize(entry) 191 super(entry) 192 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 197 def correlation_coefficient 198 if @data['correlation_coefficient'] 199 @data['correlation_coefficient'] 200 else 201 hash = {} 202 ary = field_fetch('C').split(' ') 203 ary.each do |x| 204 next unless x =~ /^[A-Z]/ 205 hash[x] = ary[ary.index(x) + 1].to_f 206 end 207 @data['correlation_coefficient'] = hash 208 end 209 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 214 def index(type = :float) 215 aa = %w( A R N D C Q E G H I L K M F P S T W Y V ) 216 values = field_fetch('I', 1).split(' ') 217 218 if values.size != 20 219 raise "Invalid format in #{entry_id} : #{values.inspect}" 220 end 221 222 if type == :zscore and values.size > 0 223 sum = 0.0 224 values.each do |a| 225 sum += a.to_f 226 end 227 mean = sum / values.size # / 20 228 var = 0.0 229 values.each do |a| 230 var += (a.to_f - mean) ** 2 231 end 232 sd = Math.sqrt(var) 233 end 234 235 if type == :integer 236 figure = 0 237 values.each do |a| 238 figure = [ figure, a[/\..*/].length - 1 ].max 239 end 240 end 241 242 hash = {} 243 244 aa.each_with_index do |a, i| 245 case type 246 when :string 247 hash[a] = values[i] 248 when :float 249 hash[a] = values[i].to_f 250 when :zscore 251 hash[a] = (values[i].to_f - mean) / sd 252 when :integer 253 hash[a] = (values[i].to_f * 10 ** figure).to_i 254 end 255 end 256 return hash 257 end