Class: Mspire::Lipid::Modification
- Inherits:
-
Object
- Object
- 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', }
- CHARGE =
{ :proton => 1, :ammonium => 1, :lithium => 1, :sodium=> 1, :water => 0, :ammonia => 0, :carbon_dioxide => 0, }
- 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
-
.formula_and_charge(string) ⇒ Object
given a string with a formula and charge, returns the formula portion and the charges (as a signed integer).
-
.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)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# 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 |
Instance Attribute Details
#charge ⇒ Object
the charge
73 74 75 |
# File 'lib/mspire/lipid/modification.rb', line 73 def charge @charge end |
#formula ⇒ Object
a MolecularFormula object
69 70 71 |
# File 'lib/mspire/lipid/modification.rb', line 69 def formula @formula end |
#massdiff ⇒ Object
negative indicates a loss
71 72 73 |
# File 'lib/mspire/lipid/modification.rb', line 71 def massdiff @massdiff end |
#name ⇒ Object
as a symbol
67 68 69 |
# File 'lib/mspire/lipid/modification.rb', line 67 def name @name end |
Class Method Details
.formula_and_charge(string) ⇒ Object
given a string with a formula and charge, returns the formula portion and the charges (as a signed integer)
14 15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ 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.
30 31 32 33 34 35 36 |
# 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 |
Instance Method Details
#charged_formula_string ⇒ Object Also known as: to_s
112 113 114 |
# File 'lib/mspire/lipid/modification.rb', line 112 def charged_formula_string @formula.to_s + @charge.abs.times.map { (@charge > 0) ? '+' : '-' }.join end |
#gain? ⇒ Boolean
118 119 120 |
# File 'lib/mspire/lipid/modification.rb', line 118 def gain? massdiff > 0 end |
#inspect ⇒ Object
126 127 128 |
# File 'lib/mspire/lipid/modification.rb', line 126 def inspect "<Mod: #{to_s}>" end |
#loss? ⇒ Boolean
122 123 124 |
# File 'lib/mspire/lipid/modification.rb', line 122 def loss? !gain? end |