class Mspire::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 Mspire::Mass.massdiff

Attributes

charge[RW]

the charge

formula[RW]

a MolecularFormula object

massdiff[RW]

negative indicates a loss

name[RW]

as a symbol

Public Class Methods

formula_and_charge(string) click to toggle source

given a string with a formula and charge, returns the formula portion and the charges (as a signed integer)

# File lib/mspire/lipid/modification.rb, line 14
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
massdiff(formula, charge, gain=true) click to toggle source

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/mspire/lipid/modification.rb, line 30
def self.massdiff(formula, charge, gain=true)
  Mspire::Mass.formula_to_exact_mass(formula)
  massdiff = Mspire::Mass.formula_to_exact_mass(formula)
  massdiff -= (charge * Mspire::Mass::ELECTRON) # + charge subtracts, - charge adds
  massdiff = -massdiff unless gain
  massdiff
end
new(name, opts={}) click to toggle source

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. However, the massdiff will be inferred from the formula if it is not given:

attributes:
:formula = the chemical formula, lipidmaps style ("C2H4BrO") or
           any valid argument to MolecularFormula.from_any
:massdiff = +/-Float
:charge = +/- Integer

instruction:
:loss = true   negates the mass diff sign and charge during initialization
               this option is typically only done for molecules
               already present in the FORMULA hash (e.g.)

proton_loss = Mspire::Lipid::Modification.new(:proton, :loss => true)
water_loss = Mspire::Lipid::Modification.new(:water, :loss => true)
# File lib/mspire/lipid/modification.rb, line 95
def initialize(name, opts={})
  @name = name
  @formula = 
    if ( form_string = (opts[:formula] || FORMULAS[name]) )
      Mspire::MolecularFormula.from_any( form_string )
    end
  @massdiff = opts[:massdiff] || MASSDIFFS[name]
  @charge = opts[:charge] || CHARGE[name]

  if opts[:loss]
    @charge = -@charge
    # 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 
  end
end

Public Instance Methods

charged_formula_string() click to toggle source
# File lib/mspire/lipid/modification.rb, line 112
def charged_formula_string
  @formula.to_s + @charge.abs.times.map { (@charge > 0) ? '+' : '-' }.join
end
Also aliased as: to_s
gain?() click to toggle source
# File lib/mspire/lipid/modification.rb, line 118
def gain?
  massdiff > 0
end
inspect() click to toggle source
# File lib/mspire/lipid/modification.rb, line 126
def inspect
  "<Mod: #{to_s}>"
end
loss?() click to toggle source
# File lib/mspire/lipid/modification.rb, line 122
def loss?
  !gain?
end
to_s()