obo 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 179add8eb74e998aa0db59d8aa58520648d56995
4
+ data.tar.gz: 94d64cb521380eeb3fb394bb42f8dba46c81497a
5
+ SHA512:
6
+ metadata.gz: f7495d695a3c85947b3504a12965ec58b8fb8d4307aefa02263129b8580611d7f3f914d62a478e7d4185a2543fe16ff09061464e018783ea305e781e2c9eb714
7
+ data.tar.gz: ab6ec0e629f33b10df673301eb721502be9857dc99362a7551a742819fa4d69874cc794eabe354d00682b237c88c5082652c1e20c7256856b019961275b28c08
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+
36
+ # For emacs:
37
+ *~
38
+ \#*
39
+ .\#*
40
+
41
+ # For vim:
42
+ #*.swp
43
+
44
+ # For redcar:
45
+ #.redcar
46
+
47
+ # For rubinius:
48
+ #*.rbc
49
+
50
+ # Don't need lock file for gem
51
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,14 +1,9 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
3
+ gemspec
4
+
8
5
  group :development do
9
- gem "minitest", ">= 0"
10
- gem "yard", "~> 0.6.0"
11
- gem "bundler", "~> 1.0.0"
12
- gem "jeweler", "~> 1.6.0"
13
- gem "rcov", ">= 0"
6
+ gem "rake"
7
+ gem "yard"
8
+ gem "simplecov", :require => false
14
9
  end
data/README.rdoc CHANGED
@@ -1,6 +1,8 @@
1
1
  = obo
2
2
 
3
- Description goes here.
3
+ The OBO format is used to describe ontologies, commonly used in biology. The format is defined at {geneontology.org}[http://www.geneontology.org/GO.format.obo-1_2.shtml]. At the moment, the parser is pretty bare-bones and is enough for me to easily get ontologies into a db.
4
+
5
+ The parser (over)uses Enumerators to ensure that you can parse arbitrarily large files. I'm very happy to have feedback about the merits (or lack of merit) of this approach.
4
6
 
5
7
  == Contributing to obo
6
8
 
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'rubygems'
3
+ #require 'rubygems'
4
+ require 'bundler/gem_tasks'
4
5
  require 'bundler'
6
+
5
7
  begin
6
8
  Bundler.setup(:default, :development)
7
9
  rescue Bundler::BundlerError => e
@@ -9,37 +11,16 @@ rescue Bundler::BundlerError => e
9
11
  $stderr.puts "Run `bundle install` to install missing gems"
10
12
  exit e.status_code
11
13
  end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "obo"
18
- gem.homepage = "http://github.com/robsyme/obo"
19
- gem.license = "MIT"
20
- gem.summary = %Q{A parser for the OBO flat file format}
21
- gem.description = %Q{The OBO format is the text file format used by OBO-Edit, the open-source, platform-independent application for viewing and editing ontologies. The format is described here: http://www.geneontology.org/GO.format.obo-1_2.shtml}
22
- gem.email = "rob.syme@gmail.com"
23
- gem.authors = ["robsyme"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
14
 
15
+ require 'rake'
28
16
  require 'rake/testtask'
17
+
29
18
  Rake::TestTask.new(:test) do |test|
30
19
  test.libs << 'lib' << 'test'
31
20
  test.pattern = 'test/**/test_*.rb'
32
21
  test.verbose = true
33
22
  end
34
23
 
35
- require 'rcov/rcovtask'
36
- Rcov::RcovTask.new do |test|
37
- test.libs << 'test'
38
- test.pattern = 'test/**/test_*.rb'
39
- test.verbose = true
40
- test.rcov_opts << '--exclude "gems/*"'
41
- end
42
-
43
24
  task :default => :test
44
25
 
45
26
  require 'yard'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
data/lib/obo.rb CHANGED
@@ -1,133 +1,7 @@
1
-
2
-
3
1
  module Obo
4
-
5
- class Header
6
- attr_reader :tagvalues
7
-
8
- def initialize
9
- @tagvalues = Hash.new{|h,k| h[k] = []}
10
- end
11
-
12
- def [](tag)
13
- values = @tagvalues[tag]
14
- values.length == 1 ? values.first : values
15
- end
16
-
17
- def add(tag,value)
18
- @tagvalues[tag] << value
19
- end
20
- end
21
-
22
- class Stanza
23
- attr_reader :name
24
- attr_reader :tagvalues
25
-
26
- def initialize(name)
27
- @name = name
28
- @tagvalues = Hash.new{|h,k| h[k] = []}
29
- end
30
-
31
- def [](tag)
32
- values = @tagvalues[tag]
33
- case values.length
34
- when 0
35
- nil
36
- when 1
37
- values.first
38
- else values
39
- end
40
- end
41
-
42
- def add(tag,value)
43
- @tagvalues[tag] << case value
44
- when 'true'
45
- true
46
- when 'false'
47
- false
48
- else value
49
- end
50
- end
51
-
52
- def method_missing(method, *args, &block)
53
- values = self[method.to_s]
54
-
55
- if values
56
- return values
57
- elsif method =~ /\?$/
58
- self.send(method[0..-2])
59
- else
60
- raise NoMethodError, "No method #{method} on #{self.class}"
61
- end
62
-
63
- end
64
- end
65
-
66
-
67
- class Parser
68
-
69
- STANZA_START = /^\[(.*?)\]/
70
- TAG_VALUE = /^(.*?):([^!]*)/
71
-
72
- def initialize(filename)
73
- @header = nil
74
- @io = File.open(filename)
75
- end
76
-
77
- def elements(io = @io)
78
- Enumerator.new do |yielder|
79
- header = Header.new
80
- previous_line_position = io.pos
81
- line = lines.next
82
- until line.is_a? Stanza
83
- header.add(*line)
84
- previous_line_position = io.pos
85
- line = lines.next
86
- end
87
- yielder << header
88
- io.pos = previous_line_position
89
-
90
- stanzas.each{|stanza| yielder << stanza}
91
- end
92
- end
93
-
94
- def stanzas
95
- Enumerator.new do |yielder|
96
- stanza = lines.first{|line| line.is_a? Stanza}
97
-
98
- lines.each do |line|
99
- case line
100
- when Array
101
- stanza.add(*line)
102
- when Stanza
103
- yielder << stanza
104
- stanza = line
105
- end
106
- end
107
-
108
- end
109
- end
110
-
111
- def rewind(io = @io)
112
- io.pos = 0
113
- end
114
-
115
- private
116
-
117
- # Yields lines that are either Stanza name or tag-value pairs
118
- def lines(io = @io)
119
- Enumerator.new do |yielder|
120
- while line = io.gets
121
- case line.strip
122
- when STANZA_START
123
- yielder << Stanza.new($1.strip)
124
- when TAG_VALUE
125
- yielder << [$1.strip,$2.strip]
126
- end
127
- end
128
- end
129
- end
130
-
131
- end
132
2
  end
133
3
 
4
+ require_relative 'obo/header'
5
+ require_relative 'obo/stanza'
6
+ require_relative 'obo/parser'
7
+
data/lib/obo/header.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Obo
2
+ class Header
3
+ attr_reader :tagvalues
4
+
5
+ def initialize
6
+ @tagvalues = Hash.new{|h,k| h[k] = []}
7
+ end
8
+
9
+ def [](tag)
10
+ values = @tagvalues[tag]
11
+ values.length == 1 ? values.first : values
12
+ end
13
+
14
+ def add(tag,value)
15
+ @tagvalues[tag] << value
16
+ end
17
+ end
18
+ end
19
+
data/lib/obo/parser.rb ADDED
@@ -0,0 +1,75 @@
1
+ require_relative 'header'
2
+ require_relative 'stanza'
3
+
4
+ module Obo
5
+ class Parser
6
+ STANZA_START = /^\[(.*?)\]/
7
+ TAG_VALUE = /^(.*?):([^!]*)/
8
+
9
+ def initialize(filename)
10
+ @header = nil
11
+ @io = File.open(filename)
12
+ end
13
+
14
+ def elements(io = @io)
15
+ Enumerator.new do |yielder|
16
+ header = Header.new
17
+ prev_line_position = io.pos
18
+ line = lines.next
19
+
20
+ until line.is_a? Stanza
21
+ header.add(*line)
22
+ prev_line_position = io.pos
23
+ line = lines.next
24
+ end
25
+
26
+ yielder << header
27
+ io.pos = prev_line_position
28
+
29
+ stanzas.each { |stanza| yielder << stanza }
30
+ end
31
+ end
32
+
33
+ def rewind(io = @io)
34
+ io.pos = 0
35
+ end
36
+
37
+ private
38
+
39
+ def stanzas
40
+ Enumerator.new do |yielder|
41
+ stanza = lines.first { |line| line.is_a? Stanza }
42
+
43
+ begin
44
+ while line = lines.next
45
+ case line
46
+ when Array
47
+ stanza.add(*line)
48
+ when Stanza
49
+ yielder << stanza
50
+ stanza = line
51
+ end
52
+ end
53
+ rescue StopIteration
54
+ yielder << stanza
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ # Yields lines that are either Stanza name or tag-value pairs
61
+ def lines(io = @io)
62
+ Enumerator.new do |yielder|
63
+ while line = io.gets
64
+ case line.strip
65
+ when STANZA_START
66
+ yielder << Stanza.new($1.strip)
67
+ when TAG_VALUE
68
+ yielder << [$1.strip,$2.strip]
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+
data/lib/obo/stanza.rb ADDED
@@ -0,0 +1,46 @@
1
+ module Obo
2
+ class Stanza
3
+ attr_reader :name
4
+ attr_reader :tagvalues
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ @tagvalues = Hash.new{|h,k| h[k] = []}
9
+ end
10
+
11
+ def [](tag)
12
+ values = @tagvalues[tag]
13
+ case values.length
14
+ when 0
15
+ nil
16
+ when 1
17
+ values.first
18
+ else values
19
+ end
20
+ end
21
+
22
+ def add(tag,value)
23
+ @tagvalues[tag] << case value
24
+ when 'true'
25
+ true
26
+ when 'false'
27
+ false
28
+ else value
29
+ end
30
+ end
31
+
32
+ def method_missing(method, *args, &block)
33
+ values = self[method.to_s]
34
+
35
+ if values
36
+ return values
37
+ elsif method =~ /\?$/
38
+ self.send(method[0..-2])
39
+ else
40
+ raise NoMethodError, "No method #{method} on #{self.class}"
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,3 @@
1
+ module Obo
2
+ VERSION = "0.1.3"
3
+ end
data/obo.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'obo/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "obo"
8
+ s.version = Obo::VERSION
9
+ s.authors = ["Robert Syme", "Darren Oakley"]
10
+ s.email = ["rob.syme@gmail.com", "daz.oakley@gmail.com"]
11
+ s.description = "The OBO format is the text file format used by OBO-Edit, the open-source, platform-independent application for viewing and editing ontologies. The format is described here: http://www.geneontology.org/GO.format.obo-1_2.shtml"
12
+ s.summary = "A parser for the OBO flat file format"
13
+ s.homepage = "http://github.com/robsyme/obo"
14
+ s.licenses = ["MIT"]
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "bundler", "~> 1.3"
22
+ end
23
+
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+
3
4
  begin
4
5
  Bundler.setup(:default, :development)
5
6
  rescue Bundler::BundlerError => e
@@ -7,8 +8,12 @@ rescue Bundler::BundlerError => e
7
8
  $stderr.puts "Run `bundle install` to install missing gems"
8
9
  exit e.status_code
9
10
  end
11
+
10
12
  require 'minitest/unit'
11
13
 
14
+ require 'simplecov'
15
+ SimpleCov.start
16
+
12
17
  $LOAD_PATH.unshift(File.dirname(__FILE__))
13
18
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
19
  require 'obo'
data/test/test_obo.rb CHANGED
@@ -2,7 +2,6 @@ require 'helper'
2
2
  require "pp"
3
3
 
4
4
  class TestObo < MiniTest::Unit::TestCase
5
-
6
5
  def setup
7
6
  @obo = Obo::Parser.new('test/data/ro.obo')
8
7
  # @obo = Obo::Parser.new('test/data/so_2_4_3.obo')
@@ -35,7 +34,17 @@ class TestObo < MiniTest::Unit::TestCase
35
34
  end
36
35
 
37
36
  def test_readthrough
38
- assert_equal 26, @obo.elements.count
37
+ assert_equal 27, @obo.elements.count
38
+ end
39
+
40
+ def test_term_extraction
41
+ typedefs = []
42
+
43
+ @obo.elements.each do |elm|
44
+ typedefs << elm
45
+ end
46
+
47
+ assert_equal 26, typedefs.select { |e| e.class == Obo::Stanza && e.name == "Typedef" }.size
39
48
  end
40
49
 
41
50
  def test_rewind
@@ -43,9 +52,8 @@ class TestObo < MiniTest::Unit::TestCase
43
52
  @obo.elements.count
44
53
  assert_raises(StopIteration){@obo.elements.count}
45
54
  @obo.rewind
46
- assert_equal 26, @obo.elements.count
55
+ assert_equal 27, @obo.elements.count
47
56
  end
48
-
49
57
  end
50
58
 
51
59
 
metadata CHANGED
@@ -1,127 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: obo
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
6
5
  platform: ruby
7
- authors:
8
- - robsyme
6
+ authors:
7
+ - Robert Syme
8
+ - Darren Oakley
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-05-24 00:00:00 +08:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: minitest
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- type: :development
25
- prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: yard
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: 0.6.0
35
- type: :development
36
- prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
39
15
  name: bundler
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
43
18
  - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 1.0.0
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
46
21
  type: :development
47
22
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: jeweler
51
- requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
54
25
  - - ~>
55
- - !ruby/object:Gem::Version
56
- version: 1.6.0
57
- type: :development
58
- prerelease: false
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
61
- name: rcov
62
- requirement: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
68
- type: :development
69
- prerelease: false
70
- version_requirements: *id005
71
- description: "The OBO format is the text file format used by OBO-Edit, the open-source, platform-independent application for viewing and editing ontologies. The format is described here: http://www.geneontology.org/GO.format.obo-1_2.shtml"
72
- email: rob.syme@gmail.com
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ description: 'The OBO format is the text file format used by OBO-Edit, the open-source,
29
+ platform-independent application for viewing and editing ontologies. The format
30
+ is described here: http://www.geneontology.org/GO.format.obo-1_2.shtml'
31
+ email:
32
+ - rob.syme@gmail.com
33
+ - daz.oakley@gmail.com
73
34
  executables: []
74
-
75
35
  extensions: []
76
-
77
- extra_rdoc_files:
78
- - LICENSE.txt
79
- - README.rdoc
80
- files:
36
+ extra_rdoc_files: []
37
+ files:
81
38
  - .document
39
+ - .gitignore
82
40
  - Gemfile
83
- - Gemfile.lock
84
41
  - LICENSE.txt
85
42
  - README.rdoc
86
43
  - Rakefile
87
44
  - VERSION
88
45
  - lib/obo.rb
46
+ - lib/obo/header.rb
47
+ - lib/obo/parser.rb
48
+ - lib/obo/stanza.rb
49
+ - lib/obo/version.rb
50
+ - obo.gemspec
89
51
  - test/data/ro.obo
90
52
  - test/data/so_2_4_3.obo
91
53
  - test/data/temp
92
54
  - test/data/testfile.txt
93
55
  - test/helper.rb
94
56
  - test/test_obo.rb
95
- has_rdoc: true
96
57
  homepage: http://github.com/robsyme/obo
97
- licenses:
58
+ licenses:
98
59
  - MIT
60
+ metadata: {}
99
61
  post_install_message:
100
62
  rdoc_options: []
101
-
102
- require_paths:
63
+ require_paths:
103
64
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: -3947284209714185762
110
- segments:
111
- - 0
112
- version: "0"
113
- required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: "0"
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
119
75
  requirements: []
120
-
121
76
  rubyforge_project:
122
- rubygems_version: 1.5.0
77
+ rubygems_version: 2.0.0.rc.2
123
78
  signing_key:
124
- specification_version: 3
79
+ specification_version: 4
125
80
  summary: A parser for the OBO flat file format
126
- test_files: []
127
-
81
+ test_files:
82
+ - test/data/ro.obo
83
+ - test/data/so_2_4_3.obo
84
+ - test/data/temp
85
+ - test/data/testfile.txt
86
+ - test/helper.rb
87
+ - test/test_obo.rb
88
+ has_rdoc:
data/Gemfile.lock DELETED
@@ -1,22 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.6.0)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- minitest (2.1.0)
10
- rake (0.8.7)
11
- rcov (0.9.9)
12
- yard (0.6.8)
13
-
14
- PLATFORMS
15
- ruby
16
-
17
- DEPENDENCIES
18
- bundler (~> 1.0.0)
19
- jeweler (~> 1.6.0)
20
- minitest
21
- rcov
22
- yard (~> 0.6.0)