ms-unimod 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History ADDED
@@ -0,0 +1,5 @@
1
+ == 0.1.0 / 2009-05-28
2
+
3
+ Initial release with a generator to setup a unimod
4
+ database and a task to calculate peptide masses
5
+ with variable n- and c-term modifications.
data/README ADDED
@@ -0,0 +1,35 @@
1
+ = {Ms-Unimod}[http://mspire.rubyforge.org/projects/ms-unimod]
2
+
3
+ An {Mspire}[http://mspire.rubyforge.org] library for utilizing Unimod[http://www.unimod.org].
4
+
5
+ == Description
6
+
7
+ Ms-Unimod allows easy setup of a Unimod database (using Sqlite[http://www.sqlite.org/]) that can be used to calculate the masses of peptides with modifications.
8
+
9
+ * Lighthouse[http://bahuvrihi.lighthouseapp.com/projects/16692-mspire/tickets]
10
+ * Github[http://github.com/bahuvrihi/ms-unimod/tree/master]
11
+ * {Google Group}[http://groups.google.com/group/mspire-forum]
12
+
13
+ == Usage
14
+
15
+ First generate the Unimod database:
16
+
17
+ % tap generate unimod_db
18
+
19
+ Then use the pepmass task to calculate a peptide mass, with or without n- or c-term modifications:
20
+
21
+ % tap run -- pepmass :RPPGFSPFR: --: dump
22
+ % tap run -- pepmass Acetyl:RPPGFSPFR:Hydroxyl% --: dump
23
+
24
+ == Installation
25
+
26
+ Ms-Unimod is available as a gem on RubyForge[http://rubyforge.org/projects/mspire]. Use:
27
+
28
+ % gem install ms-unimod
29
+
30
+ == Info
31
+
32
+ Copyright (c) 2008-2009, Regents of the University of Colorado.
33
+ Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/]
34
+ Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
35
+ Licence:: {MIT-Style}[link:files/MIT-LICENSE.html]
@@ -0,0 +1,85 @@
1
+ require 'molecules/calc'
2
+ require 'sqlite3'
3
+
4
+ module Ms
5
+ module Calc
6
+ # :startdoc::task a peptide mass calculator
7
+ #
8
+ # Calculates the mass of a molecule or peptide. Molecules are entered
9
+ # as simple or compound formulae; polypeptides can be specified using
10
+ # the one-letter residue codes bracketed by semicolons. The options can
11
+ # be used to alter the output (precision, mass calculation method etc.)
12
+ #
13
+ # % tap run -- pepmass H2O --: dump
14
+ # 18.0106 Da
15
+ #
16
+ # % tap run -- pepmass :RPPGFSPFR: --: dump
17
+ # 1059.56 Da
18
+ #
19
+ # Unimod modifcations may be specified by name at the polypeptide termini,
20
+ # provided a unimod database is available. Use '%' signs as in a SQL
21
+ # query to shorten the name. The Unimod generator may be used to generate
22
+ # a unimod database if needed:
23
+ #
24
+ # % tap generate unimod
25
+ # % tap run -- pepmass Acetyl:RPPGFSPFR:Hydroxyl% -p 2 --: dump
26
+ # 1117.57 Da
27
+ #
28
+ # Sequel and sqlite3-ruby must be installed for this feature to work.
29
+ #
30
+ # * Sequel[http://sequel.rubyforge.org/rdoc/]
31
+ # * sqlite3-ruby[http://rubyforge.org/projects/sqlite-ruby/]
32
+ #
33
+ class Pepmass < Molecules::Calc
34
+ EmpiricalFormula = Molecules::EmpiricalFormula
35
+ WATER = EmpiricalFormula.parse "H2O"
36
+
37
+ config :unimod, 'unimod.sqlite' # the path to the unimod database
38
+
39
+ # Formulates a query for a modification matching code_name
40
+ # for the unimod database. If the code_name contains a '%'
41
+ # then the query will use a LIKE syntax, otherwise the
42
+ # code_name will be searced for exactly.
43
+ def mod_query(code_name)
44
+ # should do a rails-like escape on code_name
45
+ "SELECT code_name, composition FROM modifications WHERE code_name #{code_name.include?('%') ? 'LIKE' : '='} '#{code_name}'"
46
+ end
47
+
48
+ # Attempts to find and instantiate an EmpiricalFormula for
49
+ # a unimod modification matching code_name.
50
+ def find_mod(code_name)
51
+ raise ArgumentError, "the unimod database does not exist" unless File.exists?(unimod)
52
+
53
+ results = []
54
+ db = SQLite3::Database.new(unimod)
55
+ db.execute(mod_query(code_name)) do |row|
56
+ results << row
57
+ end
58
+ db.close
59
+
60
+ case results.length
61
+ when 1 then EmpiricalFormula.parse_simple(results[0][1])
62
+ when 0 then raise "could not find modification: #{code_name}"
63
+ else raise ArgumentError, "multiple modifications found for: '#{code_name}' (#{results.collect {|result| result[0]}.join(', ')})"
64
+ end
65
+ end
66
+
67
+ # Parses the formula string into an EmpiricalFormula.
68
+ # Can be used as a hook for more complicated formulae
69
+ # in subclases.
70
+ def parse(formula)
71
+ EmpiricalFormula.parse(formula) do |str|
72
+ case str
73
+ when /^(.*?):([A-Z]+):?(.*)$/
74
+ peptide = Molecules::Libraries::Polypeptide.new($2) + WATER
75
+ peptide += find_mod($1) unless $1.to_s.empty?
76
+ peptide += find_mod($3) unless $3.to_s.empty?
77
+ peptide
78
+ else nil
79
+ end
80
+ end
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,61 @@
1
+ require 'open-uri'
2
+ require 'sequel'
3
+ require 'hpricot'
4
+ require 'ms/unimod'
5
+
6
+ module Ms
7
+ module Generators
8
+
9
+ # :startdoc::generator generate a new unimod database
10
+ #
11
+ # Downloads and generates a Unimod database (sqlite):
12
+ #
13
+ # % tap generate unimod
14
+ # % sqlite3 unimod.sqlite
15
+ # sqlite> select * from elements;
16
+ # 1|H|Hydrogen|1.007825035|1.00794
17
+ # 2|2H|Deuterium|2.014101779|2.014101779
18
+ # 3|Li|Lithium|7.016003|6.941
19
+ # ...
20
+ #
21
+ # The database data is downloaded from the unimod website.
22
+ #
23
+ # * {website}[http://www.unimod.org]
24
+ # * {data}[http://www.unimod.org/xml/unimod_tables.xml]
25
+ #
26
+ class UnimodDb < Tap::Generator::Base
27
+
28
+ config :uri, "http://www.unimod.org/xml/unimod_tables.xml" # the update uri
29
+
30
+ def manifest(m, database="unimod.sqlite")
31
+ m.file database do |db|
32
+ db.close
33
+ db = Sequel.sqlite(db.path)
34
+
35
+ log :get, uri
36
+ doc = Hpricot.XML(open(uri))
37
+
38
+ db.transaction do
39
+ Ms::Unimod::TABLES.each_pair do |table_name, schema|
40
+ log :create_table, table_name
41
+ db.create_table(table_name, &schema)
42
+ table = db[table_name]
43
+
44
+ rows = doc.search("unimod/#{table_name}/#{table_name}_row")
45
+ rows.each do |row|
46
+ attributes = row.attributes
47
+ record_id = attributes["record_id"]
48
+
49
+ log(:insert, record_id)
50
+ table.insert(attributes)
51
+ end
52
+ end
53
+ end
54
+
55
+ db.disconnect
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,147 @@
1
+ module Ms
2
+ module Unimod
3
+ TABLES = {}
4
+
5
+ TABLES[:alt_names] = lambda do
6
+ primary_key :record_id
7
+ integer :mod_key
8
+ string :alt_name
9
+ end
10
+
11
+ TABLES[:amino_acids] = lambda do
12
+ primary_key :record_id
13
+ string :one_letter
14
+ string :three_letter
15
+ string :full_name
16
+ integer :num_H
17
+ integer :num_C
18
+ integer :num_N
19
+ integer :num_O
20
+ integer :num_S
21
+ end
22
+
23
+ TABLES[:brick2element] = lambda do
24
+ primary_key :record_id
25
+ integer :brick_key
26
+ string :element
27
+ integer :num_element
28
+ end
29
+
30
+ TABLES[:bricks] = lambda do
31
+ primary_key :record_id
32
+ string :brick
33
+ string :full_name
34
+ end
35
+
36
+ TABLES[:classifications] = lambda do
37
+ primary_key :record_id
38
+ string :classification
39
+ end
40
+
41
+ TABLES[:elements] = lambda do
42
+ primary_key :record_id
43
+ string :element
44
+ string :full_name
45
+ decimal :mono_mass #, :precision => 12, :scale => 9, :default => 0.0, :null => false
46
+ decimal :avge_mass #, :precision => 12, :scale => 9, :default => 0.0, :null => false
47
+ end
48
+
49
+ TABLES[:fragment_comp] = lambda do
50
+ primary_key :record_id
51
+ integer :fragments_key
52
+ string :brick
53
+ integer :num_brick
54
+ end
55
+
56
+ TABLES[:fragments] = lambda do
57
+ primary_key :record_id
58
+ integer :mod_key
59
+ end
60
+
61
+ TABLES[:log] = lambda do
62
+ primary_key :record_id
63
+ datetime :timestamp
64
+ text :query
65
+ end
66
+
67
+ TABLES[:mod2brick] = lambda do
68
+ primary_key :record_id
69
+ integer :mod_key
70
+ string :brick
71
+ integer :num_brick
72
+ end
73
+
74
+ TABLES[:modifications] = lambda do
75
+ primary_key :record_id
76
+ string :full_name
77
+ string :code_name
78
+ decimal :mono_mass#,:precision => 12, :scale => 6
79
+ decimal :avge_mass#,:precision => 12, :scale => 4
80
+ string :composition
81
+ text :misc_notes
82
+ string :username_of_poster
83
+ string :group_of_poster
84
+ datetime :date_time_posted
85
+ datetime :date_time_modified
86
+ string :ex_code_name
87
+ integer :approved
88
+ end
89
+
90
+ TABLES[:neutral_losses] = lambda do
91
+ primary_key :record_id
92
+ integer :spec_key
93
+ string :brick
94
+ integer :num_brick
95
+ end
96
+
97
+ TABLES[:positions] = lambda do
98
+ primary_key :record_id
99
+ string :position
100
+ end
101
+
102
+ TABLES[:spec2nl] = lambda do
103
+ primary_key :record_id
104
+ integer :spec_key
105
+ integer :is_pep_nl
106
+ integer :is_req_pep_nl
107
+ integer :is_slave_nl
108
+ decimal :nl_mono_mass#,:precision => 12, :scale => 6
109
+ decimal :nl_avge_mass#,:precision => 12, :scale => 4
110
+ string :nl_composition
111
+ end
112
+
113
+ TABLES[:specificity] = lambda do
114
+ primary_key :record_id
115
+ integer :mod_key
116
+ string :one_letter
117
+ integer :position_key
118
+ integer :hidden
119
+ integer :spec_group
120
+ integer :classifications_key
121
+ text :misc_notes
122
+ end
123
+
124
+ TABLES[:users] = lambda do
125
+ primary_key :record_id
126
+ string :UserName
127
+ string :Password
128
+ string :GroupID
129
+ string :FullName
130
+ string :Email
131
+ end
132
+
133
+ TABLES[:xref_sources] = lambda do
134
+ primary_key :record_id
135
+ string :xref_source
136
+ end
137
+
138
+ TABLES[:xrefs] = lambda do
139
+ primary_key :record_id
140
+ integer :mod_key
141
+ integer :xref_source_key
142
+ text :xref_text
143
+ string :xref_url
144
+ end
145
+
146
+ end
147
+ end
data/tap.yml ADDED
File without changes
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ms-unimod
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Chiang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-28 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: tap
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.17.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sequel
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: molecules
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.0
44
+ version:
45
+ description:
46
+ email: simon.a.chiang@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - History
53
+ - README
54
+ files:
55
+ - lib/ms/generators/unimod_db.rb
56
+ - lib/ms/unimod.rb
57
+ - lib/ms/calc/pepmass.rb
58
+ - tap.yml
59
+ - History
60
+ - README
61
+ has_rdoc: true
62
+ homepage: http://mspire.rubyforge.org/projects/ms-unimod/
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --main
66
+ - README
67
+ - -S
68
+ - -N
69
+ - --title
70
+ - Ms-Unimod
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: mspire
88
+ rubygems_version: 1.3.1
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: Tasks to setup and utilize a Unimod database.
92
+ test_files: []
93
+