Skip to content

Commit

Permalink
began work on fragment prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
jtprince committed Apr 13, 2012
1 parent 576c317 commit 702f239
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/mspire/lipid.rb
Expand Up @@ -2,13 +2,13 @@
module Mspire
class Lipid
def self.members
[:lm_id,:common_name,:systematic_name,:formula,:mass,:category,:main_class,:sub_class]
[:lm_id,:common_name,:systematic_name,:formula,:mass,:category,:main_class,:sub_class,:smiles]
end

members.each {|mem| attr_accessor mem }

def initialize(*args)
(@lm_id,@common_name,@systematic_name,@formula,@mass,@category,@main_class,@sub_class) = args
(@lm_id,@common_name,@systematic_name,@formula,@mass,@category,@main_class,@sub_class,@smiles) = args
end

def inspect
Expand Down
10 changes: 10 additions & 0 deletions lib/mspire/lipid/ion.rb
@@ -1,3 +1,4 @@
require 'mspire/lipid/ion/fragment'

module Mspire
class Lipid
Expand All @@ -16,6 +17,14 @@ def initialize(lipid, mods=[])
@mz = nil
end

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

def mz
return @mz if @mz
mass = @lipid.mass
Expand All @@ -34,6 +43,7 @@ def mz
def inspect
"<|| Ion mz=#{mz} #{lipid.inspect} + #{modifications.map(&:inspect).join(', ')} ||>"
end

end
end
end
70 changes: 70 additions & 0 deletions lib/mspire/lipid/ion/fragment.rb
@@ -0,0 +1,70 @@

module Mspire
class Lipid

# goes from 1 to 99
CHAIN_PREFIXES = {
'meth' => 1,
'eth' => 2,
'prop' => 3,
'but' => 4,
'pent' => 5,
'hex' => 6,
'hept' => 7,
'oct' => 8,
'non' => 9,
'dec' => 10,
'undec' => 11,
'dodec' => 12,
'tridec' => 13,
'tetradec' => 14,
'pentadec' => 15,
'hexadec' => 16,
'heptadec' => 17,
'octadec' => 18,
'nonadec' => 19,
'eicos' => 20,
'heneicos' => 21,
'docos' => 22,
'tricos' => 23,
'tetracos' => 24,
'pentacos' => 25,
'hexacos' => 26,
'heptacos' => 27,
'octacos' => 28,
'nonacos' => 29
}

consistent = {
0 => '',
1 => 'hen',
2 => 'do',
3 => 'tri',
4 => 'tetra',
5 => 'penta',
6 => 'hexa',
7 => 'hepta',
8 => 'octa',
9 => 'nona',
}

(3..9).each do |tens_place|
(0..9).each do |ones_place|
key = consistent[ones_place] + consistent[tens_place] + "cont"
CHAIN_PREFIXES[key] = 10*tens_place + ones_place
end
end

class Ion
module Fragment
# predicts the MS/MS fragments for this ion
def predict_fragment_mzs
lipid.smiles
end

end

include Fragment
end
end
end
10 changes: 7 additions & 3 deletions lib/mspire/lipid/modification.rb
Expand Up @@ -84,9 +84,13 @@ def initialize(name, opts={})
@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]

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

def charged_formula
Expand Down
60 changes: 60 additions & 0 deletions spec/mspire/lipid/ion_spec.rb
Expand Up @@ -5,7 +5,15 @@
require 'mspire/lipid/modification'
require 'mspire/lipid/ion'

module MSS
CO2 = ( %w(c o o).map {|e| Mspire::Mass::MONO[e] }.reduce(:+) )
H2O = Mspire::Mass::MONO['h2o']
PROTON_LOSS = Mspire::Lipid::Modification.new(:proton, :loss => true)
end


describe Mspire::Lipid::Ion do

before do
lipid = Mspire::Lipid.new
lipid.mass = 300.2
Expand All @@ -20,4 +28,56 @@
@plus2.mz.should be_within(1e5).of(142.101994085)
end

describe 'predicting ms/ms fragments' do
describe 'predicting simple fatty acyls' do
xit 'hexadecanoic acid' do
lipid = Mspire::Lipid.new('LMFA01010001', 'Palmitic acid', 'hexadecanoic acid', 'C16H32O2', 256.24, 'Fatty Acyls [FA]', 'Fatty Acids and Conjugates [FA01]', 'Straight chain fatty acids [FA0101]')

ion = Mspire::Lipid::Ion.new(lipid, [MSS::PROTON_LOSS])
frags = [ion.mz - MSS::H2O]
frags << ion.mz - MSS::CO2
frags << ion.mz - (MSS::H2O + MSS::CO2)

mzs = ion.predict_fragment_mzs
mzs.should be_an(Array)
mzs.sort.should == frags.sort
end

it '11-methyl-9S-hydroxy-13E-hexadecenoic acid' do
lipid = Mspire::Lipid.new(nil, 'Made Up', '11-methyl-9S-hydroxy-13E-hexadecenoic acid', 'C17H32O3', 284.23514488492003, 'Fatty Acyls [FA]', 'Fatty Acids and Conjugates [FA01]', 'Branched fatty acids [FA0102]')
ion = Mspire::Lipid::Ion.new(lipid, [MSS::PROTON_LOSS])

# one water loss
frags = [ion.mz - MSS::H2O]

# two water loss
frags << (ion.mz - (2*MSS::H2O))

# CO2 loss
frags << (ion.mz - MSS::CO2)

# CO2 + H20 loss
frags << ion.mz - (MSS::H2O + MSS::CO2)

oh_frag_mass = 140.12011513268
frag1 = (ion.mz - oh_frag_mass)

frags << frag1 - MSS::H2O

frags << frag1 - MSS::CO2

frags << frag1 - (MSS::H2O + MSS::CO2)

mzs = ion.predict_fragment_mzs
p mzs
#mzs.sort.should == frags.sort
end

end

it 'predicts simple glycerophosopholipids' do
end

end

end

0 comments on commit 702f239

Please sign in to comment.