obo_parser 0.3.7 → 0.4.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.
@@ -0,0 +1,272 @@
1
+ require 'spec_helper'
2
+
3
+ describe OboParser do
4
+
5
+ context 'test builder' do
6
+ specify 'can be #new' do
7
+ expect( OboParser::OboParserBuilder.new).to be_truthy
8
+ end
9
+ end
10
+
11
+ context 'lexer' do
12
+ specify 'term' do
13
+ lexer = OboParser::Lexer.new('[Term]')
14
+ expect(lexer.pop(OboParser::Tokens::Term)).to be_truthy
15
+ end
16
+
17
+ context 'end_of_file' do
18
+ specify 'one' do
19
+ lexer = OboParser::Lexer.new(" \n\n")
20
+ expect(lexer.pop(OboParser::Tokens::EndOfFile)).to be_truthy
21
+ end
22
+
23
+ specify 'two' do
24
+ lexer = OboParser::Lexer.new("\n")
25
+ expect(lexer.pop(OboParser::Tokens::EndOfFile)).to be_truthy
26
+ end
27
+ end
28
+
29
+ context 'parse_term_stanza' do
30
+ let(:input) { '
31
+ id: PATO:0000015
32
+ name: color hue
33
+ def: "A chromatic scalar-circular quality inhering in an object that manifests in an observer by virtue of the dominant wavelength of the visible light; may be subject to fiat divisions, typically into 7 or 8 spectra." [PATOC:cjm]
34
+ subset: attribute_slim
35
+ is_a: PATO:0001301'
36
+ }
37
+ let(:lexer) { OboParser::Lexer.new(input) }
38
+
39
+ specify 'pop a number of values off' do
40
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
41
+ expect(t.tag).to eq('id')
42
+ expect(t.value).to eq('PATO:0000015')
43
+
44
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
45
+ expect(t.tag).to eq('name')
46
+ expect(t.value).to eq('color hue')
47
+
48
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
49
+ expect(t.tag).to eq('def')
50
+ expect(t.value).to eq('A chromatic scalar-circular quality inhering in an object that manifests in an observer by virtue of the dominant wavelength of the visible light; may be subject to fiat divisions, typically into 7 or 8 spectra.')
51
+ expect(t.xrefs).to eq(['PATOC:cjm'])
52
+
53
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
54
+ expect(t.tag).to eq('subset')
55
+ expect(t.value).to eq('attribute_slim')
56
+
57
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
58
+ expect(t.tag).to eq('is_a')
59
+ expect(t.value).to eq('PATO:0001301')
60
+ end
61
+ end
62
+
63
+ context 'typdef' do
64
+ let(:input) {'[Typedef]
65
+ id: part_of
66
+ name: part of
67
+ is_transitive: true'
68
+ }
69
+
70
+ specify 'parses' do
71
+ expect(foo = parse_obo_file(input)).to be_truthy
72
+ expect(foo.typedefs.size).to eq(1)
73
+ expect(foo.typedefs.first.id.value).to eq('part_of')
74
+ end
75
+ end
76
+
77
+ context 'parse_term_stanza2' do
78
+ let(:input) {'[Term]
79
+ id: CL:0000009
80
+ name: fusiform initial
81
+ alt_id: CL:0000274
82
+ def: "An elongated cell with approximately wedge-shaped ends, found in the vascular cambium, which gives rise to the elements of the axial system in the secondary vascular tissues." [ISBN:0471245208]
83
+ synonym: "xylem initial" RELATED []
84
+ synonym: "xylem mother cell" RELATED []
85
+ is_a: CL:0000272 ! cambial initial
86
+ is_a: CL:0000610 ! plant cell'
87
+ }
88
+
89
+ specify 'parsing' do
90
+ expect( t = parse_obo_file(input)).to be_truthy
91
+ expect( t.terms.first.tags_named('synonym').size).to eq(2)
92
+ expect( t.terms.first.tags_named('synonym').first.value).to eq('xylem initial')
93
+ expect( t.terms.first.tags_named('synonym')[1].value ).to eq('xylem mother cell')
94
+ expect( t.terms.first.tags_named('alt_id').first.value).to eq('CL:0000274')
95
+
96
+ expect( t.terms.first.relationships.size ).to eq(2)
97
+ expect( t.terms.first.relationships.collect{|r| r[1]}.sort).to contain_exactly('CL:0000272', 'CL:0000610')
98
+ expect( t.terms.first.relationships.collect{|r| r[0]}.sort).to contain_exactly( 'is_a', 'is_a')
99
+ end
100
+
101
+ specify 'parse_term' do
102
+ lexer = OboParser::Lexer.new("[Term]")
103
+ expect(lexer.pop(OboParser::Tokens::Term)).to be_truthy
104
+ end
105
+
106
+ specify 'xref_list' do
107
+ lexer = OboParser::Lexer.new("[foo:bar, stuff:things]")
108
+ expect(t = lexer.pop(OboParser::Tokens::XrefList)).to be_truthy
109
+ expect(t.value).to eq({'foo' => 'bar', 'stuff' => 'things'})
110
+ end
111
+ end
112
+
113
+ context 'relationship_tag' do
114
+ specify '1' do
115
+ lexer = OboParser::Lexer.new("relationship: develops_from CL:0000333 ! neural crest cell")
116
+ expect(t = lexer.pop(OboParser::Tokens::RelationshipTag)).to be_truthy
117
+ expect(t.relation).to eq('develops_from')
118
+ expect(t.related_term).to eq( 'CL:0000333')
119
+ expect(t.tag).to eq('relationship')
120
+ end
121
+
122
+ specify '2' do
123
+ lexer = OboParser::Lexer.new("relationship: develops_from CL:0000333")
124
+ expect(t = lexer.pop(OboParser::Tokens::RelationshipTag)).to be_truthy
125
+ expect(t.relation).to eq('develops_from')
126
+ expect(t.related_term).to eq( 'CL:0000333')
127
+ expect(t.tag).to eq('relationship')
128
+ end
129
+
130
+ specify '3 IsATag' do
131
+ lexer = OboParser::Lexer.new("is_a: CL:0000333 ! Foo")
132
+ expect(t = lexer.pop(OboParser::Tokens::IsATag)).to be_truthy
133
+ expect(t.relation).to eq('is_a')
134
+ expect(t.related_term).to eq( 'CL:0000333')
135
+ expect(t.comment).to eq('Foo')
136
+ end
137
+
138
+ specify '4 DisjointFromTag' do
139
+ lexer = OboParser::Lexer.new("disjoint_from: CL:0000333")
140
+ expect(t = lexer.pop(OboParser::Tokens::DisjointFromTag)).to be_truthy
141
+ expect(t.relation).to eq('disjoint_from')
142
+ expect(t.related_term).to eq( 'CL:0000333')
143
+ expect(t.comment).to eq('')
144
+ end
145
+
146
+ specify '4 RelationshipTag' do
147
+ lexer = OboParser::Lexer.new("relationship: part_of CL:0000333 ! Foo")
148
+ expect(t = lexer.pop(OboParser::Tokens::RelationshipTag)).to be_truthy
149
+ expect(t.relation).to eq('part_of')
150
+ expect(t.related_term).to eq( 'CL:0000333')
151
+ expect(t.comment).to eq('Foo')
152
+ end
153
+
154
+ specify 'tagvaluepair' do
155
+ lexer = OboParser::Lexer.new("id: PATO:0000179")
156
+ expect( lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
157
+ end
158
+
159
+ specify 'tagvaluepair_with_comments_and_xrefs' do
160
+ lexer = OboParser::Lexer.new("def: \"The foo that is bar.\" [PATO:0000179] ! FOO! \n")
161
+ expect( t = lexer.pop(OboParser::Tokens::TagValuePair) ).to be_truthy
162
+ expect( t.tag).to eq( 'def' )
163
+ expect( t.value).to eq( 'The foo that is bar.')
164
+ expect( t.comment).to eq( 'FOO!' )
165
+ expect( t.xrefs).to eq( ['PATO:0000179'] )
166
+ end
167
+
168
+ specify 'tagvaluepair_with_comments_and_xrefs' do
169
+ lexer = OboParser::Lexer.new("def: \"The foo that is bar.\" [PATO:0000179] ! FOO! \n")
170
+ expect( t = lexer.pop(OboParser::Tokens::TagValuePair) ).to be_truthy
171
+ expect( t.tag).to eq('def')
172
+ expect( t.value).to eq( 'The foo that is bar.' )
173
+ expect( t.comment).to eq( 'FOO!' )
174
+ expect( t.xrefs).to eq( ['PATO:0000179'] )
175
+ end
176
+
177
+ specify 'that_synonyms_parse' do
178
+ lexer = OboParser::Lexer.new("synonym: \"Nematoblast\" EXACT []\n")
179
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
180
+ expect(t.tag).to eq('synonym')
181
+ expect(t.value).to eq('Nematoblast')
182
+ expect(t.qualifier).to eq('EXACT')
183
+ expect(t.comment).to eq(nil)
184
+ expect(t.xrefs).to eq([])
185
+ end
186
+
187
+ specify 'that_xref_lists_parse_as_part_of_tagvalue_pair' do
188
+ lexer = OboParser::Lexer.new('def: "Foo and the bar, and stuff, and things. More stuff, and things!" [GO_REF:0000031 "Foo!" , GOC:msz {some=trailingmodifier}, GOC:tfm, ISBN:9780781765190 "Fundamental Immunology!, 6ed (Paul,ed), 2003", PMID:16014527] {qualifier=foo} ! and a comment')
189
+ expect( t = lexer.pop(OboParser::Tokens::TagValuePair) ).to be_truthy
190
+ expect(t.tag).to eq('def')
191
+ expect(t.value).to eq('Foo and the bar, and stuff, and things. More stuff, and things!')
192
+ expect(t.xrefs).to eq(['GO_REF:0000031', 'GOC:msz', 'GOC:tfm', 'ISBN:9780781765190', 'PMID:16014527'])
193
+ end
194
+
195
+ specify 'crummy_space_filled_xrefs' do
196
+ lexer = OboParser::Lexer.new('def: "A quality inhering in a bearer by virtue of emitting light during exposure to radiation from an external source." [The Free Online dictionary:The Free Online dictionary "www.thefreedictionary.com/ -"]')
197
+ expect(t = lexer.pop(OboParser::Tokens::TagValuePair)).to be_truthy
198
+ expect(t.tag).to eq('def')
199
+ expect(t.value).to eq( 'A quality inhering in a bearer by virtue of emitting light during exposure to radiation from an external source.')
200
+ expect(t.xrefs).to eq(['The Free Online dictionary:The Free Online dictionary'])
201
+ end
202
+ end
203
+ end
204
+
205
+ context 'Test_Parse' do
206
+ let(:of) { File.read(File.expand_path(File.join(File.dirname(__FILE__), '../files/obo_1.0_test.txt')) ) }
207
+ let(:foo) { parse_obo_file(of) }
208
+
209
+ specify 'file_parsing' do
210
+ expect(foo.terms[0].name.value).to eq( 'pato')
211
+ expect(foo.terms[1].name.value).to eq('quality')
212
+ expect(foo.typedefs.last.name.value).to eq('part_of')
213
+ expect( foo.typedefs.last.id.value).to eq( 'OBO_REL:part_of')
214
+ expect( foo.terms[1].def.xrefs).to eq(['PATOC:GVG'])
215
+ expect( foo.terms.first.tags_named('is_obsolete').first.tag).to eq('is_obsolete')
216
+ expect( foo.terms.first.tags_named('is_obsolete').first.value).to eq('true')
217
+ end
218
+ end
219
+
220
+ context 'complex_file_parsing' do
221
+ let(:of) { File.read(File.expand_path(File.join(File.dirname(__FILE__), '../files/cell.obo')) ) }
222
+ let(:foo) { parse_obo_file(of) }
223
+
224
+ specify 'complex_file_parsing' do
225
+ expect(foo.terms.first.name.value).to eq( 'cell' )
226
+ expect(foo.terms[1].name.value).to eq('primary cell line cell')
227
+ tmp = foo.terms[9].tags_named('synonym')
228
+ expect(tmp.size).to eq(2)
229
+ expect(tmp.first.value).to eq('xylem initial')
230
+ expect(tmp[1].value).to eq( 'xylem mother cell' )
231
+ expect(tmp[1].xrefs).to eq([])
232
+ expect(foo.terms[9].relationships.size).to eq(2)
233
+ end
234
+ end
235
+
236
+ specify 'complex_file_parsing_2' do
237
+ expect(of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../files/hao.obo')) )).to be_truthy
238
+ foo = parse_obo_file(of)
239
+ expect(foo.terms.first.name.value).to eq('anatomical entity')
240
+ expect(foo.terms[1].name.value).to eq('ventral mesofurco-profurcal muscle')
241
+ end
242
+
243
+ specify 'complex_file_parsing_3' do
244
+ expect(of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../files/tgma.obo')) ) ).to be_truthy
245
+ expect(foo = parse_obo_file(of)).to be_truthy
246
+
247
+ # assert_equal 'anatomical entity', foo.terms.first.name.value
248
+ # assert_equal 'ventral mesofurco-profurcal muscle', foo.terms[1].name.value
249
+
250
+ #tmp = foo.terms[9].tags_named('synonym')
251
+ #assert_equal 2, tmp.size
252
+ #assert_equal 'xylem initial', tmp.first.value
253
+ #assert_equal 'xylem mother cell', tmp[1].value
254
+ #assert_equal([], tmp[1].xrefs)
255
+
256
+ #assert_equal 2, foo.terms[9].relationships.size
257
+ end
258
+
259
+ specify 'complex_file_parsing4' do
260
+ expect(of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../files/go.obo')) )).to be_truthy
261
+ expect(foo = parse_obo_file(of)).to be_truthy
262
+ expect(foo.terms.first.name.value).to eq( 'hemolymph')
263
+ expect( foo.terms[1].name.value).to eq('hemocyte')
264
+ expect( foo.terms.first.relationships.size).to eq(1)
265
+ end
266
+
267
+ specify 'file_completes_without_typedefs' do
268
+ expect(of2 = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../files/obo_1.0_test_wo_typedefs.txt')) )).to be_truthy
269
+ expect(foo = parse_obo_file(of2)).to be_truthy
270
+ end
271
+
272
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.setup
4
+
5
+ require 'obo_parser'
6
+ require 'byebug'
7
+ require 'awesome_print'
8
+ require 'fileutils'
9
+
10
+ # FileUtils::mkdir_p 'tmp'
11
+
12
+ RSpec.configure do |config|
13
+
14
+ config.raise_errors_for_deprecations!
15
+
16
+ config.run_all_when_everything_filtered = false
17
+ # config.filter_run :focus
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ # config.order = 'random'
24
+
25
+ end
26
+
27
+ # def in_range(value, percentage, midpoint) #order of second and third params to be consistent with be_within
28
+ # # value is a scalar for testing against the range, percentage is a float less than 1, midpoint is the nominal center of the range
29
+ # return (value <= midpoint*(1.0 + percentage)) & (value >= midpoint*(1.0 - percentage))
30
+ # end
31
+
32
+
metadata CHANGED
@@ -1,87 +1,164 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: obo_parser
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 7
10
- version: 0.3.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
11
5
  platform: ruby
12
- authors:
13
- - mjy
6
+ authors:
7
+ - Matt Yoder
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-08-25 00:00:00 Z
19
- dependencies: []
20
-
21
- description: "Provides all-in-one object containing the contents of an OBO formatted file. OBO version 1.2 is targeted, though this should work for 1.0. "
22
- email: diapriid@gmail.com
11
+ date: 2011-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 11.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 11.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
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.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
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: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ description: 'Provides all-in-one object containing the contents of an OBO formatted
98
+ file. OBO version 1.2 is targeted, though this should work for 1.0. '
99
+ email:
100
+ - diapriid@gmail.com
23
101
  executables: []
24
-
25
102
  extensions: []
26
-
27
- extra_rdoc_files:
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".document"
106
+ - ".gitignore"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - Guardfile
28
110
  - LICENSE
29
- - README.rdoc
30
- files:
31
- - .document
32
- - LICENSE
33
- - README.rdoc
111
+ - README.md
34
112
  - Rakefile
35
113
  - VERSION
36
114
  - init.rb
37
115
  - install.rb
38
116
  - lib/lexer.rb
39
117
  - lib/obo_parser.rb
118
+ - lib/obo_parser/version.rb
40
119
  - lib/parser.rb
41
120
  - lib/tokens.rb
42
121
  - lib/utilities.rb
43
122
  - obo_parser.gemspec
123
+ - obo_parser/version.rb
124
+ - spec/files/cell.obo
125
+ - spec/files/go.obo
126
+ - spec/files/hao.obo
127
+ - spec/files/obo_1.0_test.txt
128
+ - spec/files/obo_1.0_test_wo_typedefs.txt
129
+ - spec/files/tgma.obo
130
+ - spec/lib/obo_parser_spec.rb
131
+ - spec/spec_helper.rb
44
132
  - tasks/obo_parser_tasks.rake
45
133
  - test/cell.obo
46
134
  - test/go.obo
47
135
  - test/hao.obo
48
136
  - test/obo_1.0_test.txt
49
137
  - test/obo_1.0_test_wo_typedefs.txt
50
- - test/test_obo_parser.rb
51
138
  - test/tgma.obo
52
139
  - uninstall.rb
53
140
  homepage: http://github.com/mjy/obo_parser
54
- licenses: []
55
-
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
56
144
  post_install_message:
57
145
  rdoc_options: []
58
-
59
- require_paths:
146
+ require_paths:
60
147
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
64
150
  - - ">="
65
- - !ruby/object:Gem::Version
66
- hash: 3
67
- segments:
68
- - 0
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
73
155
  - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
79
158
  requirements: []
80
-
81
159
  rubyforge_project:
82
- rubygems_version: 1.7.2
160
+ rubygems_version: 2.6.4
83
161
  signing_key:
84
- specification_version: 3
85
- summary: A simple OBO file handler.
162
+ specification_version: 4
163
+ summary: Ruby parsering for OBO files.
86
164
  test_files: []
87
-