active_unimod_generator 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,9 @@
1
+ == 0.1.0 / 2007-12-20 revision 16
2
+
3
+ Initial release with all Unimod tables represented as
4
+ ActiveRecord models. Includes:
5
+
6
+ * a generator for creating the ActiveUnimod models
7
+ within a Rails app
8
+ * migrations to create a local Unimod database
9
+ * tasks for creating/updating the local database
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2006-2007, Regents of the University of Colorado.
2
+ Developer:: Simon Chiang, Biomolecular Structure Program, Hansen Lab
3
+ Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this
6
+ software and associated documentation files (the "Software"), to deal in the Software
7
+ without restriction, including without limitation the rights to use, copy, modify, merge,
8
+ publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
9
+ to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
+ OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,106 @@
1
+ = ActiveUnimod
2
+
3
+ ActiveRecord models for the {Unimod}[http://www.unimod.org] database.
4
+
5
+ == Description
6
+
7
+ ActiveUnimod is a generator gem containing ActiveRecord models and database migrations
8
+ to setup and utilize the Unimod database. The ActiveUnimod models implement associations
9
+ as documented in the {unimod schema}[http://www.unimod.org/pdf/unimod_schema.pdf].
10
+
11
+ ActiveUnimod is a part of the BioActive[http://rubyforge.org/projects/bioactive] project
12
+ and is not a part of Unimod itself.
13
+
14
+ === Features/Problems
15
+
16
+ - ActiveUnimod can be used to generate models within a rails project, or programatically as a gem.
17
+ - ActiveUnimod includes tasks to update a local database using the web-available {data}[http://www.unimod.org/xml/unimod_tables.xml].
18
+ - Several associations could not be implemented cleanly because they join tables based
19
+ on fields other than the primary key. (ex: the associations based on bricks.brick)
20
+
21
+ == Installation
22
+
23
+ ActiveUnimod is available as a gem on RubyForge[http://rubyforge.org/projects/bioactive]. Use:
24
+
25
+ % gem install active_unimod_generator
26
+
27
+ == Generator Usage
28
+
29
+ Use like any other generator gem:
30
+
31
+ % script/generate active_unimod
32
+
33
+ Migrate in the Unimod tables as normal:
34
+
35
+ % rake db:migrate
36
+
37
+ Update the data in the database:
38
+
39
+ % rake active_unimod:database:update
40
+
41
+ == Usage
42
+
43
+ require 'active_unimod'
44
+
45
+ # establish a connection... for instance using sqlite (see below)
46
+ ActiveRecord::Base.establish_connection(
47
+ :adapter => 'sqlite3',
48
+ :database => 'unimod')
49
+
50
+ # update the database if needed
51
+ require 'active_unimod/database'
52
+ ActiveUnimod::Database.create_tables
53
+ ActiveUnimod::Database.update_from_web
54
+
55
+ # now use the models
56
+ Classification.find_by_classification("Other glycosylation").modifications.collect do |m|
57
+ m.full_name
58
+ end.uniq
59
+
60
+ # => ["Hexose",
61
+ # "N-Acetylhexosamine",
62
+ # "N-acetylglucosamine-1-phosphoryl",
63
+ # "phosphoglycosyl-D-mannose-1-phosphoryl",
64
+ # "ADP Ribose addition",
65
+ # "Lactosylation",
66
+ # "propyl-1,2-dideoxy-2\\'-methyl-alpha-D-glucopyranoso-[2,1-d]-Delta2\\'-thiazoline"]
67
+
68
+ == Info
69
+
70
+ Copyright (c) 2006-2007, Regents of the University of Colorado.
71
+ Developer:: {Simon Chiang}[http://bahuvrihi.wordpress.com], {Biomolecular Structure Program}[http://biomol.uchsc.edu/], {Hansen Lab}[http://hsc-proteomics.uchsc.edu/hansenlab/]
72
+ Support:: CU Denver School of Medicine Deans Academic Enrichment Fund
73
+ Licence:: MIT-Style
74
+
75
+ == SQLite installation
76
+
77
+ ActiveRecord can connect to a wide variety of databases. SQLite is used
78
+ in the examples because it is the easiest to get running. Here are the
79
+ basic installation instructions.
80
+
81
+ === Install the binaries
82
+
83
+ On Mac OSX/Unix, sqlite3 is usually pre-installed. Try calling sqlite3
84
+ from a command prompt to check (see below). If it isn't installed, check the
85
+ {sqlite website}[http://www.sqlite.org/] for installation instructions.
86
+
87
+ On Windows:
88
+ # Download the sqlite3 command line program and .dll from the
89
+ {downloads page}[http://www.sqlite.org/download.html]. They
90
+ will be named like sqlite-3_version.zip and sqlitedll-3_version.zip
91
+ respectively.
92
+ # Extract/copy these files (sqlite3.exe and sqlite3.dll) into C:\ruby\bin,
93
+ or the bin directory of wherever you installed ruby.
94
+
95
+ Now you should be able to access sqlite3 from a command prompt:
96
+
97
+ % sqlite3
98
+ SQLite version 3.[version]
99
+ Enter ".help" for instructions
100
+ sqlite>
101
+
102
+ === Install the ruby bindings
103
+
104
+ % gem install sqlite3-ruby
105
+
106
+ And that's it!
@@ -0,0 +1,70 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
11
+ require 'rake/gempackagetask'
12
+ require 'active_unimod_tasks'
13
+
14
+ #
15
+ # Gem specification
16
+ #
17
+ Gem::manage_gems
18
+ spec = Gem::Specification.new do |s|
19
+ s.name = "active_unimod_generator"
20
+ s.version = "0.1.0"
21
+ s.author = "Simon Chiang"
22
+ s.email = "simon.chiang@uchsc.edu"
23
+ s.homepage = "http://rubyforge.org/projects/bioactive/active_unimod"
24
+ s.platform = Gem::Platform::RUBY
25
+ s.summary = "ActiveRecord models and database migrations for Unimod."
26
+ s.files = Dir.glob("app/models/*") + Dir.glob("{db,lib}/**/*") + ["Rakefile", "active_unimod_generator.rb"]
27
+ s.autorequire = "active_unimod"
28
+ #s.test_file = "test/active_unimod_test_suite.rb"
29
+
30
+ s.has_rdoc = true
31
+ s.extra_rdoc_files = ["README", "MIT-LICENSE", "History"]
32
+ s.rdoc_options << '--title' << 'ActiveUnimod' << '--main' << 'README'
33
+ s.add_dependency("activerecord", ">= 2.0.1")
34
+ s.add_dependency("hpricot", ">= 0.6.0")
35
+ end
36
+
37
+ pkg = Rake::GemPackageTask.new(spec) do |pkg|
38
+ pkg.need_tar = true
39
+ end
40
+
41
+ #
42
+ # documentation tasks
43
+ #
44
+
45
+ desc 'Generate documentation.'
46
+ Rake::RDocTask.new(:rdoc) do |rdoc|
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = 'Active Unimod'
49
+ rdoc.main = 'README'
50
+ rdoc.options << '--line-numbers' << '--inline-source'
51
+ rdoc.rdoc_files.concat spec.files.select {|file| File.file?(file) && file !~ /templates|Rakefile/ }
52
+ end
53
+
54
+ #
55
+ # hoe tasks
56
+ #
57
+
58
+ desc "Publish RDoc to RubyForge"
59
+ task :publish_rdoc => [:rdoc] do
60
+ require 'yaml'
61
+
62
+ config = YAML.load(File.read(File.expand_path("~/.rubyforge/user-config.yml")))
63
+ host = "#{config["username"]}@rubyforge.org"
64
+
65
+ rsync_args = "-v -c -r"
66
+ remote_dir = "/var/www/gforge-projects/bioactive/active_unimod_generator"
67
+ local_dir = "rdoc"
68
+
69
+ sh %{rsync #{rsync_args} #{local_dir}/ #{host}:#{remote_dir}}
70
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/lib/generators/active_unimod/active_unimod_generator.rb'
2
+
3
+ # Gem Generators require the generator to be available from
4
+ # a 'generators' or 'rails_generators' path, or a '_generator.rb'
5
+ # file within the gem. Like so:
6
+ #
7
+ # gems/gem_generator-0.1.0/gem_generator.rb
8
+ #
9
+ # By contrast the natural place to develop a gem is within the
10
+ # 'lib/generators' directory. When the gem generaator is loaded
11
+ # it recieves a spec that defines the path where the generator
12
+ # was found, and that path is used to discover templates, etc.
13
+ #
14
+ # This module redirects the path to the natural packaging location
15
+ # for the generator.
16
+ module RedirectSpecPath # :nodoc:
17
+ def spec=(spec)
18
+ if spec.source == :RubyGems
19
+ spec.instance_variable_set("@path", File.join(spec.path, "/lib/generators/active_unimod"))
20
+ end
21
+ super
22
+ end
23
+ end
24
+
25
+ ActiveUnimodGenerator.extend RedirectSpecPath
@@ -0,0 +1,5 @@
1
+ class AltName < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ belongs_to :modification, :foreign_key => 'mod_key'
5
+ end
@@ -0,0 +1,3 @@
1
+ class AminoAcid < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+ end
@@ -0,0 +1,3 @@
1
+ class Brick < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+ end
@@ -0,0 +1,4 @@
1
+ class Brick2element < ActiveRecord::Base
2
+ set_table_name "brick2element"
3
+ self.primary_key = "record_id"
4
+ end
@@ -0,0 +1,6 @@
1
+ class Classification < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ has_many :specificities, :foreign_key => 'classifications_key'
5
+ has_many :modifications, :through => :specificities
6
+ end
@@ -0,0 +1,3 @@
1
+ class Element < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+ end
@@ -0,0 +1,6 @@
1
+ class Fragment < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ has_many :fragment_comps, :foreign_key => 'fragments_key'
5
+ belongs_to :modification, :foreign_key => 'mod_key'
6
+ end
@@ -0,0 +1,6 @@
1
+ class FragmentComp < ActiveRecord::Base
2
+ set_table_name "fragment_comp"
3
+ self.primary_key = "record_id"
4
+
5
+ belongs_to :fragment, :foreign_key => 'fragments_key'
6
+ end
@@ -0,0 +1,4 @@
1
+ class Log < ActiveRecord::Base
2
+ set_table_name "log"
3
+ self.primary_key = "record_id"
4
+ end
@@ -0,0 +1,6 @@
1
+ class Mod2brick < ActiveRecord::Base
2
+ set_table_name "mod2brick"
3
+ self.primary_key = "record_id"
4
+
5
+ belongs_to :modification, :foreign_key => 'mod_key'
6
+ end
@@ -0,0 +1,16 @@
1
+ class Modification < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ has_many :fragments, :foreign_key => 'mod_key'
5
+ has_many :alt_names, :foreign_key => 'mod_key'
6
+
7
+ has_many :xrefs, :foreign_key => 'mod_key'
8
+ has_many :xref_sources, :through => :xrefs
9
+
10
+ has_many :mod2bricks, :foreign_key => 'mod_key'
11
+
12
+ has_many :specificities, :foreign_key => 'mod_key'
13
+ has_many :positions, :through => :specificities
14
+ has_many :classifications, :through => :specificities
15
+
16
+ end
@@ -0,0 +1,5 @@
1
+ class NeutralLoss < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ belongs_to :spec2nl, :foreign_key => 'spec_key'
5
+ end
@@ -0,0 +1,6 @@
1
+ class Position < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ has_many :specificities, :foreign_key => 'position_key'
5
+ has_many :modifications, :through => :specificities
6
+ end
@@ -0,0 +1,7 @@
1
+ class Spec2nl < ActiveRecord::Base
2
+ set_table_name "spec2nl"
3
+ self.primary_key = "record_id"
4
+
5
+ belongs_to :specificity, :foreign_key => 'spec_key'
6
+ has_many :neutral_losses, :foreign_key => 'spec_key'
7
+ end
@@ -0,0 +1,9 @@
1
+ class Specificity < ActiveRecord::Base
2
+ set_table_name "specificity"
3
+ self.primary_key = "record_id"
4
+
5
+ has_many :spec2nls, :foreign_key => 'spec_key'
6
+ belongs_to :modification, :foreign_key => 'mod_key'
7
+ belongs_to :position, :foreign_key => 'position_key'
8
+ belongs_to :classification, :foreign_key => 'classifications_key'
9
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+ end
@@ -0,0 +1,6 @@
1
+ class Xref < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ belongs_to :modification, :foreign_key => 'mod_key'
5
+ belongs_to :xref_source, :foreign_key => 'xref_source_key'
6
+ end
@@ -0,0 +1,6 @@
1
+ class XrefSource < ActiveRecord::Base
2
+ self.primary_key = "record_id"
3
+
4
+ has_many :xrefs, :foreign_key => 'xref_source_key'
5
+ has_many :modifications, :through => :xrefs
6
+ end
@@ -0,0 +1,173 @@
1
+ # == Field Definition
2
+ #
3
+ # The official Unimod database is a MYSQL database and uses several
4
+ # MYSQL-specific field definitions such as:
5
+ #
6
+ # `mono_mass` double NOT NULL default '0',
7
+ # `mono_mass` double(12,6) default NULL,
8
+ #
9
+ # Doubles are normally treated as floats in the database-independent
10
+ # definitions of migrations. This is not sufficient for several Unimod
11
+ # fields (ex mono_mass and avge_mass). When possible I've defined
12
+ # the doubles as decimals using the specified precision and scale; when
13
+ # no precision and scale are specified (as in elements) I picked values
14
+ # capable of handling the inputs from:
15
+ # http://www.unimod.org/xml/unimod_tables.xml
16
+ #
17
+ # == Indicies
18
+ #
19
+ # Unimod has a number of indicies which are all omitted in this
20
+ # migration, because a number of them have conflicting names
21
+ # that are not ok with SQLite. This may affect performance
22
+ # negatively, but portablility positively.
23
+ #
24
+
25
+ class ActiveUnimodSchema < ActiveRecord::Migration
26
+ def self.up
27
+
28
+ create_table "alt_names", :primary_key => "record_id", :force => true do |t|
29
+ t.integer "mod_key", :default => 0, :null => false
30
+ t.string "alt_name", :default => "", :null => false
31
+ end
32
+
33
+ create_table "amino_acids", :primary_key => "record_id", :force => true do |t|
34
+ t.string "one_letter", :default => "", :null => false
35
+ t.string "three_letter"
36
+ t.string "full_name"
37
+ t.integer "num_H", :limit => 6, :default => 0
38
+ t.integer "num_C", :limit => 6, :default => 0
39
+ t.integer "num_N", :limit => 6, :default => 0
40
+ t.integer "num_O", :limit => 6, :default => 0
41
+ t.integer "num_S", :limit => 6, :default => 0
42
+ end
43
+
44
+ create_table "brick2element", :primary_key => "record_id", :force => true do |t|
45
+ t.integer "brick_key", :default => 0, :null => false
46
+ t.string "element", :default => "", :null => false
47
+ t.integer "num_element", :limit => 6, :default => 1
48
+ end
49
+
50
+ create_table "bricks", :primary_key => "record_id", :force => true do |t|
51
+ t.string "brick", :default => "", :null => false
52
+ t.string "full_name"
53
+ end
54
+
55
+ create_table "classifications", :primary_key => "record_id", :force => true do |t|
56
+ t.string "classification", :default => "", :null => false
57
+ end
58
+
59
+ create_table "elements", :primary_key => "record_id", :force => true do |t|
60
+ t.string "element", :default => "", :null => false
61
+ t.string "full_name"
62
+ t.decimal "mono_mass", :precision => 12, :scale => 9, :default => 0.0, :null => false
63
+ t.decimal "avge_mass", :precision => 12, :scale => 9, :default => 0.0, :null => false
64
+ end
65
+
66
+ create_table "fragment_comp", :primary_key => "record_id", :force => true do |t|
67
+ t.integer "fragments_key", :default => 0, :null => false
68
+ t.string "brick", :default => "", :null => false
69
+ t.integer "num_brick", :limit => 6, :default => 1
70
+ end
71
+
72
+ create_table "fragments", :primary_key => "record_id", :force => true do |t|
73
+ t.integer "mod_key", :default => 0, :null => false
74
+ end
75
+
76
+ create_table "log", :primary_key => "record_id", :force => true do |t|
77
+ t.datetime "timestamp", :null => false
78
+ t.text "query"
79
+ end
80
+
81
+ create_table "mod2brick", :primary_key => "record_id", :force => true do |t|
82
+ t.integer "mod_key", :default => 0, :null => false
83
+ t.string "brick", :default => "", :null => false
84
+ t.integer "num_brick", :limit => 6, :default => 1
85
+ end
86
+
87
+ create_table "modifications", :primary_key => "record_id", :force => true do |t|
88
+ t.string "full_name", :default => "", :null => false
89
+ t.string "code_name", :default => "", :null => false
90
+ t.decimal "mono_mass", :precision => 12, :scale => 6
91
+ t.decimal "avge_mass", :precision => 12, :scale => 4
92
+ t.string "composition"
93
+ t.text "misc_notes"
94
+ t.string "username_of_poster", :default => "", :null => false
95
+ t.string "group_of_poster", :default => "", :null => false
96
+ t.datetime "date_time_posted", :null => false
97
+ t.datetime "date_time_modified", :null => false
98
+ t.string "ex_code_name"
99
+ t.integer "approved", :limit => 4, :default => 0
100
+ end
101
+
102
+ create_table "neutral_losses", :primary_key => "record_id", :force => true do |t|
103
+ t.integer "spec_key", :default => 0, :null => false
104
+ t.string "brick", :default => "", :null => false
105
+ t.integer "num_brick", :limit => 6, :default => 1
106
+ end
107
+
108
+ create_table "positions", :primary_key => "record_id", :force => true do |t|
109
+ t.string "position", :default => "", :null => false
110
+ end
111
+
112
+ create_table "spec2nl", :primary_key => "record_id", :force => true do |t|
113
+ t.integer "spec_key", :default => 0, :null => false
114
+ t.integer "is_pep_nl", :limit => 4, :default => 0
115
+ t.integer "is_req_pep_nl", :limit => 4, :default => 0
116
+ t.integer "is_slave_nl", :limit => 4, :default => 0
117
+ t.decimal "nl_mono_mass", :precision => 12, :scale => 6
118
+ t.decimal "nl_avge_mass", :precision => 12, :scale => 4
119
+ t.string "nl_composition"
120
+ end
121
+
122
+ create_table "specificity", :primary_key => "record_id", :force => true do |t|
123
+ t.integer "mod_key", :default => 0, :null => false
124
+ t.string "one_letter", :default => "", :null => false
125
+ t.integer "position_key", :default => 0, :null => false
126
+ t.integer "hidden", :limit => 4, :default => 0
127
+ t.integer "spec_group", :limit => 6, :default => 0
128
+ t.integer "classifications_key", :default => 0, :null => false
129
+ t.text "misc_notes"
130
+ end
131
+
132
+ create_table "users", :primary_key => "record_id", :force => true do |t|
133
+ t.string "UserName", :limit => 64
134
+ t.string "Password", :limit => 64
135
+ t.string "GroupID", :limit => 64
136
+ t.string "FullName"
137
+ t.string "Email"
138
+ end
139
+
140
+ create_table "xref_sources", :primary_key => "record_id", :force => true do |t|
141
+ t.string "xref_source", :default => "", :null => false
142
+ end
143
+
144
+ create_table "xrefs", :primary_key => "record_id", :force => true do |t|
145
+ t.integer "mod_key", :default => 0, :null => false
146
+ t.integer "xref_source_key", :default => 0, :null => false
147
+ t.text "xref_text"
148
+ t.string "xref_url"
149
+ end
150
+
151
+ end
152
+
153
+ def self.down
154
+ drop_table :alt_names
155
+ drop_table :amino_acids
156
+ drop_table :brick2element
157
+ drop_table :bricks
158
+ drop_table :classifications
159
+ drop_table :elements
160
+ drop_table :fragment_comp
161
+ drop_table :fragments
162
+ drop_table :log
163
+ drop_table :mod2brick
164
+ drop_table :modifications
165
+ drop_table :neutral_losses
166
+ drop_table :positions
167
+ drop_table :spec2nl
168
+ drop_table :specificity
169
+ drop_table :users
170
+ drop_table :xref_sources
171
+ drop_table :xrefs
172
+ end
173
+ end
@@ -0,0 +1,142 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of ActiveRecord to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 1) do
13
+
14
+ create_table "alt_names", :primary_key => "record_id", :force => true do |t|
15
+ t.integer "mod_key", :default => 0, :null => false
16
+ t.string "alt_name", :default => "", :null => false
17
+ end
18
+
19
+ create_table "amino_acids", :primary_key => "record_id", :force => true do |t|
20
+ t.string "one_letter", :default => "", :null => false
21
+ t.string "three_letter"
22
+ t.string "full_name"
23
+ t.integer "num_H", :limit => 6, :default => 0
24
+ t.integer "num_C", :limit => 6, :default => 0
25
+ t.integer "num_N", :limit => 6, :default => 0
26
+ t.integer "num_O", :limit => 6, :default => 0
27
+ t.integer "num_S", :limit => 6, :default => 0
28
+ end
29
+
30
+ create_table "brick2element", :primary_key => "record_id", :force => true do |t|
31
+ t.integer "brick_key", :default => 0, :null => false
32
+ t.string "element", :default => "", :null => false
33
+ t.integer "num_element", :limit => 6, :default => 1
34
+ end
35
+
36
+ create_table "bricks", :primary_key => "record_id", :force => true do |t|
37
+ t.string "brick", :default => "", :null => false
38
+ t.string "full_name"
39
+ end
40
+
41
+ create_table "classifications", :primary_key => "record_id", :force => true do |t|
42
+ t.string "classification", :default => "", :null => false
43
+ end
44
+
45
+ create_table "elements", :primary_key => "record_id", :force => true do |t|
46
+ t.string "element", :default => "", :null => false
47
+ t.string "full_name"
48
+ t.decimal "mono_mass", :precision => 12, :scale => 9, :default => 0.0, :null => false
49
+ t.decimal "avge_mass", :precision => 12, :scale => 9, :default => 0.0, :null => false
50
+ end
51
+
52
+ create_table "fragment_comp", :primary_key => "record_id", :force => true do |t|
53
+ t.integer "fragments_key", :default => 0, :null => false
54
+ t.string "brick", :default => "", :null => false
55
+ t.integer "num_brick", :limit => 6, :default => 1
56
+ end
57
+
58
+ create_table "fragments", :primary_key => "record_id", :force => true do |t|
59
+ t.integer "mod_key", :default => 0, :null => false
60
+ end
61
+
62
+ create_table "log", :primary_key => "record_id", :force => true do |t|
63
+ t.datetime "timestamp", :null => false
64
+ t.text "query"
65
+ end
66
+
67
+ create_table "mod2brick", :primary_key => "record_id", :force => true do |t|
68
+ t.integer "mod_key", :default => 0, :null => false
69
+ t.string "brick", :default => "", :null => false
70
+ t.integer "num_brick", :limit => 6, :default => 1
71
+ end
72
+
73
+ create_table "modifications", :primary_key => "record_id", :force => true do |t|
74
+ t.string "full_name", :default => "", :null => false
75
+ t.string "code_name", :default => "", :null => false
76
+ t.decimal "mono_mass", :precision => 12, :scale => 6
77
+ t.decimal "avge_mass", :precision => 12, :scale => 4
78
+ t.string "composition"
79
+ t.text "misc_notes"
80
+ t.string "username_of_poster", :default => "", :null => false
81
+ t.string "group_of_poster", :default => "", :null => false
82
+ t.datetime "date_time_posted", :null => false
83
+ t.datetime "date_time_modified", :null => false
84
+ t.string "ex_code_name"
85
+ t.integer "approved", :limit => 4, :default => 0
86
+ end
87
+
88
+ create_table "neutral_losses", :primary_key => "record_id", :force => true do |t|
89
+ t.integer "spec_key", :default => 0, :null => false
90
+ t.string "brick", :default => "", :null => false
91
+ t.integer "num_brick", :limit => 6, :default => 1
92
+ end
93
+
94
+ create_table "plugin_schema_info", :id => false, :force => true do |t|
95
+ t.string "plugin_name"
96
+ t.integer "version"
97
+ end
98
+
99
+ create_table "positions", :primary_key => "record_id", :force => true do |t|
100
+ t.string "position", :default => "", :null => false
101
+ end
102
+
103
+ create_table "spec2nl", :primary_key => "record_id", :force => true do |t|
104
+ t.integer "spec_key", :default => 0, :null => false
105
+ t.integer "is_pep_nl", :limit => 4, :default => 0
106
+ t.integer "is_req_pep_nl", :limit => 4, :default => 0
107
+ t.integer "is_slave_nl", :limit => 4, :default => 0
108
+ t.decimal "nl_mono_mass", :precision => 12, :scale => 6
109
+ t.decimal "nl_avge_mass", :precision => 12, :scale => 4
110
+ t.string "nl_composition"
111
+ end
112
+
113
+ create_table "specificity", :primary_key => "record_id", :force => true do |t|
114
+ t.integer "mod_key", :default => 0, :null => false
115
+ t.string "one_letter", :default => "", :null => false
116
+ t.integer "position_key", :default => 0, :null => false
117
+ t.integer "hidden", :limit => 4, :default => 0
118
+ t.integer "spec_group", :limit => 6, :default => 0
119
+ t.integer "classifications_key", :default => 0, :null => false
120
+ t.text "misc_notes"
121
+ end
122
+
123
+ create_table "users", :primary_key => "record_id", :force => true do |t|
124
+ t.string "UserName", :limit => 64
125
+ t.string "Password", :limit => 64
126
+ t.string "GroupID", :limit => 64
127
+ t.string "FullName"
128
+ t.string "Email"
129
+ end
130
+
131
+ create_table "xref_sources", :primary_key => "record_id", :force => true do |t|
132
+ t.string "xref_source", :default => "", :null => false
133
+ end
134
+
135
+ create_table "xrefs", :primary_key => "record_id", :force => true do |t|
136
+ t.integer "mod_key", :default => 0, :null => false
137
+ t.integer "xref_source_key", :default => 0, :null => false
138
+ t.text "xref_text"
139
+ t.string "xref_url"
140
+ end
141
+
142
+ end
@@ -0,0 +1,4 @@
1
+ require 'active_record'
2
+ Dir.glob(File.dirname(__FILE__) + "/../app/models/*").each do |model|
3
+ require model
4
+ end
@@ -0,0 +1,84 @@
1
+ require 'active_unimod'
2
+ require 'hpricot'
3
+ require 'open-uri'
4
+ require 'logger'
5
+
6
+ ActiveRecord::Base.logger ||= Logger.new('unimod_log.txt')
7
+
8
+ module ActiveUnimod
9
+
10
+ # Methods for managing a local Unimod database. Information
11
+ # normally logged by Rails will be written to 'unimod_log.txt'
12
+ # unless ActiveRecord::Base.logger is set when this file is
13
+ # required.
14
+ #
15
+ module Database
16
+ TABLES = [
17
+ AltName, AminoAcid, Brick2element, Brick, Classification,
18
+ Element, FragmentComp, Fragment, Log, Mod2brick, Modification,
19
+ NeutralLoss, Position, Spec2nl, Specificity, User, XrefSource, Xref]
20
+
21
+ module_function
22
+
23
+ # Creates the ActiveUnimod tables using the default migration (db/migrate/001_active_unimod_schema)
24
+ def create_tables(verbose=true)
25
+ ActiveRecord::Migration.verbose = verbose
26
+ ActiveRecord::Migrator.migrate(File.dirname(__FILE__) + "/../../db/migrate/")
27
+ end
28
+
29
+ # Parses the xml into ActiveUnimod records. If overwrite=true the new
30
+ # records will replace existing records by with the same id. Otherwise,
31
+ # non-existant records will be created and the existing records will
32
+ # be checked. Any inconsistent records will be collected and returned
33
+ # as an array of [new_record, existing_record] arrays.
34
+ #
35
+ # Progress is logged to logger.
36
+ #
37
+ def update_from_xml(xml, overwrite=false, logger=Logger.new($stdout))
38
+ doc = Hpricot.XML(xml)
39
+ inconsistencies = []
40
+
41
+ TABLES.each do |table|
42
+ table.transaction do
43
+ logger.add(Logger::INFO, "updating: #{table.table_name}")
44
+
45
+ rows = doc.search("unimod/#{table.table_name}/#{table.table_name}_row")
46
+ rows.each do |row|
47
+ attributes = row.attributes
48
+ id = attributes.delete("record_id")
49
+ record = table.new(attributes)
50
+ record.id = id
51
+
52
+ if table.exists?(id)
53
+ existing_record = table.find(id)
54
+ unless record.attributes == existing_record.attributes
55
+ if overwrite
56
+ logger.add(Logger::INFO, "overwritting: #{id}")
57
+ existing_record.attributes = row.attributes
58
+ existing_record.save
59
+ else
60
+ inconsistencies << [record, existing_record]
61
+ end
62
+ end
63
+ else
64
+ logger.add(Logger::INFO, "adding: #{id}")
65
+ record.save
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ inconsistencies
72
+ end
73
+
74
+ # Retrieves the unimod_tables.xml from "http://www.unimod.org/xml/unimod_tables.xml"
75
+ # and uses this datafile in update_from_xml.
76
+ def update_from_web(url=nil, overwrite=false, logger=Logger.new($stdout))
77
+ url = "http://www.unimod.org/xml/unimod_tables.xml" if url == nil
78
+
79
+ logger.add(Logger::INFO, "retrieving: #{url}")
80
+ update_from_xml(open(url), overwrite, logger)
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,25 @@
1
+ namespace :active_unimod do
2
+ namespace :database do
3
+
4
+ # TODO - add a flag for which way to relsove discrepancies.
5
+ desc "Updates unimod database from website."
6
+ task :update do
7
+ require File.expand_path(RAILS_ROOT + "/config/environment")
8
+ require 'active_unimod/database'
9
+
10
+ inconsistencies = ActiveUnimod::Database.update_from_web(nil, ENV["OVERWRITE"])
11
+
12
+ unless inconsistencies.empty?
13
+ require 'pp'
14
+ puts "found #{inconsistencies.length} inconsistent #{inconsistencies.length > 1 ? 'entries' : 'entry'}:"
15
+ inconsistencies.each do |record, existing|
16
+ puts "#{record.class.table_name}(#{record.id})\n expected #{PP.singleline_pp(record.attributes, "")}\n but was #{PP.singleline_pp(existing.attributes, "")}"
17
+ end
18
+
19
+ puts
20
+ puts "inconsistent entries WERE NOT updated"
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ NAME
2
+ active_unimod - allows incorporation/usage of a Unimod database
3
+
4
+ SYNOPSIS
5
+ active_unimod [path/to/rails_root (default Dir.pwd)]
6
+
7
+ DESCRIPTION
8
+ Creates models and database migrations to setup and utilize a
9
+ local Unimod database.
10
+
11
+ Included:
12
+ - Models for all the Unimod tables.
13
+ - A migration to setup these tables.
14
+ - Tests files and fixtures for each table.
15
+ - Tasks for working with the local Unimod database.
16
+ - Use options '--skip-migration' or '--skip-fixtures' to skip
17
+ installation of these components.
18
+
19
+ EXAMPLE
20
+ ./script/generate active_unimod
21
+
22
+ This will generate a the models in app/models, install unit test files,
23
+ fixtures, and a migration in db/migrate.
24
+
25
+ ./script/generate active_unimod --help
26
+
27
+ Print this help
@@ -0,0 +1,82 @@
1
+ class ActiveUnimodGenerator < Rails::Generator::Base # :nodoc:
2
+ default_options :skip_migration => false, :skip_fixtures => false
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+ @destination_root = runtime_args.shift || Dir.pwd
7
+ end
8
+
9
+ def manifest
10
+ record do |m|
11
+ m.directory "app/models"
12
+ m.directory "db/migrate"
13
+ m.directory "lib/tasks"
14
+ m.directory "test/fixtures"
15
+ m.directory "test/unit"
16
+
17
+ m.file "/../../../../lib/active_unimod_tasks.rb", "lib/tasks/active_unimod_tasks.rake"
18
+
19
+ root = File.expand_path( File.dirname(__FILE__) + "/../../../" )
20
+ Dir.glob(File.join(root, "app/models/*.rb")).each do |model_file|
21
+ model = File.basename(model_file).chomp(".rb")
22
+
23
+ m.file "/../../../../app/models/#{model}.rb", File.join('app/models', "#{model}.rb")
24
+ m.template 'unit_test.rb', File.join('test/unit', "#{model}_test.rb"), :assigns => {:class_name => model.camelize}
25
+ unless options[:skip_fixtures]
26
+ m.template 'fixtures.yml', File.join('test/fixtures', "#{model}.yml")
27
+ end
28
+ end
29
+
30
+ unless options[:skip_migration]
31
+ @migration_directory = File.join(@destination_root, 'db/migrate')
32
+ migration_file_name = "active_unimod_schema"
33
+ if migration_exists?(migration_file_name)
34
+ raise "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}"
35
+ end
36
+
37
+ m.file('/../../../../db/migrate/001_active_unimod_schema.rb', "db/migrate/#{next_migration_string}_#{migration_file_name}.rb")
38
+ end
39
+ end
40
+ end
41
+
42
+ protected
43
+
44
+ def add_options!(opt)
45
+ opt.separator ''
46
+ opt.separator 'Options:'
47
+ opt.on("--skip-migration",
48
+ "Don't generate a migration file for these models") { |v| options[:skip_migration] = v }
49
+ opt.on("--skip-fixtures",
50
+ "Don't generation a fixture file for these models") { |v| options[:skip_fixtures] = v}
51
+ end
52
+
53
+ #
54
+ # The migration_template method makes the migration
55
+ # file in the wrong place, and the workaround above requires
56
+ # these protected methods from 'rails-2.0.1\lib\commands.rb'
57
+ #
58
+ def existing_migrations(file_name)
59
+ Dir.glob("#{@migration_directory}/[0-9]*_*.rb").grep(/[0-9]+_#{file_name}.rb$/)
60
+ end
61
+
62
+ def migration_exists?(file_name)
63
+ not existing_migrations(file_name).empty?
64
+ end
65
+
66
+ def current_migration_number
67
+ Dir.glob("#{@destination_root}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path|
68
+ n = File.basename(file_path).split('_', 2).first.to_i
69
+ if n > max then n else max end
70
+ end
71
+ end
72
+
73
+ def next_migration_number
74
+ current_migration_number + 1
75
+ end
76
+
77
+ def next_migration_string(padding = 3)
78
+ "%.#{padding}d" % next_migration_number
79
+ end
80
+
81
+
82
+ end
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ # one:
4
+ # column: value
5
+ #
6
+ # two:
7
+ # column: value
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ def test_truth
6
+ assert true
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_unimod_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Chiang
8
+ autorequire: active_unimod
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2007-12-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activerecord
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.1
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hpricot
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.6.0
32
+ version:
33
+ description:
34
+ email: simon.chiang@uchsc.edu
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ - MIT-LICENSE
42
+ - History
43
+ files:
44
+ - app/models/alt_name.rb
45
+ - app/models/amino_acid.rb
46
+ - app/models/brick.rb
47
+ - app/models/brick2element.rb
48
+ - app/models/classification.rb
49
+ - app/models/element.rb
50
+ - app/models/fragment.rb
51
+ - app/models/fragment_comp.rb
52
+ - app/models/log.rb
53
+ - app/models/mod2brick.rb
54
+ - app/models/modification.rb
55
+ - app/models/neutral_loss.rb
56
+ - app/models/position.rb
57
+ - app/models/spec2nl.rb
58
+ - app/models/specificity.rb
59
+ - app/models/user.rb
60
+ - app/models/xref.rb
61
+ - app/models/xref_source.rb
62
+ - db/migrate
63
+ - db/migrate/001_active_unimod_schema.rb
64
+ - db/schema.rb
65
+ - lib/active_unimod
66
+ - lib/active_unimod/database.rb
67
+ - lib/active_unimod.rb
68
+ - lib/active_unimod_tasks.rb
69
+ - lib/generators
70
+ - lib/generators/active_unimod
71
+ - lib/generators/active_unimod/active_unimod_generator.rb
72
+ - lib/generators/active_unimod/templates
73
+ - lib/generators/active_unimod/templates/fixtures.yml
74
+ - lib/generators/active_unimod/templates/unit_test.rb
75
+ - lib/generators/active_unimod/USAGE
76
+ - Rakefile
77
+ - active_unimod_generator.rb
78
+ - README
79
+ - MIT-LICENSE
80
+ - History
81
+ has_rdoc: true
82
+ homepage: http://rubyforge.org/projects/bioactive/active_unimod
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --title
86
+ - ActiveUnimod
87
+ - --main
88
+ - README
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ version:
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 0.9.5
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: ActiveRecord models and database migrations for Unimod.
110
+ test_files: []
111
+