mspire-obo 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ require 'mspire/obo/group'
4
+
5
+ describe Mspire::Obo::Group do
6
+
7
+ let(:obos) { %i(ims uo).map {|key| Mspire::Obo[key] } }
8
+ subject { Mspire::Obo::Group.new(obos) }
9
+
10
+ it 'is built with Mspire::Obo objects' do
11
+ expect(subject.obos).to eq(obos)
12
+ end
13
+
14
+ describe 'making individual hashes' do
15
+
16
+ specify '#id_to_name! builds id_to_name meta hash' do
17
+ expect(subject.id_to_name!.id_to_name["UO:0000012"]).to eq "kelvin"
18
+ expect(subject.id_to_name!.id_to_name["IMS:1000013"]).to eq "unit"
19
+ end
20
+
21
+ specify '#id_to_cast! builds id_to_name meta hash' do
22
+ expect(subject.id_to_cast!.id_to_cast["UO:0000012"]).to eq false
23
+ expect(subject.id_to_cast!.id_to_cast["IMS:1001207"]).to eq :to_f
24
+ end
25
+
26
+ specify '#id_to_stanza! builds id_to_name meta hash' do
27
+ expect(subject.id_to_stanza!.id_to_stanza["UO:0000012"].class).to eq Obo::Stanza
28
+ expect(subject.id_to_stanza!.id_to_stanza["IMS:1001207"].class).to eq Obo::Stanza
29
+ end
30
+
31
+ specify '' do
32
+ expect(subject.name_to_id!.name_to_id['kelvin']).to eq "UO:0000012"
33
+ expect(subject.name_to_id!.name_to_id['unit']).to eq "UO:0000000" # <- clobbered "IMS:1000013"
34
+ end
35
+
36
+ describe 'resolving collisions with name_to_id' do
37
+ specify '#name_to_id allows lookup with namespace' do
38
+ subject.name_to_id!
39
+ expect(subject.name_to_id.class).to eq Hash
40
+ expect(subject.name_to_id['unit']).to eq "UO:0000000"
41
+ expect(subject.name_to_id('unit')).to eq "UO:0000000"
42
+ expect(subject.name_to_id("unit", 'IMS')).to eq "IMS:1000013"
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#make_all! building all hashes' do
48
+ let(:made) { subject.make_all! }
49
+
50
+ it 'builds id_to_name' do
51
+ expect(made.id_to_name["UO:0000012"]).to eq "kelvin"
52
+ expect(made.id_to_name["IMS:1000013"]).to eq "unit"
53
+ end
54
+
55
+ it 'builds id_to_cast' do
56
+ expect(made.id_to_cast["UO:0000012"]).to eq false
57
+ expect(made.id_to_cast["IMS:1001207"]).to eq :to_f
58
+ end
59
+
60
+ it 'builds id_to_stanza' do
61
+ expect(made.id_to_stanza["UO:0000012"].class).to eq Obo::Stanza
62
+ expect(made.id_to_stanza["IMS:1001207"].class).to eq Obo::Stanza
63
+ end
64
+
65
+ it "builds name_to_id, clobbering early ids when names collide (later takes precedence)" do
66
+ expect(made.name_to_id['kelvin']).to eq "UO:0000012"
67
+ expect(made.name_to_id['unit']).to eq "UO:0000000" # <- clobbered "IMS:1000013"
68
+ end
69
+ end
70
+
71
+
72
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'mspire/obo'
3
+ require 'mspire/obo/header_parser'
4
+
5
+
6
+ describe Mspire::Obo::HeaderParser do
7
+ let(:obo_file) { Mspire::Obo::DIR + "/unit.obo" }
8
+
9
+ it 'reads headers from obo files' do
10
+ header = described_class.new.header(obo_file)
11
+ {"format-version"=>["1.2"], "date"=>["12:10:2011 11:21"], "saved-by"=>["George Gkoutos"], "auto-generated-by"=>["OBO-Edit 2.1-beta13"], "subsetdef"=>["unit_group_slim \"unit group slim\"", "unit_slim \"unit slim\""], "default-namespace"=>["unit.ontology"], "namespace-id-rule"=>["* UO:$sequence(7,0,9999999)$"], "import"=>["http://purl.obolibrary.org/obo/pato.obo"]}.each do |key, expect|
12
+ expect(header.tagvalues[key]).to eq expect
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ require 'mspire/obo'
4
+
5
+
6
+ describe Mspire::Obo do
7
+
8
+ let(:bases) { %w(psi-ms unit imagingMS PSI-MOD quality) }
9
+ let(:filename) { Hash[bases.map {|base| [base, Mspire::Obo::DIR + "/#{base}.obo"] }] }
10
+
11
+ let(:normal) { /\A[\d\.]{5,10}\Z/ }# "0.9.1" or "0.91.132"
12
+ let(:date) { /\A[\d:]{8,15}\Z/ } # "09:04:2014"
13
+
14
+ describe 'the Mspire::Obo class' do
15
+ specify '#version(filename) returns the version' do
16
+ expect(Mspire::Obo.version(filename['psi-ms'])).to match(normal)
17
+ end
18
+
19
+ specify '#available returns an informative hash for each obo' do
20
+ hashes = Mspire::Obo.available
21
+ hashes.each {|hash| expect(hash.keys.sort).to eq [:full_name, :uri, :namespace, :path, :version, :key].sort }
22
+ ms_hash = hashes.find {|hash| hash[:namespace] == 'MS' }
23
+ expect(ms_hash[:full_name].split(' ').first).to eq('Proteomics')
24
+ expect(ms_hash[:uri]).to match(/psidev.*psi-ms.obo/)
25
+ expect(ms_hash[:namespace]).to eq "MS"
26
+ expect(ms_hash[:path]).to match(/.+obo\/psi-ms.obo/)
27
+ expect(ms_hash[:version]).to match normal
28
+ expect(ms_hash[:key]).to eq :ms
29
+ end
30
+
31
+ specify '#[symbol] loads an obo with a simple key symbol' do
32
+ obo = Mspire::Obo[:ms]
33
+ expect(obo.class).to eq Mspire::Obo
34
+ expect(obo.full_name.split(' ').first).to eq('Proteomics')
35
+ expect(obo.version).to match normal
36
+ expect(obo.uri).to match(/psidev.*psi-ms.obo/)
37
+ expect(obo.stanzas.size).to be > 2000
38
+ end
39
+ specify '#[symbol, false] loads an obo (no file loaded) with a simple key symbol' do
40
+ obo = Mspire::Obo[:ms, false]
41
+ expect(obo.class).to eq Mspire::Obo
42
+ expect(obo.version).to match normal
43
+ expect(obo.stanzas).to be nil
44
+ end
45
+ end
46
+
47
+ it 'can set the version from a file (only reads the header)' do
48
+ versions = bases.map do |base|
49
+ Mspire::Obo.new.set_version!(filename[base]).version
50
+ end
51
+ [normal, date, normal, normal, date].zip(versions) do |exp_re, act|
52
+ expect(act).to match(exp_re)
53
+ end
54
+ end
55
+
56
+ context 'accessing ontology information from a file' do
57
+ let(:obo) { Mspire::Obo.new(filename['psi-ms']) }
58
+
59
+ describe 'Obo::Stanza' do
60
+ it 'can properly cast values' do
61
+ hash = obo.make_id_to_stanza
62
+ expect(hash.size > 10).to eq true # check for the hash
63
+ {
64
+ 'MS:1000511' => ['1', 1],
65
+ 'MS:1000004' => ['2.2', 2.2],
66
+ 'MS:1000011' => ['2.2', '2.2'],
67
+ 'MS:1000018' => ['low to high', 'low to high'],
68
+ }.each do |id, vals|
69
+ expect( hash[id].cast(vals.first) ).to eq(vals.last)
70
+ end
71
+ end
72
+ end
73
+
74
+ it 'has no uri or full_name unless provided' do
75
+ expect([:uri, :full_name].map {|attr| obo.send(attr) }).to eq [nil,nil]
76
+ end
77
+
78
+ it 'automatically sets a version from the header information' do
79
+ normal = /\A[\d\.]{5,10}\Z/
80
+ expect(obo.version).to match(normal)
81
+ end
82
+
83
+ describe 'attr_accessor methods require hashes be built first' do
84
+ describe 'attr_accessor methods for hashes before building' do
85
+ specify 'they all yield nil' do
86
+ expect([obo.id_to_name, obo.id_to_cast, obo.id_to_stanza, obo.name_to_id]).to eq [nil].*(4)
87
+ end
88
+ end
89
+
90
+ it 'yields a hash if properly initialized' do
91
+ [obo.id_to_stanza!.id_to_stanza,
92
+ obo.id_to_name!.id_to_name,
93
+ obo.id_to_cast!.id_to_cast,
94
+ obo.name_to_id!.name_to_id].each do |hash|
95
+ expect(hash.class).to eq Hash
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'methods returning hashes' do
101
+ specify '#make_id_to_name' do
102
+ hash = obo.make_id_to_name
103
+ expect(hash.class).to eq Hash
104
+ expect(hash['MS:1000005']).to eq 'sample volume'
105
+ end
106
+ specify '#make_id_to_cast' do
107
+ hash = obo.make_id_to_cast
108
+ expect(hash.class).to eq Hash
109
+ expect(hash['MS:1000511']).to eq :to_i
110
+ expect(hash['MS:1000004']).to eq :to_f
111
+ expect(hash['MS:1000018']).to eq false
112
+ expect(hash['MS:1000032']).to eq :to_s
113
+ end
114
+ specify '#make_name_to_id' do
115
+ hash = obo.make_name_to_id
116
+ expect(hash.class).to eq Hash
117
+ expect(hash['ProteinProspector']).to eq 'MS:1002043'
118
+ end
119
+ specify '#make_id_to_stanza' do
120
+ hash = obo.make_id_to_stanza
121
+ expect(hash.class).to eq Hash
122
+ stanza = hash['MS:1001994']
123
+ expect(stanza.class).to eq Obo::Stanza
124
+ expect(stanza['name']).to eq('top hat baseline reduction')
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,20 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rspec'
5
+
6
+ #TESTFILES = File.dirname(__FILE__) + '/testfiles'
7
+
8
+ # Requires supporting files with custom matchers and macros, etc,
9
+ # in ./support/ and its subdirectories.
10
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.color_enabled = true
15
+ config.tty = true
16
+ config.formatter = :documentation # :progress, :html, :textmate
17
+ #config.formatter = :progress # :progress, :html, :textmate
18
+ end
19
+
20
+
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mspire-obo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - John T. Prince
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: obo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: andand
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.1.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.1.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.8.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.8.2
111
+ description: simplified access for obo ontology files. Builds hashes for quick lookup
112
+ of terms and finds version, etc.
113
+ email:
114
+ - jtprince@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/ext/obo.rb
125
+ - lib/mspire/obo.rb
126
+ - lib/mspire/obo/group.rb
127
+ - lib/mspire/obo/hash_provider.rb
128
+ - lib/mspire/obo/header_parser.rb
129
+ - lib/mspire/obo/version.rb
130
+ - mspire-obo.gemspec
131
+ - obo/PSI-MOD.meta
132
+ - obo/PSI-MOD.obo
133
+ - obo/imagingMS.meta
134
+ - obo/imagingMS.obo
135
+ - obo/psi-ms.meta
136
+ - obo/psi-ms.obo
137
+ - obo/quality.meta
138
+ - obo/quality.obo
139
+ - obo/unit.meta
140
+ - obo/unit.obo
141
+ - spec/mspire/obo/group_spec.rb
142
+ - spec/mspire/obo/header_parser_spec.rb
143
+ - spec/mspire/obo_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage: ''
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.2.2
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: simplified access for obo ontology files
169
+ test_files:
170
+ - spec/mspire/obo/group_spec.rb
171
+ - spec/mspire/obo/header_parser_spec.rb
172
+ - spec/mspire/obo_spec.rb
173
+ - spec/spec_helper.rb