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.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +78 -0
- data/Guardfile +43 -0
- data/{README.rdoc → README.md} +13 -9
- data/Rakefile +5 -49
- data/lib/obo_parser.rb +0 -2
- data/lib/obo_parser/version.rb +3 -0
- data/lib/utilities.rb +1 -1
- data/obo_parser.gemspec +22 -51
- data/obo_parser/version.rb +0 -0
- data/spec/files/cell.obo +12417 -0
- data/spec/files/go.obo +18523 -0
- data/spec/files/hao.obo +14175 -0
- data/spec/files/obo_1.0_test.txt +12582 -0
- data/spec/files/obo_1.0_test_wo_typedefs.txt +12561 -0
- data/spec/files/tgma.obo +18522 -0
- data/spec/lib/obo_parser_spec.rb +272 -0
- data/spec/spec_helper.rb +32 -0
- metadata +128 -51
- data/test/test_obo_parser.rb +0 -268
data/test/test_obo_parser.rb
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
require 'test/unit'
|
|
2
|
-
require 'rubygems'
|
|
3
|
-
require 'ruby-debug'
|
|
4
|
-
|
|
5
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/obo_parser'))
|
|
6
|
-
|
|
7
|
-
class OboParserTest < Test::Unit::TestCase
|
|
8
|
-
def test_truth
|
|
9
|
-
assert true
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class Test_OboParserBuilder < Test::Unit::TestCase
|
|
14
|
-
def test_builder
|
|
15
|
-
b = OboParser::OboParserBuilder.new
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class Test_Regex < Test::Unit::TestCase
|
|
20
|
-
|
|
21
|
-
def test_some_regex
|
|
22
|
-
assert true
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Test_Lexer < Test::Unit::TestCase
|
|
28
|
-
|
|
29
|
-
def test_term
|
|
30
|
-
lexer = OboParser::Lexer.new("[Term]")
|
|
31
|
-
assert lexer.pop(OboParser::Tokens::Term)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_end_of_file
|
|
35
|
-
lexer = OboParser::Lexer.new(" \n\n")
|
|
36
|
-
assert lexer.pop(OboParser::Tokens::EndOfFile)
|
|
37
|
-
|
|
38
|
-
lexer = OboParser::Lexer.new("\n")
|
|
39
|
-
assert lexer.pop(OboParser::Tokens::EndOfFile)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_parse_term_stanza
|
|
43
|
-
input = '
|
|
44
|
-
id: PATO:0000015
|
|
45
|
-
name: color hue
|
|
46
|
-
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]
|
|
47
|
-
subset: attribute_slim
|
|
48
|
-
is_a: PATO:0001301'
|
|
49
|
-
lexer = OboParser::Lexer.new(input)
|
|
50
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
51
|
-
assert_equal 'id', t.tag
|
|
52
|
-
assert_equal 'PATO:0000015', t.value
|
|
53
|
-
|
|
54
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
55
|
-
assert_equal 'name', t.tag
|
|
56
|
-
assert_equal 'color hue', t.value
|
|
57
|
-
|
|
58
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
59
|
-
assert_equal 'def', t.tag
|
|
60
|
-
assert_equal '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.', t.value
|
|
61
|
-
assert_equal(['PATOC:cjm'], t.xrefs)
|
|
62
|
-
|
|
63
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
64
|
-
assert_equal 'subset', t.tag
|
|
65
|
-
assert_equal 'attribute_slim', t.value
|
|
66
|
-
|
|
67
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
68
|
-
assert_equal 'is_a', t.tag
|
|
69
|
-
assert_equal 'PATO:0001301', t.value
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_typdef
|
|
73
|
-
input = '[Typedef]
|
|
74
|
-
id: part_of
|
|
75
|
-
name: part of
|
|
76
|
-
is_transitive: true'
|
|
77
|
-
assert foo = parse_obo_file(input)
|
|
78
|
-
assert_equal 1, foo.typedefs.size
|
|
79
|
-
assert_equal 'part_of', foo.typedefs.first.id.value
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_parse_term_stanza2
|
|
83
|
-
input = '[Term]
|
|
84
|
-
id: CL:0000009
|
|
85
|
-
name: fusiform initial
|
|
86
|
-
alt_id: CL:0000274
|
|
87
|
-
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]
|
|
88
|
-
synonym: "xylem initial" RELATED []
|
|
89
|
-
synonym: "xylem mother cell" RELATED []
|
|
90
|
-
is_a: CL:0000272 ! cambial initial
|
|
91
|
-
is_a: CL:0000610 ! plant cell'
|
|
92
|
-
|
|
93
|
-
assert foo = parse_obo_file(input)
|
|
94
|
-
assert_equal 2, foo.terms.first.tags_named('synonym').size
|
|
95
|
-
assert_equal 'xylem initial', foo.terms.first.tags_named('synonym').first.value
|
|
96
|
-
assert_equal 'xylem mother cell', foo.terms.first.tags_named('synonym')[1].value
|
|
97
|
-
assert_equal 'CL:0000274', foo.terms.first.tags_named('alt_id').first.value
|
|
98
|
-
|
|
99
|
-
assert_equal 2, foo.terms.first.relationships.size
|
|
100
|
-
assert_equal(['CL:0000272', 'CL:0000610'], foo.terms.first.relationships.collect{|r| r[1]}.sort)
|
|
101
|
-
assert_equal(['is_a', 'is_a'], foo.terms.first.relationships.collect{|r| r[0]}.sort)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_parse_term
|
|
105
|
-
lexer = OboParser::Lexer.new("[Term]")
|
|
106
|
-
assert lexer.pop(OboParser::Tokens::Term)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_xref_list
|
|
110
|
-
lexer = OboParser::Lexer.new("[foo:bar, stuff:things]")
|
|
111
|
-
assert t = lexer.pop(OboParser::Tokens::XrefList)
|
|
112
|
-
assert_equal( {'foo' => 'bar', 'stuff' => 'things'} , t.value)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_relationship_tag
|
|
116
|
-
lexer = OboParser::Lexer.new("relationship: develops_from CL:0000333 ! neural crest cell")
|
|
117
|
-
assert t = lexer.pop(OboParser::Tokens::RelationshipTag)
|
|
118
|
-
assert_equal 'develops_from', t.relation
|
|
119
|
-
assert_equal 'CL:0000333', t.related_term
|
|
120
|
-
assert_equal 'relationship', t.tag
|
|
121
|
-
|
|
122
|
-
lexer = OboParser::Lexer.new("relationship: develops_from CL:0000333")
|
|
123
|
-
assert t = lexer.pop(OboParser::Tokens::RelationshipTag)
|
|
124
|
-
assert_equal 'develops_from', t.relation
|
|
125
|
-
assert_equal 'CL:0000333', t.related_term
|
|
126
|
-
assert_equal 'relationship', t.tag
|
|
127
|
-
|
|
128
|
-
lexer = OboParser::Lexer.new("is_a: CL:0000333 ! Foo")
|
|
129
|
-
assert t = lexer.pop(OboParser::Tokens::IsATag)
|
|
130
|
-
assert_equal 'is_a', t.relation
|
|
131
|
-
assert_equal 'CL:0000333', t.related_term
|
|
132
|
-
assert_equal 'Foo', t.comment
|
|
133
|
-
|
|
134
|
-
lexer = OboParser::Lexer.new("disjoint_from: CL:0000333")
|
|
135
|
-
assert t = lexer.pop(OboParser::Tokens::DisjointFromTag)
|
|
136
|
-
assert_equal 'disjoint_from', t.relation
|
|
137
|
-
assert_equal 'CL:0000333', t.related_term
|
|
138
|
-
assert_equal "", t.comment
|
|
139
|
-
|
|
140
|
-
lexer = OboParser::Lexer.new("relationship: part_of CL:0000333 ! Foo")
|
|
141
|
-
assert t = lexer.pop(OboParser::Tokens::RelationshipTag)
|
|
142
|
-
assert_equal 'part_of', t.relation
|
|
143
|
-
assert_equal 'CL:0000333', t.related_term
|
|
144
|
-
assert_equal 'Foo', t.comment
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def test_tagvaluepair
|
|
148
|
-
lexer = OboParser::Lexer.new("id: PATO:0000179")
|
|
149
|
-
assert lexer.pop(OboParser::Tokens::TagValuePair)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def test_tagvaluepair_with_comments_and_xrefs
|
|
153
|
-
lexer = OboParser::Lexer.new("def: \"The foo that is bar.\" [PATO:0000179] ! FOO! \n")
|
|
154
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
155
|
-
assert_equal 'def', t.tag
|
|
156
|
-
assert_equal 'The foo that is bar.', t.value
|
|
157
|
-
assert_equal 'FOO!', t.comment
|
|
158
|
-
assert_equal(['PATO:0000179'], t.xrefs)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def test_that_synonyms_parse
|
|
162
|
-
lexer = OboParser::Lexer.new("synonym: \"Nematoblast\" EXACT []\n")
|
|
163
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
164
|
-
assert_equal 'synonym', t.tag
|
|
165
|
-
assert_equal 'Nematoblast', t.value
|
|
166
|
-
assert_equal 'EXACT', t.qualifier
|
|
167
|
-
assert_equal nil, t.comment
|
|
168
|
-
assert_equal([], t.xrefs)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def test_that_xref_lists_parse_as_part_of_tagvalue_pair
|
|
172
|
-
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')
|
|
173
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
174
|
-
assert_equal 'def', t.tag
|
|
175
|
-
assert_equal 'Foo and the bar, and stuff, and things. More stuff, and things!', t.value
|
|
176
|
-
assert_equal(['GO_REF:0000031', 'GOC:msz', 'GOC:tfm', 'ISBN:9780781765190', 'PMID:16014527'], t.xrefs)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def test_crummy_space_filled_xrefs
|
|
180
|
-
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/ -"]')
|
|
181
|
-
assert t = lexer.pop(OboParser::Tokens::TagValuePair)
|
|
182
|
-
assert_equal 'def', t.tag
|
|
183
|
-
assert_equal 'A quality inhering in a bearer by virtue of emitting light during exposure to radiation from an external source.', t.value
|
|
184
|
-
assert_equal(['The Free Online dictionary:The Free Online dictionary'], t.xrefs)
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
class Test_Parser < Test::Unit::TestCase
|
|
190
|
-
def setup
|
|
191
|
-
@of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/obo_1.0_test.txt')) )
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def test_file_parsing
|
|
195
|
-
foo = parse_obo_file(@of)
|
|
196
|
-
assert_equal 'pato', foo.terms[0].name.value
|
|
197
|
-
assert_equal 'quality', foo.terms[1].name.value
|
|
198
|
-
assert_equal 'part_of', foo.typedefs.last.name.value
|
|
199
|
-
assert_equal 'OBO_REL:part_of', foo.typedefs.last.id.value
|
|
200
|
-
assert_equal(['PATOC:GVG'], foo.terms[1].def.xrefs)
|
|
201
|
-
assert_equal 'is_obsolete', foo.terms.first.tags_named('is_obsolete').first.tag
|
|
202
|
-
assert_equal 'true', foo.terms.first.tags_named('is_obsolete').first.value
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
def test_complex_file_parsing
|
|
206
|
-
assert of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/cell.obo')) )
|
|
207
|
-
foo = parse_obo_file(of)
|
|
208
|
-
assert_equal 'cell', foo.terms.first.name.value
|
|
209
|
-
assert_equal 'primary cell line cell', foo.terms[1].name.value
|
|
210
|
-
|
|
211
|
-
tmp = foo.terms[9].tags_named('synonym')
|
|
212
|
-
assert_equal 2, tmp.size
|
|
213
|
-
assert_equal 'xylem initial', tmp.first.value
|
|
214
|
-
assert_equal 'xylem mother cell', tmp[1].value
|
|
215
|
-
assert_equal([], tmp[1].xrefs)
|
|
216
|
-
|
|
217
|
-
assert_equal 2, foo.terms[9].relationships.size
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
def test_complex_file_parsing2
|
|
221
|
-
assert of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/hao.obo')) )
|
|
222
|
-
foo = parse_obo_file(of)
|
|
223
|
-
assert_equal 'anatomical entity', foo.terms.first.name.value
|
|
224
|
-
assert_equal 'ventral mesofurco-profurcal muscle', foo.terms[1].name.value
|
|
225
|
-
|
|
226
|
-
#tmp = foo.terms[9].tags_named('synonym')
|
|
227
|
-
#assert_equal 2, tmp.size
|
|
228
|
-
#assert_equal 'xylem initial', tmp.first.value
|
|
229
|
-
#assert_equal 'xylem mother cell', tmp[1].value
|
|
230
|
-
#assert_equal([], tmp[1].xrefs)
|
|
231
|
-
|
|
232
|
-
#assert_equal 2, foo.terms[9].relationships.size
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def test_complex_file_parsing3
|
|
236
|
-
assert of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/tgma.obo')) )
|
|
237
|
-
foo = parse_obo_file(of)
|
|
238
|
-
# assert_equal 'anatomical entity', foo.terms.first.name.value
|
|
239
|
-
# assert_equal 'ventral mesofurco-profurcal muscle', foo.terms[1].name.value
|
|
240
|
-
|
|
241
|
-
#tmp = foo.terms[9].tags_named('synonym')
|
|
242
|
-
#assert_equal 2, tmp.size
|
|
243
|
-
#assert_equal 'xylem initial', tmp.first.value
|
|
244
|
-
#assert_equal 'xylem mother cell', tmp[1].value
|
|
245
|
-
#assert_equal([], tmp[1].xrefs)
|
|
246
|
-
|
|
247
|
-
#assert_equal 2, foo.terms[9].relationships.size
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
def test_complex_file_parsing4
|
|
251
|
-
assert of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/go.obo')) )
|
|
252
|
-
foo = parse_obo_file(of)
|
|
253
|
-
assert_equal 'hemolymph', foo.terms.first.name.value
|
|
254
|
-
assert_equal 'hemocyte', foo.terms[1].name.value
|
|
255
|
-
assert_equal 1, foo.terms.first.relationships.size
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
def test_file_completes_without_typedefs
|
|
259
|
-
@of2 = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/obo_1.0_test_wo_typedefs.txt')) )
|
|
260
|
-
assert foo = parse_obo_file(@of2)
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def teardown
|
|
264
|
-
@of = nil
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
end
|
|
268
|
-
|