class MS::Lipid::Modification
the convention is all mods are gains unless the name ends in an underscore
Constants
- CHARGE
- FORMULAS
the charge on the mod should be represented by the number of plusses or minuses after the formula (Li+ for a +1 charge Lithium or H2++, 2 protons with a total of 2 charges)
- MASSDIFFS
determined by running formulas through MS::Mass.massdiff
Attributes
the charge
as a molecular formula
negative indicates a loss
as a symbol
Public Class Methods
given a string with a formula and charge, returns the formula portion and the charges (as a signed integer)
# File lib/ms/lipid/modification.rb, line 13 def self.formula_and_charge(string) md = string.match(/([^+]*)(\+*)$/) charges_string = md[2] if charges_string.nil? 0 else charges_string.count(charges_string[0]) int = -int if charges_string[0] == '-' end [md[1], int] end
calculates the mass diff. For every positive charge the mass of an electron is subtracted; for every negative charge the mass of an electron is added. If gain is false, then the mass diff will be negative.
# File lib/ms/lipid/modification.rb, line 29 def self.massdiff(formula, charge, gain=true) MS::Mass.formula_to_exact_mass(formula) massdiff = MS::Mass.formula_to_exact_mass(formula) massdiff -= (charge * MS::Mass::ELECTRON) # + charge subtracts, - charge adds massdiff = -massdiff unless gain massdiff end
if no mass or formula is given then it searches command mods for the name @param [Symbol] name the name of the mod A number of opts are expected if they are not found in the FORMULAS
, CHARGE
, or MASSDIFFS
hashes:
attributes: :formula = the chemical formula, lipidmaps style ("C2H4BrO") :massdiff = +/-Float :charge = +/- Integer instruction: :loss = true flips the mass diff sign during initialization necessary to get negative massdiff on named molecule (unnecessary if you input massdiff manually)
# File lib/ms/lipid/modification.rb, line 82 def initialize(name, opts={}) @name = name @formula = opts[:formula] || FORMULAS[name] @massdiff = opts[:massdiff] || MASSDIFFS[name] @charge = opts[:charge] || CHARGE[name] # necessary if you are using a named molecule and you want its loss # rather than gain (i.e., you want a negative massdiff) @massdiff = -@massdiff if opts[:loss] end
Public Instance Methods
# File lib/ms/lipid/modification.rb, line 92 def charged_formula @formula + @charge.abs.times.map { (@charge > 0) ? '+' : '-' }.join end
# File lib/ms/lipid/modification.rb, line 96 def gain? massdiff > 0 end
# File lib/ms/lipid/modification.rb, line 104 def inspect "<Mod: #{charged_formula}>" end
# File lib/ms/lipid/modification.rb, line 100 def loss? !gain? end