Class: Mass::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_id/mass.rb

Instance Method Summary collapse

Constructor Details

#initialize(mass_hash, add_extra = 0.0) ⇒ Calculator

mass_hash must respond to :h2o or ‘h2o’. This is added to represent the tails of the peptide. add_extra is outside of that (e.g., an H+)



151
152
153
154
# File 'lib/spec_id/mass.rb', line 151

def initialize(mass_hash, add_extra=0.0)
  @mass_hash = mass_hash_to_s(mass_hash)
  @final_add = @mass_hash['h2o'] + add_extra
end

Instance Method Details

#mass_hash_to_s(mass_hash) ⇒ Object



156
157
158
159
160
161
162
# File 'lib/spec_id/mass.rb', line 156

def mass_hash_to_s(mass_hash)
  new_hash = {}
  mass_hash.each do |k,v|
    new_hash[k.to_s] = v
  end
  new_hash
end

#masses(aaseqs) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/spec_id/mass.rb', line 164

def masses(aaseqs)
  aaseqs.map do |aaseq|
    sum = @final_add  # <- add in the initialization
    aaseq.split('').each do |let|
      if @mass_hash.key? let
        sum += @mass_hash[let]
      else
        abort "LETTER not found in mass_hash: #{let}"
      end
    end
    sum
  end
end