obo_parser 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,109 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'ruby-debug'
4
+
5
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/obo_file'))
6
+
7
+ class OboParserTest < Test::Unit::TestCase
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
12
+
13
+ class Test_OboFileBuilder < Test::Unit::TestCase
14
+ def test_builder
15
+ b = OboFile::OboFileBuilder.new
16
+ end
17
+ end
18
+
19
+
20
+ class Test_Regex < Test::Unit::TestCase
21
+
22
+ def test_comment_stripping
23
+ # hackish, likely will fail with complex combinations of "!"
24
+ txt = "line without note\nBegin taxa; ! comment\n! not this line\n'this ok!'\n\"this too!!\""
25
+ r2 = Regexp.new(/(\s*?![^!'"]*?\n)/i)
26
+ assert_equal "line without note\nBegin taxa;\n\n'this ok!'\n\"this too!!\"" , txt.gsub(r2, "\n")
27
+ end
28
+ end
29
+
30
+ class Test_Lexer < Test::Unit::TestCase
31
+
32
+ def test_term
33
+ lexer = OboFile::Lexer.new("[Term]")
34
+ assert lexer.pop(OboFile::Tokens::Term)
35
+ end
36
+
37
+ def test_end_of_file
38
+ lexer = OboFile::Lexer.new(" \n\n")
39
+ assert lexer.pop(OboFile::Tokens::EndOfFile)
40
+
41
+ lexer = OboFile::Lexer.new("\n")
42
+ assert lexer.pop(OboFile::Tokens::EndOfFile)
43
+ end
44
+
45
+ def test_parse_term_stanza
46
+ input = '
47
+ id: PATO:0000015
48
+ name: color hue
49
+ 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]
50
+ subset: attribute_slim
51
+ is_a: PATO:0001301'
52
+ lexer = OboFile::Lexer.new(input)
53
+ assert t = lexer.pop(OboFile::Tokens::TagValuePair)
54
+ assert_equal 'id', t.tag
55
+ assert_equal 'PATO:0000015', t.value
56
+
57
+ assert t = lexer.pop(OboFile::Tokens::TagValuePair)
58
+ assert_equal 'name', t.tag
59
+ assert_equal 'color hue', t.value
60
+
61
+ assert t = lexer.pop(OboFile::Tokens::TagValuePair)
62
+ assert_equal 'def', t.tag
63
+ 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." [PATOC:cjm]', t.value
64
+
65
+ assert t = lexer.pop(OboFile::Tokens::TagValuePair)
66
+ assert_equal 'subset', t.tag
67
+ assert_equal 'attribute_slim', t.value
68
+
69
+ assert t = lexer.pop(OboFile::Tokens::TagValuePair)
70
+ assert_equal 'is_a', t.tag
71
+ assert_equal 'PATO:0001301', t.value
72
+ end
73
+
74
+
75
+ def test_parse_term
76
+ lexer = OboFile::Lexer.new("[Term]")
77
+ assert lexer.pop(OboFile::Tokens::Term)
78
+ end
79
+
80
+ def test_tagvaluepair
81
+ lexer = OboFile::Lexer.new("id: PATO:0000179")
82
+ assert lexer.pop(OboFile::Tokens::TagValuePair)
83
+ end
84
+ end
85
+
86
+ class Test_Parser < Test::Unit::TestCase
87
+ def setup
88
+ @of = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/obo_1.0_test.txt')) )
89
+ end
90
+
91
+ def test_file_parsing
92
+ foo = parse_obo_file(@of)
93
+ assert_equal 'pato', foo.terms[0].name
94
+ assert_equal 'quality', foo.terms[1].name
95
+ assert_equal 'part_of', foo.typedefs.last.name
96
+ assert_equal 'OBO_REL:part_of', foo.typedefs.last.id
97
+ end
98
+
99
+ def teardown
100
+ @of = nil
101
+ end
102
+
103
+ def test_file_completes_without_typedefs
104
+ @of2 = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/obo_1.0_test_wo_typedefs.txt')) )
105
+ assert foo = parse_obo_file(@of2)
106
+ end
107
+
108
+ end
109
+
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obo_parser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - mjy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-17 00:00:00 -04:00
18
+ default_executable:
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
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README
30
+ - README.rdoc
31
+ files:
32
+ - .document
33
+ - .gitignore
34
+ - LICENSE
35
+ - README
36
+ - README.rdoc
37
+ - Rakefile
38
+ - VERSION
39
+ - init.rb
40
+ - install.rb
41
+ - lib/lexer.rb
42
+ - lib/obo_file.rb
43
+ - lib/parser.rb
44
+ - lib/tokens.rb
45
+ - obo_parser.gemspec
46
+ - tasks/obo_parser_tasks.rake
47
+ - test/cell.obo
48
+ - test/obo_1.0_test.txt
49
+ - test/obo_1.0_test_wo_typedefs.txt
50
+ - test/test_obo_parser.rb
51
+ - uninstall.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/mjy/obo_parser
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.6
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: A simple OBO file handler.
82
+ test_files:
83
+ - test/test_obo_parser.rb