obo_parser 0.2.0 → 0.2.1
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.
- data/VERSION +1 -1
- data/lib/obo_parser.rb +13 -5
- data/lib/utilities.rb +118 -0
- data/obo_parser.gemspec +3 -2
- data/test/test_obo_parser.rb +0 -1
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/obo_parser.rb
CHANGED
@@ -9,24 +9,31 @@ module OboParser
|
|
9
9
|
require File.expand_path(File.join(File.dirname(__FILE__), 'tokens'))
|
10
10
|
require File.expand_path(File.join(File.dirname(__FILE__), 'parser'))
|
11
11
|
require File.expand_path(File.join(File.dirname(__FILE__), 'lexer'))
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'utilities'))
|
12
13
|
|
13
14
|
|
14
15
|
class OboParser # Node
|
15
16
|
attr_accessor :terms, :typedefs
|
16
17
|
|
17
|
-
def initialize
|
18
|
+
def initialize # :yields: true
|
18
19
|
@terms = []
|
19
20
|
@typedefs = []
|
21
|
+
true
|
20
22
|
end
|
21
23
|
|
22
|
-
def term_strings
|
24
|
+
def term_strings # :yields: Array of Strings
|
23
25
|
@terms.collect{|t| t.name}.sort
|
24
26
|
end
|
25
|
-
|
26
|
-
def term_hash
|
27
|
+
|
28
|
+
def term_hash # :yields: Hash (String => String) (name => id)
|
29
|
+
# Warning! This assumes terms are unqiue, they are not required to be so.
|
27
30
|
@terms.inject({}) {|sum, t| sum.update(t.name => t.id)}
|
28
31
|
end
|
29
|
-
|
32
|
+
|
33
|
+
def id_hash # :yields: Hash (String => String (id => name)
|
34
|
+
# ids are unique
|
35
|
+
@terms.inject({}) {|sum, t| sum.update(t.id => t.name)}
|
36
|
+
end
|
30
37
|
|
31
38
|
class Stanza
|
32
39
|
attr_accessor :name, :id, :tags
|
@@ -104,3 +111,4 @@ end
|
|
104
111
|
|
105
112
|
|
106
113
|
|
114
|
+
|
data/lib/utilities.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby-debug'
|
3
|
+
require 'obo_parser'
|
4
|
+
|
5
|
+
module OboParser::Utilities
|
6
|
+
|
7
|
+
# Example usage
|
8
|
+
# of1 = File.read('hao1.obo')
|
9
|
+
# of2 = File.read('hao2.obo')
|
10
|
+
# of3 = File.read('hao3.obo')
|
11
|
+
# of4 = File.read('hao4.obo')
|
12
|
+
#
|
13
|
+
# OboParser::Utilities::dump_comparison_by_id([of1, of2, of3, of4])
|
14
|
+
|
15
|
+
def self.dump_comparison_by_id(files = []) # :yields: String
|
16
|
+
of = []
|
17
|
+
files.each_with_index do |f, i|
|
18
|
+
of[i] = parse_obo_file(f)
|
19
|
+
end
|
20
|
+
|
21
|
+
all_data = {}
|
22
|
+
|
23
|
+
of.each do |f|
|
24
|
+
tmp_hash = f.id_hash
|
25
|
+
tmp_hash.keys.each do |id|
|
26
|
+
if all_data[id]
|
27
|
+
all_data[id].push tmp_hash[id]
|
28
|
+
else
|
29
|
+
all_data[id] = [tmp_hash[id]]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "\nA list of all labels used across all submitted files for a given ID\n\n"
|
35
|
+
all_data.keys.sort.each do |k|
|
36
|
+
if all_data[k].uniq.size > 1
|
37
|
+
puts "#{k}\t: #{all_data[k].uniq.join(', ')}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.alignment_translate(infile = nil) # :yields: String
|
43
|
+
# infile is a tab delimited 2 column file that contains IDs in the from FOO_1234
|
44
|
+
# The file is replicated to STDOUT replacing the ID with the Term
|
45
|
+
|
46
|
+
agreement = ARGV[0]
|
47
|
+
raise "Provide a file with comparison." if agreement.nil?
|
48
|
+
comparison = File.read(agreement)
|
49
|
+
|
50
|
+
obo_files = Dir.entries('.').inject([]){|sum, a| sum.push( a =~ /\.obo\Z/ ? a : nil)}.compact!
|
51
|
+
identifiers = {}
|
52
|
+
|
53
|
+
obo_files.each do |f|
|
54
|
+
puts "Reading: #{f}"
|
55
|
+
identifiers.merge!( parse_obo_file(File.read(f)).id_hash )
|
56
|
+
end
|
57
|
+
|
58
|
+
comparison.each do |l|
|
59
|
+
v1, v2 = l.split("\t")
|
60
|
+
# puts "#{v1} - #{v2}"
|
61
|
+
|
62
|
+
next if v1.nil? || v2.nil?
|
63
|
+
|
64
|
+
v1.gsub!(/_/, ":")
|
65
|
+
v1.strip!
|
66
|
+
v2.gsub!(/_/, ":")
|
67
|
+
v2.strip!
|
68
|
+
|
69
|
+
puts (identifiers[v1].nil? ? 'NOT FOUND' : identifiers[v1]) +
|
70
|
+
"\t" +
|
71
|
+
(identifiers[v2].nil? ? 'NOT FOUND' : identifiers[v2])
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def self.shared_labels(files = []) # :yields: String
|
78
|
+
|
79
|
+
# Returns labels found in all passed ontologies
|
80
|
+
|
81
|
+
# Usage:
|
82
|
+
|
83
|
+
# of1 = File.read('fly_anatomy.obo')
|
84
|
+
# of2 = File.read('hao.obo')
|
85
|
+
# of3 = File.read('mosquito_anatomy.obo')
|
86
|
+
|
87
|
+
# shared_labels([of1, of6])
|
88
|
+
|
89
|
+
comparison = {}
|
90
|
+
|
91
|
+
files.each do |f|
|
92
|
+
o = parse_obo_file(f)
|
93
|
+
o.term_hash.keys.each do |k|
|
94
|
+
tmp = k.gsub(/adult/, "").strip
|
95
|
+
tmp = k.gsub(/embryonic\/larval/, "").strip
|
96
|
+
if comparison[tmp]
|
97
|
+
comparison[tmp] += 1
|
98
|
+
else
|
99
|
+
comparison.merge!(tmp => 1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
match = []
|
105
|
+
comparison.keys.each do |k|
|
106
|
+
if comparison[k] == files.size
|
107
|
+
match.push k
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
puts match.sort.join("\n")
|
112
|
+
|
113
|
+
puts "\n#{match.length} total."
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
data/obo_parser.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{obo_parser}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mjy"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-02-28}
|
13
13
|
s.description = %q{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. }
|
14
14
|
s.email = %q{diapriid@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/obo_parser.rb",
|
32
32
|
"lib/parser.rb",
|
33
33
|
"lib/tokens.rb",
|
34
|
+
"lib/utilities.rb",
|
34
35
|
"obo_parser.gemspec",
|
35
36
|
"tasks/obo_parser_tasks.rake",
|
36
37
|
"test/cell.obo",
|
data/test/test_obo_parser.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- mjy
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-02-28 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/obo_parser.rb
|
43
43
|
- lib/parser.rb
|
44
44
|
- lib/tokens.rb
|
45
|
+
- lib/utilities.rb
|
45
46
|
- obo_parser.gemspec
|
46
47
|
- tasks/obo_parser_tasks.rake
|
47
48
|
- test/cell.obo
|