Class: MS::Lipid::Modification

Inherits:
Object
  • Object
show all
Defined in:
lib/ms/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 => 'NH3H',
  :lithium => 'Li',
  :water => 'H2O',
}
CHARGE =
{
  :proton => 1,
  :ammonium => 1,
  :lithium => 1,
  :water => 0,
}
MASSDIFFS =

determined by running formulas through MS::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:

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)

Parameters:

  • name (Symbol)

    the name of the mod



82
83
84
85
86
87
88
89
90
# 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

Instance Attribute Details

#chargeObject

the charge



66
67
68
# File 'lib/ms/lipid/modification.rb', line 66

def charge
  @charge
end

#formulaObject

as a molecular formula



62
63
64
# File 'lib/ms/lipid/modification.rb', line 62

def formula
  @formula
end

#massdiffObject

negative indicates a loss



64
65
66
# File 'lib/ms/lipid/modification.rb', line 64

def massdiff
  @massdiff
end

#nameObject

as a symbol



60
61
62
# File 'lib/ms/lipid/modification.rb', line 60

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)



13
14
15
16
17
18
19
20
21
22
23
# 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

.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.



29
30
31
32
33
34
35
# 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

Instance Method Details

#charged_formulaObject



92
93
94
# File 'lib/ms/lipid/modification.rb', line 92

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

#gain?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/ms/lipid/modification.rb', line 96

def gain?
  massdiff > 0
end

#inspectObject



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

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

#loss?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/ms/lipid/modification.rb', line 100

def loss?
  !gain?
end