Class: Bio::AAindex1
- Defined in:
- lib/bio/db/aaindex.rb
Overview
Class for AAindex1 format.
Constant Summary
Constants inherited from AAindex
Bio::AAindex::DELIMITER, Bio::AAindex::RS, Bio::AAindex::TAGSIZE
Instance Method Summary collapse
-
#correlation_coefficient ⇒ Object
Returns correlation_coefficient (Hash) in the C line.
-
#index(type = :float) ⇒ Object
Returns the index (Array) in the I line.
-
#initialize(entry) ⇒ AAindex1
constructor
A new instance of AAindex1.
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.
142 143 144 |
# File 'lib/bio/db/aaindex.rb', line 142 def initialize(entry) super(entry) end |
Instance Method Details
#correlation_coefficient ⇒ Object
Returns correlation_coefficient (Hash) in the C line.
cf.) => 0.999, ‘CDEF123456’ => 0.543, …
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# 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) ⇒ Object
Returns the index (Array) in the I line.
an argument: :string, :float, :zscore or :integer
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# 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 |