Class: Mspire::Lipid::Ion

Inherits:
Object
  • Object
show all
Includes:
Fragment
Defined in:
lib/mspire/lipid/ion.rb,
lib/mspire/lipid/ion/fragment.rb

Overview

a lipid with modifications (typically the mods give it a charge so that it can be seen in the mass spec)

Defined Under Namespace

Modules: Fragment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fragment

#predict_fragment_mzs

Constructor Details

#initialize(lipid, mods = []) ⇒ Ion

the key attribute of a query



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

def initialize(lipid, mods=[])
  @lipid = lipid
  @modifications = mods
  @mz = nil
end

Instance Attribute Details

#lipidObject

an Mspire::Lipid object



10
11
12
# File 'lib/mspire/lipid/ion.rb', line 10

def lipid
  @lipid
end

#modificationsObject

an Mspire::Lipid::Modifications object



12
13
14
# File 'lib/mspire/lipid/ion.rb', line 12

def modifications
  @modifications
end

Instance Method Details

#chargeObject



21
22
23
24
25
26
27
# File 'lib/mspire/lipid/ion.rb', line 21

def charge
  z = 0
  @modifications.each do |mod|
    z += mod.charge
  end
  z
end

#formulaObject

a MolecularFormula object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mspire/lipid/ion.rb', line 30

def formula
  _formula = @lipid.formula
  _formula = Mspire::MolecularFormula.from_any(_formula) unless _formula.is_a?(Mspire::MolecularFormula)
  modifications.each do |mod|
    if mod.gain?
      _formula += mod.formula 
    else
      _formula -= mod.formula
    end
  end
  _formula
end

#inspectObject



65
66
67
# File 'lib/mspire/lipid/ion.rb', line 65

def inspect
  "<|| Ion mz=#{mz} #{lipid.inspect} + #{modifications.map(&:inspect).join(', ')} ||>"
end

#mzObject

the unsigned m/z value



60
61
62
63
# File 'lib/mspire/lipid/ion.rb', line 60

def mz
  _mz_signed = mz_signed
  _mz_signed >= 0 ? _mz_signed : -_mz_signed
end

#mz_signedObject

value is cached



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mspire/lipid/ion.rb', line 44

def mz_signed
  return @mz if @mz
  mass = @lipid.mass
  charge = 0
  @modifications.each do |mod|
    mass += mod.massdiff 
    charge += mod.charge
  end
  if charge == 0
    @mz = nil
  else
    @mz = mass / charge
  end
end