require 'ms/mass' module Ms module Mass # A module for working with commonly used residue masses in proteomics. # # require 'ms/mass/aa' # include Ms::Mass::AA # # MONO['A'] # => 71.0371137878 # AVG['A'] # => 71.0779 # # # or use symbols # MONO[:A] # => 71.0371137878 # # This module is built on masses generated from the excellent {'molecules' # library}[http://github.com/bahuvrihi/molecules/tree/master]. See that # library for more serious work with masses: # # gem install molecules module AA Ms::Mass.constants.reject {|v| v == 'AA' }.each do |const| const_set(const, Ms::Mass.const_get(const)) end # These are included here to offer maximum functionality MOLECULES_MONO_UNSUPPORTED = { :B => 172.048405, # average of aspartic acid and asparagine :X => 118.805716, # the average of the mono masses of the 20 amino acids :* => 118.805716, # same as X :Z => (129.04259 + 128.05858) / 2, # average glutamic acid and glutamine #:J => nil, } MOLECULES_AVG_UNSUPPORTED = { :B => 172.1405, # average of aspartic acid and asparagine :X => 118.88603, # the average of the masses of the 20 amino acids :* => 118.88603, # same as X :Z => (129.1155+ 128.1307) / 2, # average glutamic acid and glutamine #:J => nil, } # generated from molecules version 0.1.3: MOLECULES_MONO = { :A => 71.0371137878, :C => 103.0091844778, :D => 115.026943032, :E => 129.0425930962, :F => 147.0684139162, :G => 57.0214637236, :H => 137.0589118624, :I => 113.0840639804, :K => 128.0949630177, :L => 113.0840639804, :M => 131.0404846062, :N => 114.0429274472, :O => 211.1446528645, :P => 97.052763852, :Q => 128.0585775114, :R => 156.1011110281, :S => 87.0320284099, :T => 101.0476784741, :U => 150.9536355878, :V => 99.0684139162, :W => 186.0793129535, :Y => 163.0633285383, } MONO = MOLECULES_MONO_UNSUPPORTED.merge MOLECULES_MONO # generated from molecules version 0.1.3: MOLECULES_AVG = { :A => 71.0779, :C => 103.1429, :D => 115.0874, :E => 129.11398, :F => 147.17386, :G => 57.05132, :H => 137.13928, :I => 113.15764, :K => 128.17228, :L => 113.15764, :M => 131.19606, :N => 114.10264, :O => 211.28076, :P => 97.11518, :Q => 128.12922, :R => 156.18568, :S => 87.0773, :T => 101.10388, :U => 150.0379, :V => 99.13106, :W => 186.2099, :Y => 163.17326, } AVG = MOLECULES_AVG_UNSUPPORTED.merge MOLECULES_AVG [AVG, MONO].each do |hash| hash.each {|k,v| hash[k.to_s] = v } end # returns a hash based on the molecules library of amino acid residues. # type is :mono or :avg def self.mass_index(type=:mono) require 'molecules' hash = {} ('A'..'Z').each do |letter| if res = Molecules::Libraries::Residue[letter] hash[letter] = if type == :mono res.mass elsif type == :avg res.mass {|v| v.std_atomic_weight.value } else raise ArgumentError, "type must be :mono or :avg" end end end hash end # prints a MONO or AVG hash for inclusion in ruby code # type can be :mono or :avg def self.print_mass_index(type=:mono) puts "#{type.to_s.upcase} = {" mass_index(type).sort.each do |k,v| puts ":#{k} => #{v}," end puts "}" end end end end