Class: Mspire::Lipid::Modification
- Inherits:
-
MolecularFormula
- Object
- MolecularFormula
- Mspire::Lipid::Modification
- 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
-
#charge ⇒ Object
the charge.
-
#formula ⇒ Object
a MolecularFormula object.
-
#massdiff ⇒ Object
negative indicates a loss.
-
#name ⇒ Object
as a symbol.
Class Method Summary collapse
-
.massdiff(formula, charge, gain = true) ⇒ Object
calculates the mass diff.
Instance Method Summary collapse
- #charged_formula_string ⇒ Object (also: #to_s)
- #gain? ⇒ Boolean
-
#initialize(name, opts = {}) ⇒ Modification
constructor
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.
- #inspect ⇒ Object
- #loss? ⇒ Boolean
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)
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
#charge ⇒ Object
the charge
59 60 61 |
# File 'lib/mspire/lipid/modification.rb', line 59 def charge @charge end |
#formula ⇒ Object
a MolecularFormula object
55 56 57 |
# File 'lib/mspire/lipid/modification.rb', line 55 def formula @formula end |
#massdiff ⇒ Object
negative indicates a loss
57 58 59 |
# File 'lib/mspire/lipid/modification.rb', line 57 def massdiff @massdiff end |
#name ⇒ Object
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_string ⇒ Object 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
104 105 106 |
# File 'lib/mspire/lipid/modification.rb', line 104 def gain? massdiff > 0 end |
#inspect ⇒ Object
112 113 114 |
# File 'lib/mspire/lipid/modification.rb', line 112 def inspect "<Mod: #{to_s}>" end |
#loss? ⇒ Boolean
108 109 110 |
# File 'lib/mspire/lipid/modification.rb', line 108 def loss? !gain? end |