Class: Mspire::Lipid::Modification

Inherits:
MolecularFormula
  • Object
show all
Defined in:
lib/mspire/lipid/modification.rb

Overview

the convention is all mods are gains unless the name ends in an underscore

Constant Summary collapse

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)

{
  :proton => 'H',
  :ammonium => 'NH4',
  :lithium => 'Li',
  :sodium => 'Na',
  :water => 'H2O',
  :ammonia => 'NH3',
  :carbon_dioxide => 'CO2',
  :acetate => 'C2H3O2',  # OAc-  # need to work out negative charge
}
CHARGE =

OAc- # need to work out negative charge

{
  :proton => 1,
  :ammonium => 1,
  :lithium => 1,
  :sodium=> 1,
  :water => 0,
  :ammonia => 0,
  :carbon_dioxide => 0,
  :acetate => -1,  
}
MASSDIFFS =

determined by running formulas through Mspire::Mass.massdiff

{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, opts = {}) ⇒ Modification

if no mass or formula is given then it searches command mods for the name 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)

Parameters:

  • name (Symbol)

    the name of the mod



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/mspire/lipid/modification.rb', line 81

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

Instance Attribute Details

#chargeObject

the charge



59
60
61
# File 'lib/mspire/lipid/modification.rb', line 59

def charge
  @charge
end

#formulaObject

a MolecularFormula object



55
56
57
# File 'lib/mspire/lipid/modification.rb', line 55

def formula
  @formula
end

#massdiffObject

negative indicates a loss



57
58
59
# File 'lib/mspire/lipid/modification.rb', line 57

def massdiff
  @massdiff
end

#nameObject

as a symbol



53
54
55
# File 'lib/mspire/lipid/modification.rb', line 53

def name
  @name
end

Class Method Details

.massdiff(formula, charge, gain = true) ⇒ Object

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. Formula may be a string.



15
16
17
18
19
20
# File 'lib/mspire/lipid/modification.rb', line 15

def self.massdiff(formula, charge, gain=true)
  massdiff = Mspire::MolecularFormula[formula].mass
  massdiff -= (charge * Mspire::Mass::ELECTRON) # + charge subtracts, - charge adds
  massdiff = -massdiff unless gain
  massdiff
end

Instance Method Details

#charged_formula_stringObject Also known as: to_s



98
99
100
# File 'lib/mspire/lipid/modification.rb', line 98

def charged_formula_string
  @formula.to_s + @charge.abs.times.map { (@charge > 0) ? '+' : '-' }.join
end

#gain?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/mspire/lipid/modification.rb', line 104

def gain?
  massdiff > 0
end

#inspectObject



112
113
114
# File 'lib/mspire/lipid/modification.rb', line 112

def inspect
  "<Mod: #{to_s}>"
end

#loss?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/mspire/lipid/modification.rb', line 108

def loss?
  !gain?
end