rbbt 1.1.8 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.rdoc +12 -12
  2. data/bin/rbbt_config +2 -3
  3. data/install_scripts/norm/Rakefile +4 -4
  4. data/install_scripts/organisms/{tair.Rakefile → Ath.Rakefile} +4 -3
  5. data/install_scripts/organisms/{cgd.Rakefile → Cal.Rakefile} +0 -0
  6. data/install_scripts/organisms/{worm.Rakefile → Cel.Rakefile} +0 -0
  7. data/install_scripts/organisms/{human.Rakefile → Hsa.Rakefile} +4 -8
  8. data/install_scripts/organisms/{mgi.Rakefile → Mmu.Rakefile} +0 -0
  9. data/install_scripts/organisms/{rgd.Rakefile → Rno.Rakefile} +0 -0
  10. data/install_scripts/organisms/{sgd.Rakefile → Sce.Rakefile} +0 -0
  11. data/install_scripts/organisms/{pombe.Rakefile → Spo.Rakefile} +0 -0
  12. data/install_scripts/organisms/rake-include.rb +15 -19
  13. data/lib/rbbt.rb +0 -3
  14. data/lib/rbbt/ner/rnorm.rb +2 -2
  15. data/lib/rbbt/sources/go.rb +48 -3
  16. data/lib/rbbt/sources/organism.rb +12 -17
  17. data/lib/rbbt/util/open.rb +27 -27
  18. data/lib/rbbt/util/tmpfile.rb +16 -0
  19. data/tasks/install.rake +1 -1
  20. data/test/rbbt/bow/test_bow.rb +33 -0
  21. data/test/rbbt/bow/test_classifier.rb +72 -0
  22. data/test/rbbt/bow/test_dictionary.rb +91 -0
  23. data/test/rbbt/ner/rnorm/test_cue_index.rb +57 -0
  24. data/test/rbbt/ner/rnorm/test_tokens.rb +70 -0
  25. data/test/rbbt/ner/test_abner.rb +17 -0
  26. data/test/rbbt/ner/test_banner.rb +17 -0
  27. data/test/rbbt/ner/test_dictionaryNER.rb +122 -0
  28. data/test/rbbt/ner/test_regexpNER.rb +33 -0
  29. data/test/rbbt/ner/test_rner.rb +126 -0
  30. data/test/rbbt/ner/test_rnorm.rb +47 -0
  31. data/test/rbbt/sources/test_biocreative.rb +38 -0
  32. data/test/rbbt/sources/test_biomart.rb +31 -0
  33. data/test/rbbt/sources/test_entrez.rb +49 -0
  34. data/test/rbbt/sources/test_go.rb +24 -0
  35. data/test/rbbt/sources/test_organism.rb +59 -0
  36. data/test/rbbt/sources/test_polysearch.rb +27 -0
  37. data/test/rbbt/sources/test_pubmed.rb +29 -0
  38. data/test/rbbt/util/test_arrayHash.rb +257 -0
  39. data/test/rbbt/util/test_filecache.rb +37 -0
  40. data/test/rbbt/util/test_index.rb +31 -0
  41. data/test/rbbt/util/test_misc.rb +20 -0
  42. data/test/rbbt/util/test_open.rb +97 -0
  43. data/test/rbbt/util/test_simpleDSL.rb +57 -0
  44. data/test/rbbt/util/test_tmpfile.rb +21 -0
  45. data/test/test_helper.rb +4 -0
  46. data/test/test_rbbt.rb +11 -0
  47. metadata +39 -12
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'rbbt/sources/pubmed'
3
+ require 'test/unit'
4
+
5
+ class TestPubMed < Test::Unit::TestCase
6
+
7
+ def test_get_online
8
+ pmid = '16438716'
9
+ assert(PubMed.get_online(pmid) =~ /Discovering semantic features in the literature: a foundation for building functional associations./)
10
+
11
+ pmids = ['16438716', 17204154]
12
+ assert(PubMed.get_online(pmids)[pmid] =~ /Discovering semantic features in the literature: a foundation for building functional associations./)
13
+ end
14
+
15
+ def test_get_article
16
+ pmid = '16438716'
17
+ assert(PubMed.get_article(pmid).title == "Discovering semantic features in the literature: a foundation for building functional associations.")
18
+
19
+ pmids = ['16438716', 17204154]
20
+ assert(PubMed.get_article(pmids)[pmid].title == "Discovering semantic features in the literature: a foundation for building functional associations.")
21
+ end
22
+
23
+ def test_query
24
+ assert(PubMed.query('chagoyen[All Fields] AND ("loattrfull text"[sb] AND hasabstract[text])').include? '16438716')
25
+ end
26
+
27
+ end
28
+
29
+
@@ -0,0 +1,257 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'rbbt/util/arrayHash'
3
+ require 'test/unit'
4
+
5
+ class TestArrayHash < Test::Unit::TestCase
6
+
7
+ def test_merge_values
8
+ list1 = ["A|B","C"]
9
+ list2 = ["a|b","c"]
10
+ list3 = ["a|b",""]
11
+ list4 = nil
12
+
13
+ assert_equal(["A|B|a|b","C|c"], ArrayHash.merge_values(list1,list2))
14
+
15
+ assert_equal(["A|B|a|b","C"], ArrayHash.merge_values(list1,list3))
16
+
17
+ assert_equal(["a|b|A|B","C"], ArrayHash.merge_values(list3,list1))
18
+
19
+ assert_equal(["A|B","C"], ArrayHash.merge_values(list4,list1))
20
+ end
21
+
22
+ def test_pullout
23
+ data_in = {
24
+ "1" => ['A|B','C'],
25
+ "2" => ['a|b','c']
26
+ }
27
+
28
+ data_out0 = {
29
+ 'A' => ["1",'C'],
30
+ 'B' => ["1",'C'],
31
+ 'a' => ["2",'c'],
32
+ 'b' => ["2",'c'],
33
+ }
34
+
35
+ data_out0_ci = {
36
+ 'a' => ["1|2",'C|c'],
37
+ 'b' => ["1|2",'C|c'],
38
+ }
39
+
40
+
41
+
42
+ data_out1 = {
43
+ 'C' => ["1",'A|B'],
44
+ 'c' => ["2",'a|b'],
45
+ }
46
+
47
+
48
+ assert_equal(data_out0, ArrayHash.pullout(data_in,0, :case_insensitive => false))
49
+ assert_equal(data_out1, ArrayHash.pullout(data_in,1, :case_insensitive => false))
50
+ assert_equal(data_out0_ci, ArrayHash.pullout(data_in,0,:case_insensitive => true))
51
+
52
+ assert_equal("1|2", ArrayHash.pullout(data_in,0,:case_insensitive => true, :index => true)['A'])
53
+ assert_equal("1|2", ArrayHash.pullout(data_in,0,:case_insensitive => true, :index => true)['a'])
54
+
55
+ end
56
+
57
+ def test_merge
58
+ hash1 = {
59
+ '1' => ['A','B'],
60
+ '2' => ['a','b'],
61
+ }
62
+
63
+ hash2 = {
64
+ '1' => ['C']
65
+ }
66
+
67
+ hash_merged1 = {
68
+ '1' => ['A','B','C'],
69
+ '2' => ['a','b','']
70
+ }
71
+
72
+ hash3 = {
73
+ 'A' => ['D']
74
+ }
75
+
76
+ hash_merged2 = {
77
+ '1' => ['A','B','D'],
78
+ '2' => ['a','b','']
79
+ }
80
+
81
+ hash4 = {
82
+ 'D' => ['1']
83
+ }
84
+
85
+
86
+ assert_equal(hash_merged1, ArrayHash.merge(hash1, hash2, 'main', 'main', :case_insensitive => false))
87
+ assert_equal(hash_merged2, ArrayHash.merge(hash1, hash3, 0, 'main', :case_insensitive => false))
88
+ assert_equal(hash_merged2, ArrayHash.merge(hash1, hash4, 'main', 0, :case_insensitive => false))
89
+ end
90
+
91
+ def test_case_insensitive
92
+ hash1 = {
93
+ 'c' => ['A','B'],
94
+ 'd' => ['a','b'],
95
+ }
96
+
97
+ hash2 = {
98
+ 'C' => ['D']
99
+ }
100
+
101
+ hash_merged1 = {
102
+ 'c' => ['A','B',''],
103
+ 'd' => ['a','b',''],
104
+ 'C' => ['','','D']
105
+ }
106
+
107
+ hash_merged2 = {
108
+ 'c' => ['A','B','D'],
109
+ 'd' => ['a','b',''],
110
+ }
111
+
112
+ assert_equal(hash_merged1, ArrayHash.merge(hash1, hash2, 'main', 'main', :case_insensitive => false))
113
+ assert_equal(hash_merged2, ArrayHash.merge(hash1, hash2, 'main', 'main', :case_insensitive => true))
114
+
115
+ end
116
+
117
+ def test_clean
118
+ data = {
119
+ '1' => ['A','B'],
120
+ '2' => ['a','A'],
121
+ }
122
+ data_clean = {
123
+ '1' => ['A','B'],
124
+ '2' => ['a',''],
125
+ }
126
+ assert_equal(data_clean, ArrayHash.clean(data))
127
+
128
+ data = {
129
+ '1' => ['A','B'],
130
+ '2' => ['a','A|b'],
131
+ }
132
+ data_clean = {
133
+ '1' => ['A','B'],
134
+ '2' => ['a','b'],
135
+ }
136
+ assert_equal(data_clean, ArrayHash.clean(data))
137
+
138
+ data = {
139
+ '1' => ['A','B'],
140
+ '2' => ['A|a','b'],
141
+ }
142
+ data_clean = {
143
+ '1' => ['A','B'],
144
+ '2' => ['a','b'],
145
+ }
146
+ assert_equal(data_clean, ArrayHash.clean(data))
147
+
148
+
149
+ data = {
150
+ '1' => ['a1','a2'],
151
+ '2' => ['a3','a4|A1'],
152
+ }
153
+ data_clean = {
154
+ '1' => ['a1','a2'],
155
+ '2' => ['a3','a4'],
156
+ }
157
+ assert_equal(data, ArrayHash.clean(data))
158
+ assert_equal(data_clean, ArrayHash.clean(data, :case_sensitive => true))
159
+
160
+
161
+ end
162
+
163
+
164
+ def test_field_pos
165
+ data = {
166
+ '1' => ['A','B'],
167
+ '2' => ['a','b'],
168
+ }
169
+
170
+ table = ArrayHash.new(table, 'Entrez', ['FA', 'FB'])
171
+
172
+ assert_equal(0, table.field_pos('FA'))
173
+ assert_equal(:main, table.field_pos('Entrez'))
174
+ assert_equal(:main, table.field_pos('entrez'))
175
+
176
+ end
177
+
178
+ def test_object_merge
179
+ data1 = {
180
+ '1' => ['A','B'],
181
+ '2' => ['a','b'],
182
+ }
183
+ table1 = ArrayHash.new(data1, 'Entrez', ['FA', 'FB'])
184
+
185
+ data2 = {
186
+ '1' => ['C']
187
+ }
188
+ table2 = ArrayHash.new(data2, 'Entrez', ['FC'])
189
+
190
+ hash_merged1 = {
191
+ '1' => ['A','B','C'],
192
+ '2' => ['a','b','']
193
+ }
194
+ names1 = %w(FA FB FC)
195
+
196
+ table1.merge(table2, 'Entrez', :case_insensitive => false)
197
+ assert_equal(hash_merged1, table1.data)
198
+ assert_equal(names1, table1.fields)
199
+
200
+
201
+
202
+ data3 = {
203
+ 'b' => ['d']
204
+ }
205
+ table3 = ArrayHash.new(data3, 'FB', ['FD'])
206
+
207
+ hash_merged2 = {
208
+ '1' => ['A','B','C',''],
209
+ '2' => ['a','b','','d']
210
+ }
211
+ names2 = %w(FA FB FC FD)
212
+
213
+
214
+ table1.merge(table3, 'FB', :case_insensitive => false)
215
+ assert_equal(hash_merged2, table1.data)
216
+ assert_equal(names2, table1.fields)
217
+ end
218
+
219
+ def test_remove
220
+ data = {
221
+ '1' => ['A','B'],
222
+ '2' => ['a','b'],
223
+ }
224
+ data2 = {
225
+ '1' => ['B'],
226
+ '2' => ['b'],
227
+ }
228
+
229
+
230
+ table = ArrayHash.new(data, 'Entrez', ['FA', 'FB'])
231
+ table.remove('FA')
232
+
233
+ assert_equal(nil, table.field_pos('FA'))
234
+ assert_equal(['FB'], table.fields)
235
+ assert_equal(data2, table.data)
236
+ end
237
+
238
+ def test_process
239
+ data_in = {
240
+ '1' => ['A','B'],
241
+ '2' => ['a','b'],
242
+ }
243
+ data_out = {
244
+ '1' => ['FA(A)','B'],
245
+ '2' => ['FA(a)','b'],
246
+ }
247
+
248
+ table = ArrayHash.new(data_in, 'Entrez', ['FA', 'FB'])
249
+
250
+ table.process('FA'){|n| "FA(#{n})"}
251
+
252
+ assert_equal(data_out, table.data)
253
+ end
254
+
255
+ end
256
+
257
+
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'rbbt'
3
+ require 'rbbt/util/filecache'
4
+ require 'test/unit'
5
+
6
+ class TestFileCache < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @cachedir = Rbbt.cachedir
10
+ end
11
+
12
+ def test_escape
13
+ path = '/etc/password'
14
+ assert_equal('_SLASH_etc_SLASH_password',FileCache.clean_path(path))
15
+ end
16
+
17
+ def test_path
18
+ assert_equal(File.expand_path(FileCache.path('123456789.xml')), File.expand_path(File.join(@cachedir, '/5/6/7/8/9/123456789.xml')))
19
+ assert_equal(File.expand_path(FileCache.path('12.xml')), File.expand_path(File.join(@cachedir, '/1/2/12.xml')))
20
+
21
+ assert_raise(FileCache::BadPathError){FileCache.path('/etc/passwd')}
22
+ end
23
+
24
+ def test_add_read
25
+ filename = 'test_file_cache.txt'
26
+ content = 'hello'
27
+
28
+ FileCache.del_file(filename)
29
+ FileCache.add_file(filename, content)
30
+ assert_raise(FileCache::FileExistsError){FileCache.add_file(filename,'')}
31
+ assert_nothing_raised{FileCache.add_file(filename,'',:force => true)}
32
+ FileCache.del_file(filename)
33
+
34
+ end
35
+
36
+
37
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'rbbt/util/index'
3
+ require 'test/unit'
4
+
5
+ class TestIndex < Test::Unit::TestCase
6
+
7
+
8
+ def test_index
9
+ require 'rbbt/util/tmpfile'
10
+ require 'rbbt/util/open'
11
+
12
+ tmp = TmpFile.tmp_file('test_open-')
13
+ data =<<-EOD
14
+ S000006236 856144 YPR032W YPR032W NP_015357 SNI1_YEAST Q12038|Q12038 CAA95028|CAA89286 SRO7
15
+ S000001262 856629 YHR219W YHR219W NP_012091 YH19_YEAST P38900 AAB69742 YHR219W
16
+ EOD
17
+ Open.write(tmp,data)
18
+
19
+ index = Index.index(tmp,:sep => " |\\|")
20
+ assert(index['AAB69742'] == 'S000001262' )
21
+ assert(index['Q12038'] == 'S000006236' )
22
+
23
+ FileUtils.rm tmp
24
+
25
+ end
26
+
27
+
28
+
29
+ end
30
+
31
+
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'rbbt/util/misc'
3
+ require 'test/unit'
4
+
5
+ class TestIndex < Test::Unit::TestCase
6
+
7
+
8
+ def test_chunk
9
+ a = %w(a b c d e f g h i j k l m)
10
+ assert_equal([["a", "d", "g", "j", "m"], ["b", "e", "h", "k"], ["c", "f", "i", "l"]], a.chunk(3))
11
+ end
12
+
13
+ def test_special
14
+ assert "BRC".is_special?
15
+ assert !"bindings".is_special?
16
+ end
17
+
18
+ end
19
+
20
+
@@ -0,0 +1,97 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require File.dirname(__FILE__) + '/../../test_helper'
3
+ require 'rbbt/util/open'
4
+ require 'test/unit'
5
+
6
+ class TestOpen < Test::Unit::TestCase
7
+
8
+ def test_remote
9
+
10
+ assert( Open.remote("http://localhost:20002/asdf.html"))
11
+ assert(! Open.remote("/tmp/foo.xml"))
12
+
13
+ end
14
+
15
+ def test_gziped
16
+ assert(Open.gziped("/tmp/foo.xml.gz"))
17
+ assert(Open.gziped("http://cvsweb.geneontology.org/cgi-bin/cvsweb.cgi/go/gene-associations/gene_association.goa_human.gz?rev=HEAD"))
18
+ assert(Open.gziped("http://cvsweb.geneontology.org/cgi-bin/cvsweb.cgi/go/gene-associations/gene_association.goa_human.gz"))
19
+ end
20
+
21
+ def test_read_write
22
+ require 'rbbt/util/tmpfile'
23
+ require 'fileutils'
24
+
25
+ tmp = TmpFile.tmp_file('test-')
26
+
27
+ content = "test content"
28
+
29
+ Open.write(tmp, content)
30
+ assert(Open.read(tmp) == content)
31
+
32
+ assert_equal("tast contant", Open.read(IO::popen("cat #{ tmp }|tr 'e' 'a'")))
33
+
34
+ FileUtils.rm(tmp)
35
+ end
36
+
37
+ def test_append
38
+ require 'rbbt/util/tmpfile'
39
+ require 'fileutils'
40
+
41
+ tmp = TmpFile.tmp_file('test-')
42
+ content1 = "test content1"
43
+ content2 = "test content2"
44
+
45
+ Open.write(tmp, content1)
46
+ Open.append(tmp, content2)
47
+ assert(Open.read(tmp) == content1 + content2)
48
+ FileUtils.rm(tmp)
49
+ end
50
+
51
+
52
+ def test_read_remote
53
+ url ="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&retmode=xml&id=16438716"
54
+
55
+ assert(Open.read(url, :quiet =>true) =~ /Discovering semantic features in the literature: a foundation for building functional associations./)
56
+ end
57
+
58
+ def test_to_hash
59
+ require 'rbbt/util/tmpfile'
60
+
61
+ tmp = TmpFile.tmp_file('test_open-')
62
+ data =<<-EOD
63
+ row1 a b 3
64
+ row1 aa bb 33
65
+ row2 a d e r
66
+ EOD
67
+ Open.write(tmp,data)
68
+
69
+ data = Open.to_hash(tmp, :native => 1,:extra => [2,3],:sep => " ")
70
+ assert(data['a'][0].include?('b'))
71
+ assert(data['a'][0].include?('d'))
72
+
73
+ data = Open.to_hash(tmp,:native => 1, :sep => " ")
74
+ assert(data['a'][1].include?('b') && data['a'][1].include?('d'))
75
+
76
+ data = Open.to_hash(tmp,:native => 1, :sep => " ", :flatten => true)
77
+ assert(["row1", "bb", "33"].sort, data["aa"].sort)
78
+ assert(["row1", "row2", "b", "d", "3", "e", "r"].sort, data["a"].sort)
79
+
80
+ data = Open.to_hash(tmp,:native => 1, :sep => " ", :single => true)
81
+ assert_equal({"aa"=>"row1", "a"=>"row1"}, data)
82
+
83
+ FileUtils.rm tmp
84
+ end
85
+
86
+ def test_fields
87
+ assert_equal(["1","2"] , Open.fields("1\t2") )
88
+ assert_equal(["1","2",""] , Open.fields("1\t2\t") )
89
+ assert_equal(["","",""] , Open.fields("\t\t") )
90
+ end
91
+
92
+
93
+
94
+
95
+ end
96
+
97
+