mspire-lipidomics 0.1.5 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Jeweler::Tasks.new do |gem|
13
13
  gem.description = %Q{does lipidomics}
14
14
  gem.email = "jtprince@gmail.com"
15
15
  gem.authors = ["John T. Prince"]
16
- gem.add_dependency "mspire", ">= 0.7.8"
16
+ gem.add_dependency "mspire", "~> 0.7.17"
17
17
  gem.add_development_dependency "rubabel", ">= 0.1.0"
18
18
  gem.add_development_dependency "rspec", "~> 2.3.0"
19
19
  gem.add_development_dependency "jeweler", "~> 1.6.4"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
1
+ 0.1.8
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ puts "under development"
4
+
5
+ =begin
3
6
  require 'trollop'
4
7
  require 'ms/mzml'
5
8
  require 'ms/lipid/search'
@@ -197,3 +200,4 @@ files.each do |file|
197
200
  end
198
201
  end
199
202
  end
203
+ =end
@@ -1,4 +1,5 @@
1
1
  require 'mspire/lipid/ion/fragment'
2
+ require 'mspire/molecular_formula'
2
3
 
3
4
  module Mspire
4
5
  class Lipid
@@ -20,20 +21,27 @@ module Mspire
20
21
  def charge
21
22
  z = 0
22
23
  @modifications.each do |mod|
23
- z -= mod.charge
24
+ z += mod.charge
24
25
  end
25
26
  z
26
27
  end
27
28
 
29
+ # a MolecularFormula object
28
30
  def formula
29
- formula = lipid.formula.dup
31
+ _formula = @lipid.formula
32
+ _formula = Mspire::MolecularFormula.from_any(_formula) unless _formula.is_a?(Mspire::MolecularFormula)
30
33
  modifications.each do |mod|
31
- formula += mod.formula
34
+ if mod.gain?
35
+ _formula += mod.formula
36
+ else
37
+ _formula -= mod.formula
38
+ end
32
39
  end
33
- formula
40
+ _formula
34
41
  end
35
42
 
36
- def mz
43
+ # value is cached
44
+ def mz_signed
37
45
  return @mz if @mz
38
46
  mass = @lipid.mass
39
47
  charge = 0
@@ -48,6 +56,12 @@ module Mspire
48
56
  end
49
57
  end
50
58
 
59
+ # the unsigned m/z value
60
+ def mz
61
+ _mz_signed = mz_signed
62
+ _mz_signed >= 0 ? _mz_signed : -_mz_signed
63
+ end
64
+
51
65
  def inspect
52
66
  "<|| Ion mz=#{mz} #{lipid.inspect} + #{modifications.map(&:inspect).join(', ')} ||>"
53
67
  end
@@ -59,7 +59,7 @@ module Mspire
59
59
 
60
60
  # as a symbol
61
61
  attr_accessor :name
62
- # as a MolecularFormula object
62
+ # a MolecularFormula object
63
63
  attr_accessor :formula
64
64
  # negative indicates a loss
65
65
  attr_accessor :massdiff
@@ -73,7 +73,7 @@ module Mspire
73
73
  #
74
74
  # attributes:
75
75
  # :formula = the chemical formula, lipidmaps style ("C2H4BrO") or
76
- # any valid argument to MolecularFormula.new
76
+ # any valid argument to MolecularFormula.from_any
77
77
  # :massdiff = +/-Float
78
78
  # :charge = +/- Integer
79
79
  #
@@ -89,7 +89,7 @@ module Mspire
89
89
  @name = name
90
90
  @formula =
91
91
  if ( form_string = (opts[:formula] || FORMULAS[name]) )
92
- Mspire::MolecularFormula.new( form_string )
92
+ Mspire::MolecularFormula.from_any( form_string )
93
93
  end
94
94
  @massdiff = opts[:massdiff] || MASSDIFFS[name]
95
95
  @charge = opts[:charge] || CHARGE[name]
@@ -102,10 +102,12 @@ module Mspire
102
102
  end
103
103
  end
104
104
 
105
- def charged_formula
105
+ def charged_formula_string
106
106
  @formula.to_s + @charge.abs.times.map { (@charge > 0) ? '+' : '-' }.join
107
107
  end
108
108
 
109
+ alias_method :to_s, :charged_formula_string
110
+
109
111
  def gain?
110
112
  massdiff > 0
111
113
  end
@@ -115,7 +117,7 @@ module Mspire
115
117
  end
116
118
 
117
119
  def inspect
118
- "<Mod: #{charged_formula}>"
120
+ "<Mod: #{to_s}>"
119
121
  end
120
122
 
121
123
  end
@@ -69,7 +69,7 @@ module Mspire
69
69
  if opts.values_at(:molecular_formula_objects, :rubabel_molecules).any? || (opts[:high_res_mass] && lm_ft == :programmatic)
70
70
  lipids.each do |lipid|
71
71
  if opts[:molecular_formula_objects]
72
- lipid.formula = Mspire::MolecularFormula.new(lipid.formula)
72
+ lipid.formula = Mspire::MolecularFormula.from_string(lipid.formula)
73
73
  end
74
74
  if lm_ft == :programmatic && opts[:high_res_mass]
75
75
  lipid.mass = Mspire::Mass.formula_to_exact_mass(lipid.formula)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mspire-lipidomics"
8
- s.version = "0.1.5"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John T. Prince"]
12
- s.date = "2012-05-10"
12
+ s.date = "2012-07-10"
13
13
  s.description = "does lipidomics"
14
14
  s.email = "jtprince@gmail.com"
15
15
  s.executables = ["lipidomic-search.rb"]
@@ -56,27 +56,27 @@ Gem::Specification.new do |s|
56
56
  s.homepage = "http://github.com/princelab/mspire-lipidomics"
57
57
  s.licenses = ["MIT"]
58
58
  s.require_paths = ["lib"]
59
- s.rubygems_version = "1.8.18"
59
+ s.rubygems_version = "1.8.24"
60
60
  s.summary = "mass spectrometry based lipidomics - especially shotgun lipidomics"
61
61
 
62
62
  if s.respond_to? :specification_version then
63
63
  s.specification_version = 3
64
64
 
65
65
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_runtime_dependency(%q<mspire>, [">= 0.7.8"])
66
+ s.add_runtime_dependency(%q<mspire>, ["~> 0.7.17"])
67
67
  s.add_development_dependency(%q<rubabel>, [">= 0.1.0"])
68
68
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
69
69
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
70
70
  s.add_development_dependency(%q<rcov>, [">= 0"])
71
71
  else
72
- s.add_dependency(%q<mspire>, [">= 0.7.8"])
72
+ s.add_dependency(%q<mspire>, ["~> 0.7.17"])
73
73
  s.add_dependency(%q<rubabel>, [">= 0.1.0"])
74
74
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
75
75
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
76
76
  s.add_dependency(%q<rcov>, [">= 0"])
77
77
  end
78
78
  else
79
- s.add_dependency(%q<mspire>, [">= 0.7.8"])
79
+ s.add_dependency(%q<mspire>, ["~> 0.7.17"])
80
80
  s.add_dependency(%q<rubabel>, [">= 0.1.0"])
81
81
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
82
82
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
@@ -14,11 +14,11 @@ parser = Trollop::Parser.new do
14
14
  opt :top_n, "how many closest ions to print", :default => 3
15
15
  banner ""
16
16
  text "modifications: (at least 1 charged mod is required)"
17
- opt :lithium, "search for lithium adducts"
18
- opt :ammonium, "search for ammonium adducts"
19
- opt :proton_gain, "search for proton gain"
20
- opt :proton_loss, "search for proton loss"
21
- opt :water_loss, "if used, *all* mods are also considered with water loss"
17
+ opt :lithium, "search for i down to 1 lithium adducts", :default => 0
18
+ opt :ammonium, "search for i down to 1 ammonium adducts", :default => 0
19
+ opt :proton_gain, "search for i down to 1 proton additions", :default => 0
20
+ opt :proton_loss, "search for i down to 1 proton losses", :default => 0
21
+ opt :water_loss, "if used, *all* mods are also considered with i down to 0 water losses", :default => 0
22
22
  opt :textfile, "a text file with m/z values, one per line", :type => String
23
23
  opt :lower_bound, "use lower bound searching (requires m/z's to be in sorted order)"
24
24
  opt :sort, "sorts the m/z's"
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  CHARGED_MODS = [:lithium, :ammonium, :proton_gain, :proton_loss]
35
35
 
36
- unless CHARGED_MODS.any? {|key| opts[key] }
36
+ unless CHARGED_MODS.any? {|key| opts[key] > 0 }
37
37
  puts "*" * 78
38
38
  puts "ArgumentError: need at least one charged mod!"
39
39
  puts "*" * 78
@@ -44,9 +44,11 @@ end
44
44
  (lipidmaps, *actual_mzs) = ARGV
45
45
 
46
46
  if f=opts[:textfile]
47
- actual_mzs = IO.readlines(f).map(&:chomp).map(&:to_f)
47
+ actual_mzs = IO.readlines(f).map(&:chomp)
48
48
  end
49
49
 
50
+ actual_mzs.map!(&:to_f)
51
+
50
52
  unless actual_mzs.size > 0
51
53
  STDERR.puts "NO m/z values given!!!"
52
54
  parser.educate
@@ -55,14 +57,14 @@ end
55
57
 
56
58
  $VERBOSE = opts[:verbose]
57
59
 
58
- MSLM = Mspire::Lipid::Modification
60
+ LipidMod = Mspire::Lipid::Modification
59
61
 
60
62
  mods = {
61
- proton_gain: MSLM.new(:proton),
62
- water_loss: MSLM.new(:water, :loss => true),
63
- lithium: MSLM.new(:lithium),
64
- ammonium: MSLM.new(:ammonium),
65
- proton_loss: MSLM.new(:proton, :loss => true)
63
+ proton_gain: LipidMod.new(:proton),
64
+ water_loss: LipidMod.new(:water, :loss => true),
65
+ lithium: LipidMod.new(:lithium),
66
+ ammonium: LipidMod.new(:ammonium),
67
+ proton_loss: LipidMod.new(:proton, :loss => true)
66
68
  }
67
69
 
68
70
  lipids = Mspire::LipidMaps.parse_file(lipidmaps)
@@ -70,10 +72,12 @@ lipids = Mspire::LipidMaps.parse_file(lipidmaps)
70
72
  ions = []
71
73
  lipids.each do |lipid|
72
74
  CHARGED_MODS.each do |key|
73
- if opts[key]
74
- ions << Mspire::Lipid::Ion.new(lipid, [mods[key]])
75
- if opts[:water_loss]
76
- ions << Mspire::Lipid::Ion.new(lipid, [mods[key], mods[:water_loss]])
75
+ if opts[key] > 0
76
+ opts[key].downto(1) do |num_charge_mod|
77
+ mods_to_use = [mods[key]] * num_charge_mod
78
+ opts[:water_loss].downto(0) do |i|
79
+ ions << Mspire::Lipid::Ion.new(lipid, mods_to_use + ([mods[:water_loss]]*i))
80
+ end
77
81
  end
78
82
  end
79
83
  end
@@ -110,7 +114,7 @@ actual_mzs.each do |exp_mz|
110
114
  rank = i + 1
111
115
  ppm = ((exp_mz - ion.mz) / ion.mz) * 1e6
112
116
  lipid = ion.lipid
113
- row.push( rank, ppm, ppm.abs, lipid.category, lipid.lm_id, lipid.common_name, ion.modifications.map(&:charged_formula).join(", ") )
117
+ row.push( rank, ppm, ppm.abs, lipid.category, lipid.lm_id, lipid.common_name, ion.modifications.map(&:charged_formula_string).join(", ") )
114
118
  end
115
119
  puts row.join("\t")
116
120
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  require 'mspire/lipid'
5
4
  require 'mspire/lipid/modification'
6
5
  require 'mspire/lipid/ion'
@@ -15,17 +14,29 @@ end
15
14
  describe Mspire::Lipid::Ion do
16
15
 
17
16
  before do
18
- lipid = Mspire::Lipid.new
19
- lipid.mass = 300.2
17
+ lipid = Mspire::Lipid.new("LMGP02010009", "PE(16:0/18:1(9Z))", "1-hexadecanoyl-2-(9Z-octadecenoyl)-sn-glycero-3-phosphoethanolamine", 'C39H76NO8P', 717.5308, 'Glycerophospholipids [GP]', 'Glycerophosphoethanolamines [GP02]', 'Diacylglycerophosphoethanolamines [GP0201]', '7850611', 'FHQVHHIBKUMWTI-OTMQOFQLSA-N')
20
18
  proton = Mspire::Lipid::Modification.new(:proton)
19
+ proton_loss = Mspire::Lipid::Modification.new(:proton, :loss => true)
21
20
  h2o_loss = Mspire::Lipid::Modification.new(:water, :loss => true)
22
- @plus1 = Mspire::Lipid::Ion.new(lipid, [proton, h2o_loss])
23
- @plus2 = Mspire::Lipid::Ion.new(lipid, [proton, proton, h2o_loss])
21
+ @plus1_less_h20 = Mspire::Lipid::Ion.new(lipid, [proton, h2o_loss])
22
+ @plus2_less_h20 = Mspire::Lipid::Ion.new(lipid, [proton, proton, h2o_loss])
23
+ @minus1_less_h20 = Mspire::Lipid::Ion.new(lipid, [proton_loss, h2o_loss])
24
24
  end
25
25
 
26
26
  it 'calculates the correct m/z' do
27
- @plus1.mz.should be_within(1e5).of(283.196711735)
28
- @plus2.mz.should be_within(1e5).of(142.101994085)
27
+ @plus1_less_h20.mz.should be_within(1e-5).of(700.52751178307)
28
+ @plus2_less_h20.mz.should be_within(1e-5).of(350.76739412492003)
29
+ @minus1_less_h20.mz.should be_within(1e-5).of(698.5129588842301)
30
+ end
31
+
32
+ it 'calculates the correct formula' do
33
+ @plus1_less_h20.formula.to_s.should == "C39H75NO7P"
34
+ @plus1_less_h20.charge.should == 1
35
+
36
+ @plus2_less_h20.formula.to_s.should == "C39H76NO7P"
37
+ @plus2_less_h20.charge.should == 2
38
+ @minus1_less_h20.formula.to_s.should == "C39H73NO7P"
39
+ @minus1_less_h20.charge.should == -1
29
40
  end
30
41
 
31
42
  describe 'predicting ms/ms fragments' do
@@ -43,7 +54,8 @@ describe Mspire::Lipid::Ion do
43
54
  mzs.sort.should == frags.sort
44
55
  end
45
56
 
46
- it '11-methyl-9S-hydroxy-13E-hexadecenoic acid' do
57
+ # WORKING THIS GUY OUT!!!!!!
58
+ xit '11-methyl-9S-hydroxy-13E-hexadecenoic acid' do
47
59
  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]')
48
60
  ion = Mspire::Lipid::Ion.new(lipid, [MSS::PROTON_LOSS])
49
61
 
@@ -69,7 +81,6 @@ describe Mspire::Lipid::Ion do
69
81
  frags << frag1 - (MSS::H2O + MSS::CO2)
70
82
 
71
83
  mzs = ion.predict_fragment_mzs
72
- p mzs
73
84
  #mzs.sort.should == frags.sort
74
85
  end
75
86
 
@@ -1,30 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  require 'mspire/lipid/modification'
4
+ require 'mspire/lipid'
5
+ require 'mspire/lipid/ion'
4
6
 
5
7
  describe Mspire::Lipid::Modification do
6
8
  Mod = Mspire::Lipid::Modification
7
9
 
8
- it 'can create common mods easily' do
9
- # water loss
10
- water_loss = Mod.new(:water, :loss => true)
11
- water_loss.loss?.should be_true
12
- water_loss.massdiff.<(0).should be_true
13
- water_loss.charge.should == 0
14
- water_loss.charged_formula.should == 'H2O'
15
-
16
- # proton gain
17
- prot = Mod.new(:proton)
18
- prot.gain?.should be_true
19
- prot.massdiff.>(0).should be_true
20
- prot.charge.should == 1
21
- prot.charged_formula.should == 'H+'
22
-
23
- ammon = Mod.new(:ammonium)
24
- ammon.gain?.should be_true
25
- ammon.massdiff.>(0).should be_true
26
- ammon.charge.should == 1
27
- ammon.charged_formula.should == 'H4N+'
10
+ describe 'creates common mods easily' do
11
+
12
+ it 'water loss' do
13
+ water_loss = Mod.new(:water, :loss => true)
14
+ water_loss.loss?.should be_true
15
+ water_loss.massdiff.<(0).should be_true
16
+ water_loss.charge.should == 0
17
+ water_loss.charged_formula_string.should == 'H2O'
18
+ end
19
+
20
+ it 'proton gain' do
21
+ prot = Mod.new(:proton)
22
+ prot.gain?.should be_true
23
+ prot.massdiff.>(0).should be_true
24
+ prot.charge.should == 1
25
+ prot.charged_formula_string.should == 'H+'
26
+ end
27
+
28
+ it 'proton loss' do
29
+ prot_loss = Mod.new(:proton, :loss => true)
30
+ prot_loss.gain?.should be_false
31
+ prot_loss.loss?.should be_true
32
+ prot_loss.massdiff.<(0).should be_true
33
+ prot_loss.charge.should == -1
34
+ prot_loss.charged_formula_string.should == 'H-'
35
+ end
36
+
37
+ it 'ammonium gain' do
38
+ ammon = Mod.new(:ammonium)
39
+ ammon.gain?.should be_true
40
+ ammon.massdiff.>(0).should be_true
41
+ ammon.charge.should == 1
42
+ ammon.charged_formula_string.should == 'H4N+'
43
+ end
28
44
  end
29
45
 
30
46
  it 'can create custom mods' do
@@ -1,3 +1,5 @@
1
+
2
+ =begin
1
3
  require 'spec_helper'
2
4
 
3
5
  require 'mspire/lipid_maps'
@@ -77,3 +79,4 @@ describe Mspire::Lipid::Search do
77
79
  end
78
80
 
79
81
  end
82
+ =end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspire-lipidomics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mspire
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.7.8
21
+ version: 0.7.17
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.7.8
29
+ version: 0.7.17
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rubabel
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  requirements: []
157
157
  rubyforge_project:
158
- rubygems_version: 1.8.18
158
+ rubygems_version: 1.8.24
159
159
  signing_key:
160
160
  specification_version: 3
161
161
  summary: mass spectrometry based lipidomics - especially shotgun lipidomics