bio-phyloxml 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.travis.yml +12 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.md +199 -0
- data/README.rdoc +48 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/bio-phyloxml.rb +12 -0
- data/lib/bio/phyloxml.rb +3 -0
- data/lib/bio/phyloxml/elements.rb +1166 -0
- data/lib/bio/phyloxml/parser.rb +1000 -0
- data/lib/bio/phyloxml/phyloxml.xsd +582 -0
- data/lib/bio/phyloxml/writer.rb +227 -0
- data/sample/test_phyloxml_big.rb +205 -0
- data/test/data/phyloxml/apaf.xml +666 -0
- data/test/data/phyloxml/bcl_2.xml +2097 -0
- data/test/data/phyloxml/made_up.xml +144 -0
- data/test/data/phyloxml/ncbi_taxonomy_mollusca_short.xml +65 -0
- data/test/data/phyloxml/phyloxml_examples.xml +415 -0
- data/test/helper.rb +25 -0
- data/test/unit/bio/test_phyloxml.rb +821 -0
- data/test/unit/bio/test_phyloxml_writer.rb +334 -0
- metadata +155 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
unless defined? BioRubyTestDataPath and BioRubyTestDataPath
|
14
|
+
test_data_path = Pathname.new(File.join(File.dirname(__FILE__),
|
15
|
+
"data")).cleanpath.to_s
|
16
|
+
test_data_path.freeze
|
17
|
+
BioRubyTestDataPath = test_data_path
|
18
|
+
end
|
19
|
+
|
20
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
22
|
+
require 'bio-phyloxml'
|
23
|
+
|
24
|
+
class Test::Unit::TestCase
|
25
|
+
end
|
@@ -0,0 +1,821 @@
|
|
1
|
+
#
|
2
|
+
# = test/unit/bio/db/test_phyloxml.rb - Unit test for Bio::PhyloXML::Parser
|
3
|
+
#
|
4
|
+
# Copyright:: Copyright (C) 2009
|
5
|
+
# Diana Jaunzeikare <latvianlinuxgirl@gmail.com>
|
6
|
+
# License:: The Ruby License
|
7
|
+
#
|
8
|
+
|
9
|
+
# loading helper routine for testing bioruby
|
10
|
+
require 'pathname'
|
11
|
+
load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 2,
|
12
|
+
'helper.rb')).cleanpath.to_s
|
13
|
+
|
14
|
+
# libraries needed for the tests
|
15
|
+
require 'test/unit'
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'libxml'
|
19
|
+
rescue LoadError
|
20
|
+
end
|
21
|
+
|
22
|
+
if defined?(LibXML) then
|
23
|
+
require 'bio/phyloxml'
|
24
|
+
end
|
25
|
+
|
26
|
+
module Bio
|
27
|
+
class TestPhyloXML_Check_LibXML < Test::Unit::TestCase
|
28
|
+
def test_libxml
|
29
|
+
assert(defined?(LibXML),
|
30
|
+
"Error: libxml-ruby library is not present. Please install libxml-ruby library. It is needed for Bio::PhyloXML module. Unit test for PhyloXML will not be performed.")
|
31
|
+
end
|
32
|
+
end #class TestPhyloXML_LibXMLCheck
|
33
|
+
end #module Bio
|
34
|
+
|
35
|
+
module Bio
|
36
|
+
|
37
|
+
module TestPhyloXMLData
|
38
|
+
|
39
|
+
PHYLOXML_TEST_DATA = Pathname.new(File.join(BioRubyTestDataPath, 'phyloxml')).cleanpath.to_s
|
40
|
+
|
41
|
+
def self.example_xml
|
42
|
+
File.join PHYLOXML_TEST_DATA, 'phyloxml_examples.xml'
|
43
|
+
#If you want to test the output of writer, then do this:
|
44
|
+
#File.join PHYLOXML_TEST_DATA, 'phyloxml_examples_test.xml'
|
45
|
+
# But make sure you run ruby test/unit/bio/db/test_phyloxml_writer.rb before
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.made_up_xml
|
49
|
+
File.join PHYLOXML_TEST_DATA, 'made_up.xml'
|
50
|
+
#If you want to test the output of writer, then do this:
|
51
|
+
#File.join PHYLOXML_TEST_DATA, 'made_up_test.xml'
|
52
|
+
# But make sure you run ruby test/unit/bio/db/test_phyloxml_writer.rb before
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.metazoa_xml
|
56
|
+
File.join PHYLOXML_TEST_DATA, 'ncbi_taxonomy_metazoa.xml'
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.mollusca_xml
|
60
|
+
File.join PHYLOXML_TEST_DATA, 'ncbi_taxonomy_mollusca.xml'
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.life_xml
|
64
|
+
File.join PHYLOXML_TEST_DATA, 'tol_life_on_earth_1.xml'
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.dollo_xml
|
68
|
+
File.join PHYLOXML_TEST_DATA, 'o_tol_332_d_dollo.xml'
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.mollusca_short_xml
|
72
|
+
File.join PHYLOXML_TEST_DATA, 'ncbi_taxonomy_mollusca_short.xml'
|
73
|
+
end
|
74
|
+
|
75
|
+
end #end module TestPhyloXMLData
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class TestPhyloXML_class_methods < Test::Unit::TestCase
|
80
|
+
|
81
|
+
def test_open
|
82
|
+
filename = TestPhyloXMLData.example_xml
|
83
|
+
assert_instance_of(Bio::PhyloXML::Parser,
|
84
|
+
phyloxml = Bio::PhyloXML::Parser.open(filename))
|
85
|
+
common_test_next_tree(phyloxml)
|
86
|
+
phyloxml.close
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_open_with_block
|
90
|
+
filename = TestPhyloXMLData.example_xml
|
91
|
+
phyloxml_bak = nil
|
92
|
+
ret = Bio::PhyloXML::Parser.open(filename) do |phyloxml|
|
93
|
+
assert_instance_of(Bio::PhyloXML::Parser, phyloxml)
|
94
|
+
common_test_next_tree(phyloxml)
|
95
|
+
phyloxml_bak = phyloxml
|
96
|
+
"ok"
|
97
|
+
end
|
98
|
+
assert_equal("ok", ret)
|
99
|
+
assert_equal(true, phyloxml_bak.closed?)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_new
|
103
|
+
str = File.read(TestPhyloXMLData.example_xml)
|
104
|
+
assert_instance_of(Bio::PhyloXML::Parser,
|
105
|
+
phyloxml = Bio::PhyloXML::Parser.new(str))
|
106
|
+
common_test_next_tree(phyloxml)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_for_io
|
110
|
+
io = File.open(TestPhyloXMLData.example_xml)
|
111
|
+
assert_instance_of(Bio::PhyloXML::Parser,
|
112
|
+
phyloxml = Bio::PhyloXML::Parser.for_io(io))
|
113
|
+
common_test_next_tree(phyloxml)
|
114
|
+
io.close
|
115
|
+
end
|
116
|
+
|
117
|
+
def common_test_next_tree(phyloxml)
|
118
|
+
tree = phyloxml.next_tree
|
119
|
+
tree_arr = []
|
120
|
+
while tree != nil do
|
121
|
+
tree_arr[tree_arr.length] = tree.name
|
122
|
+
tree = phyloxml.next_tree
|
123
|
+
end
|
124
|
+
assert_equal(13, tree_arr.length)
|
125
|
+
end
|
126
|
+
private :common_test_next_tree
|
127
|
+
|
128
|
+
end #class TestPhyloXML_class_methods
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
class TestPhyloXML_private_methods < Test::Unit::TestCase
|
133
|
+
def setup
|
134
|
+
@phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
135
|
+
end
|
136
|
+
|
137
|
+
def teardown
|
138
|
+
@phyloxml.close
|
139
|
+
end
|
140
|
+
|
141
|
+
def test__validate
|
142
|
+
assert_nothing_raised {
|
143
|
+
@phyloxml.instance_eval {
|
144
|
+
_validate(:file, TestPhyloXMLData.example_xml)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
def test__validate_string
|
150
|
+
assert_nothing_raised {
|
151
|
+
@phyloxml.instance_eval {
|
152
|
+
_validate(:string, '<?xml version="1.0"?><phyloxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.phyloxml.org http://www.phyloxml.org/1.10/phyloxml.xsd" xmlns="http://www.phyloxml.org"/>')
|
153
|
+
}
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
def test__validate_validation_error
|
158
|
+
libxml_set_handler_quiet
|
159
|
+
assert_raise(RuntimeError) {
|
160
|
+
@phyloxml.instance_eval {
|
161
|
+
_validate(:string, '<a>test</a>')
|
162
|
+
}
|
163
|
+
}
|
164
|
+
libxml_set_handler_verbose
|
165
|
+
end
|
166
|
+
|
167
|
+
def test__schema
|
168
|
+
s = @phyloxml.instance_eval { _schema }
|
169
|
+
assert_instance_of(LibXML::XML::Schema, s)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test__secure_filename
|
173
|
+
assert_equal('http:/bioruby.org/test.xml',
|
174
|
+
@phyloxml.instance_eval {
|
175
|
+
_secure_filename('http://bioruby.org/test.xml')
|
176
|
+
})
|
177
|
+
end
|
178
|
+
|
179
|
+
def test__secure_filename_unchanged
|
180
|
+
assert_equal('test/test.xml',
|
181
|
+
@phyloxml.instance_eval {
|
182
|
+
_secure_filename('test/test.xml')
|
183
|
+
})
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_ClosedPhyloXMLParser
|
187
|
+
cp = Bio::PhyloXML::Parser::ClosedPhyloXMLParser.new
|
188
|
+
assert_raise(LibXML::XML::Error) { cp.next_tree }
|
189
|
+
end
|
190
|
+
|
191
|
+
private
|
192
|
+
|
193
|
+
def libxml_set_handler_quiet
|
194
|
+
# Sets quiet handler.
|
195
|
+
# Note that there are no way to get current handler.
|
196
|
+
LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
|
197
|
+
end
|
198
|
+
|
199
|
+
def libxml_set_handler_verbose
|
200
|
+
# Sets verbose handler (default LibXML error handler).
|
201
|
+
# Note that there are no way to get current handler.
|
202
|
+
LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
|
203
|
+
end
|
204
|
+
end #class TestPhyloXML_private_methods
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
class TestPhyloXML_close < Test::Unit::TestCase
|
209
|
+
def phyloxml_open(&block)
|
210
|
+
Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml, &block)
|
211
|
+
end
|
212
|
+
private :phyloxml_open
|
213
|
+
|
214
|
+
def test_close
|
215
|
+
phyloxml = phyloxml_open
|
216
|
+
phyloxml.next_tree
|
217
|
+
assert_nil(phyloxml.close)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_closed?
|
221
|
+
phyloxml = phyloxml_open
|
222
|
+
assert_equal(false, phyloxml.closed?)
|
223
|
+
phyloxml.next_tree
|
224
|
+
assert_equal(false, phyloxml.closed?)
|
225
|
+
phyloxml.close
|
226
|
+
assert_equal(true, phyloxml.closed?)
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_closed_with_block
|
230
|
+
ret = phyloxml_open do |phyloxml|
|
231
|
+
assert_equal(false, phyloxml.closed?)
|
232
|
+
phyloxml.next_tree
|
233
|
+
assert_equal(false, phyloxml.closed?)
|
234
|
+
phyloxml
|
235
|
+
end
|
236
|
+
assert_equal(true, ret.closed?)
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_close_after_close
|
240
|
+
phyloxml = phyloxml_open
|
241
|
+
phyloxml.close
|
242
|
+
assert_raise(LibXML::XML::Error) { phyloxml.close }
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_next_tree_after_close
|
246
|
+
phyloxml = phyloxml_open
|
247
|
+
phyloxml.close
|
248
|
+
assert_raise(LibXML::XML::Error) { phyloxml.next_tree }
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_next_tree_after_open_with_block
|
252
|
+
phyloxml = phyloxml_open { |arg| arg }
|
253
|
+
assert_raise(LibXML::XML::Error) { phyloxml.next_tree }
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_close_after_open_with_block
|
257
|
+
phyloxml = phyloxml_open { |arg| arg }
|
258
|
+
assert_raise(LibXML::XML::Error) { phyloxml.close }
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_close_in_open_with_block
|
262
|
+
phyloxml = phyloxml_open do |arg|
|
263
|
+
ret = arg
|
264
|
+
assert_nil(arg.close)
|
265
|
+
ret
|
266
|
+
end
|
267
|
+
assert_raise(LibXML::XML::Error) { phyloxml.close }
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_close_does_not_affect_io
|
271
|
+
io = File.open(TestPhyloXMLData.example_xml)
|
272
|
+
phyloxml = Bio::PhyloXML::Parser.for_io(io)
|
273
|
+
phyloxml.next_tree
|
274
|
+
phyloxml.close
|
275
|
+
assert(!io.closed?)
|
276
|
+
end
|
277
|
+
end #class TestPhyloXML_close
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
class TestPhyloXML1 < Test::Unit::TestCase
|
282
|
+
|
283
|
+
def setup
|
284
|
+
@phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
285
|
+
end
|
286
|
+
|
287
|
+
def teardown
|
288
|
+
@phyloxml.close
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_initialize
|
292
|
+
assert_instance_of(Bio::PhyloXML::Parser, @phyloxml)
|
293
|
+
end
|
294
|
+
|
295
|
+
def test_next_tree()
|
296
|
+
tree = @phyloxml.next_tree
|
297
|
+
tree_arr = []
|
298
|
+
while tree != nil do
|
299
|
+
|
300
|
+
tree_arr[tree_arr.length] = tree.name
|
301
|
+
tree = @phyloxml.next_tree
|
302
|
+
end
|
303
|
+
assert_equal(13, tree_arr.length)
|
304
|
+
end
|
305
|
+
|
306
|
+
end #class TestPhyloXML1
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
class TestPhyloXML2 < Test::Unit::TestCase
|
311
|
+
|
312
|
+
#setup is called before and every time any function es executed.
|
313
|
+
def setup
|
314
|
+
@phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
315
|
+
@tree = @phyloxml.next_tree
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_tree_name
|
319
|
+
assert_equal("example from Prof. Joe Felsenstein's book \"Inferring Phylogenies\"", @tree.name)
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_tree_description
|
323
|
+
assert_equal("phyloXML allows to use either a \"branch_length\" attribute or element to indicate branch lengths.", @tree.description)
|
324
|
+
end
|
325
|
+
|
326
|
+
def test_branch_length_attribute
|
327
|
+
assert_equal(0.792, @tree.total_distance)
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_rooted_atr
|
331
|
+
assert_equal(true, @tree.rooted)
|
332
|
+
end
|
333
|
+
|
334
|
+
|
335
|
+
def test_branch_length_tag
|
336
|
+
@tree = @phyloxml.next_tree
|
337
|
+
assert_equal(0.792, @tree.total_distance)
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_bootstrap
|
341
|
+
#iterate throuch first 2 trees to get to the third
|
342
|
+
@tree = @phyloxml.next_tree
|
343
|
+
@tree = @phyloxml.next_tree
|
344
|
+
node = @tree.get_node_by_name("AB")
|
345
|
+
assert_equal('bootstrap', node.confidences[0].type)
|
346
|
+
assert_equal(89, node.confidences[0].value)
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_to_biotreenode_bootstrap
|
350
|
+
#iterate throuch first 2 trees to get to the third
|
351
|
+
@tree = @phyloxml.next_tree
|
352
|
+
@tree = @phyloxml.next_tree
|
353
|
+
node = @tree.get_node_by_name("AB")
|
354
|
+
bionode = node.to_biotreenode
|
355
|
+
assert_equal(89, bionode.bootstrap)
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_duplications
|
359
|
+
4.times do
|
360
|
+
@tree = @phyloxml.next_tree
|
361
|
+
end
|
362
|
+
node = @tree.root
|
363
|
+
assert_equal(1, node.events.speciations)
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_taxonomy_scientific_name
|
367
|
+
3.times do
|
368
|
+
@tree = @phyloxml.next_tree
|
369
|
+
end
|
370
|
+
t = @tree.get_node_by_name('A').taxonomies[0]
|
371
|
+
assert_equal('E. coli', t.scientific_name)
|
372
|
+
assert_equal("J. G. Cooper, 1863", t.authority)
|
373
|
+
t = @tree.get_node_by_name('C').taxonomies[0]
|
374
|
+
assert_equal('C. elegans', t.scientific_name)
|
375
|
+
end
|
376
|
+
|
377
|
+
def test_taxonomy_id
|
378
|
+
5.times do
|
379
|
+
@tree = @phyloxml.next_tree
|
380
|
+
end
|
381
|
+
leaves = @tree.leaves
|
382
|
+
codes = []
|
383
|
+
ids = []
|
384
|
+
#id_types = []
|
385
|
+
leaves.each { |node|
|
386
|
+
codes[codes.length] = node.taxonomies[0].code
|
387
|
+
ids[ids.length] = node.taxonomies[0].taxonomy_id
|
388
|
+
#id_types[id_types.length] = node.taxonomy.id_type
|
389
|
+
}
|
390
|
+
assert_equal(["CLOAB", "DICDI", "OCTVU"], codes.sort)
|
391
|
+
#@todo assert ids, id_types. or create new class for id.
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_taxonomy2
|
395
|
+
9.times do
|
396
|
+
@tree = @phyloxml.next_tree
|
397
|
+
end
|
398
|
+
taxonomy = @tree.root.taxonomies[0]
|
399
|
+
assert_equal("8556", taxonomy.taxonomy_id.value)
|
400
|
+
assert_equal("NCBI", taxonomy.taxonomy_id.provider)
|
401
|
+
assert_equal("Varanus", taxonomy.scientific_name)
|
402
|
+
assert_equal("genus", taxonomy.rank)
|
403
|
+
assert_equal("EMBL REPTILE DATABASE", taxonomy.uri.desc)
|
404
|
+
assert_equal("http://www.embl-heidelberg.de/~uetz/families/Varanidae.html", taxonomy.uri.uri)
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_distribution_desc
|
408
|
+
9.times do
|
409
|
+
@tree = @phyloxml.next_tree
|
410
|
+
end
|
411
|
+
leaves = @tree.leaves
|
412
|
+
descrs = []
|
413
|
+
leaves.each { |node|
|
414
|
+
descrs << node.distributions[0].desc
|
415
|
+
}
|
416
|
+
assert_equal(['Africa', 'Asia', 'Australia'], descrs.sort)
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_distribution_point
|
420
|
+
10.times do
|
421
|
+
@tree = @phyloxml.next_tree
|
422
|
+
end
|
423
|
+
point = @tree.get_node_by_name('A').distributions[0].points[0]
|
424
|
+
assert_equal("WGS84", point.geodetic_datum)
|
425
|
+
assert_equal(47.481277, point.lat)
|
426
|
+
assert_equal(8.769303, point.long)
|
427
|
+
assert_equal(472, point.alt)
|
428
|
+
|
429
|
+
point = @tree.get_node_by_name('B').distributions[0].points[0]
|
430
|
+
assert_equal("WGS84", point.geodetic_datum)
|
431
|
+
assert_equal(35.155904, point.lat)
|
432
|
+
assert_equal(136.915863, point.long)
|
433
|
+
assert_equal(10, point.alt)
|
434
|
+
end
|
435
|
+
|
436
|
+
def test_sequence
|
437
|
+
3.times do
|
438
|
+
@tree = @phyloxml.next_tree
|
439
|
+
end
|
440
|
+
sequence_a = @tree.get_node_by_name('A').sequences[0]
|
441
|
+
assert_equal('alcohol dehydrogenase', sequence_a.annotations[0].desc)
|
442
|
+
assert_equal("probability", sequence_a.annotations[0].confidence.type)
|
443
|
+
assert_equal(0.99, sequence_a.annotations[0].confidence.value)
|
444
|
+
sequence_b = @tree.get_node_by_name('B').sequences[0]
|
445
|
+
assert_equal('alcohol dehydrogenase', sequence_b.annotations[0].desc)
|
446
|
+
assert_equal("probability", sequence_b.annotations[0].confidence.type)
|
447
|
+
assert_equal(0.91, sequence_b.annotations[0].confidence.value)
|
448
|
+
sequence_c = @tree.get_node_by_name('C').sequences[0]
|
449
|
+
assert_equal('alcohol dehydrogenase', sequence_c.annotations[0].desc)
|
450
|
+
assert_equal("probability", sequence_c.annotations[0].confidence.type)
|
451
|
+
assert_equal(0.67, sequence_c.annotations[0].confidence.value)
|
452
|
+
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_sequence2
|
456
|
+
4.times do
|
457
|
+
@tree = @phyloxml.next_tree
|
458
|
+
end
|
459
|
+
leaves = @tree.leaves
|
460
|
+
leaves.each { |node|
|
461
|
+
#just test one node for now
|
462
|
+
if node.sequences[0].id_source == 'x'
|
463
|
+
assert_equal('adhB', node.sequences[0].symbol)
|
464
|
+
assert_equal("ncbi", node.sequences[0].accession.source)
|
465
|
+
assert_equal('AAB80874', node.sequences[0].accession.value)
|
466
|
+
assert_equal('alcohol dehydrogenase', node.sequences[0].name)
|
467
|
+
end
|
468
|
+
if node.sequences[0].id_source == 'z'
|
469
|
+
assert_equal("InterPro:IPR002085",
|
470
|
+
node.sequences[0].annotations[0].ref)
|
471
|
+
end
|
472
|
+
}
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_sequence3
|
476
|
+
5.times do
|
477
|
+
@tree = @phyloxml.next_tree
|
478
|
+
end
|
479
|
+
@tree.leaves.each { |node|
|
480
|
+
if node.sequences[0].symbol == 'ADHX'
|
481
|
+
assert_equal('UniProtKB', node.sequences[0].accession.source)
|
482
|
+
assert_equal('P81431', node.sequences[0].accession.value)
|
483
|
+
assert_equal('Alcohol dehydrogenase class-3', node.sequences[0].name)
|
484
|
+
assert_equal(true, node.sequences[0].is_aligned)
|
485
|
+
assert_equal(true, node.sequences[0].is_aligned?)
|
486
|
+
assert_equal('TDATGKPIKCMAAIAWEAKKPLSIEEVEVAPPKSGEVRIKILHSGVCHTD',
|
487
|
+
node.sequences[0].mol_seq)
|
488
|
+
assert_equal('EC:1.1.1.1', node.sequences[0].annotations[0].ref)
|
489
|
+
assert_equal('GO:0004022', node.sequences[0].annotations[1].ref)
|
490
|
+
end
|
491
|
+
}
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_to_biosequence
|
495
|
+
5.times do
|
496
|
+
@tree = @phyloxml.next_tree
|
497
|
+
end
|
498
|
+
@tree.leaves.each { |node|
|
499
|
+
if node.sequences[0].symbol =='ADHX'
|
500
|
+
seq = node.sequences[0].to_biosequence
|
501
|
+
assert_equal('Alcohol dehydrogenase class-3', seq.definition)
|
502
|
+
assert_equal('UniProtKB', seq.id_namespace)
|
503
|
+
assert_equal('P81431', seq.entry_id)
|
504
|
+
assert_equal('TDATGKPIKCMAAIAWEAKKPLSIEEVEVAPPKSGEVRIKILHSGVCHTD',
|
505
|
+
seq.seq.to_s)
|
506
|
+
end
|
507
|
+
}
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_extract_biosequence
|
511
|
+
5.times do
|
512
|
+
@tree = @phyloxml.next_tree
|
513
|
+
end
|
514
|
+
@tree.leaves.each { |node|
|
515
|
+
if node.sequences[0].symbol == 'ADHX'
|
516
|
+
seq = node.extract_biosequence
|
517
|
+
assert_equal('Alcohol dehydrogenase class-3', seq.definition)
|
518
|
+
assert_equal('TDATGKPIKCMAAIAWEAKKPLSIEEVEVAPPKSGEVRIKILHSGVCHTD',
|
519
|
+
seq.seq.to_s)
|
520
|
+
assert_equal('Octopus vulgaris', seq.classification[0])
|
521
|
+
end
|
522
|
+
}
|
523
|
+
end
|
524
|
+
|
525
|
+
def test_date
|
526
|
+
11.times do
|
527
|
+
@tree = @phyloxml.next_tree
|
528
|
+
end
|
529
|
+
date_a = @tree.get_node_by_name('A').date
|
530
|
+
assert_equal('mya', date_a.unit)
|
531
|
+
assert_equal("Silurian", date_a.desc)
|
532
|
+
assert_equal(425, date_a.value)
|
533
|
+
date_b = @tree.get_node_by_name('B').date
|
534
|
+
assert_equal('mya', date_b.unit)
|
535
|
+
assert_equal("Devonian", date_b.desc)
|
536
|
+
assert_equal(320, date_b.value)
|
537
|
+
date_c = @tree.get_node_by_name('C').date
|
538
|
+
assert_equal('mya', date_c.unit)
|
539
|
+
assert_equal('Ediacaran', date_c.desc)
|
540
|
+
assert_equal(600, date_c.value)
|
541
|
+
assert_equal(570, date_c.minimum)
|
542
|
+
assert_equal(630, date_c.maximum)
|
543
|
+
end
|
544
|
+
|
545
|
+
def test_property
|
546
|
+
7.times do
|
547
|
+
@tree = @phyloxml.next_tree
|
548
|
+
end
|
549
|
+
property = @tree.get_node_by_name('A').properties[0]
|
550
|
+
assert_equal('xsd:integer', property.datatype)
|
551
|
+
assert_equal('NOAA:depth', property.ref)
|
552
|
+
assert_equal('clade', property.applies_to)
|
553
|
+
assert_equal('METRIC:m', property.unit)
|
554
|
+
assert_equal(' 1200 ', property.value)
|
555
|
+
end
|
556
|
+
|
557
|
+
def test_uri
|
558
|
+
9.times do
|
559
|
+
@tree = @phyloxml.next_tree
|
560
|
+
end
|
561
|
+
uri = @tree.root.taxonomies[0].uri
|
562
|
+
assert_equal("EMBL REPTILE DATABASE", uri.desc)
|
563
|
+
assert_equal("http://www.embl-heidelberg.de/~uetz/families/Varanidae.html", uri.uri)
|
564
|
+
end
|
565
|
+
|
566
|
+
|
567
|
+
|
568
|
+
end #class TestPhyloXML2
|
569
|
+
|
570
|
+
class TestPhyloXML3 < Test::Unit::TestCase
|
571
|
+
|
572
|
+
TEST_STRING =
|
573
|
+
"""<phylogeny rooted=\"true\">
|
574
|
+
<name>same example, with support of type \"bootstrap\"</name>
|
575
|
+
<clade>
|
576
|
+
<clade branch_length=\"0.06\">
|
577
|
+
<name>AB</name>
|
578
|
+
<confidence type=\"bootstrap\">89</confidence>
|
579
|
+
<clade branch_length=\"0.102\">
|
580
|
+
<name>A</name>
|
581
|
+
</clade>
|
582
|
+
<clade branch_length=\"0.23\">
|
583
|
+
<name>B</name>
|
584
|
+
</clade>
|
585
|
+
</clade>
|
586
|
+
<clade branch_length=\"0.4\">
|
587
|
+
<name>C</name>
|
588
|
+
</clade>
|
589
|
+
</clade>
|
590
|
+
</phylogeny>"""
|
591
|
+
|
592
|
+
def setup
|
593
|
+
phyloxml = Bio::PhyloXML::Parser.new(TEST_STRING)
|
594
|
+
@tree = phyloxml.next_tree()
|
595
|
+
|
596
|
+
end
|
597
|
+
|
598
|
+
def test_children
|
599
|
+
node = @tree.get_node_by_name("AB")
|
600
|
+
# nodes = @tree.children(node).sort { |a,b| a.name <=> b.name }
|
601
|
+
node_names = []
|
602
|
+
@tree.children(node).each { |children|
|
603
|
+
node_names[node_names.length] = children.name
|
604
|
+
}
|
605
|
+
node_names.sort!
|
606
|
+
assert_equal(["A", "B"], node_names)
|
607
|
+
end
|
608
|
+
|
609
|
+
|
610
|
+
end # class
|
611
|
+
|
612
|
+
class TestPhyloXML4 < Test::Unit::TestCase
|
613
|
+
|
614
|
+
#test cases what pertain to tree
|
615
|
+
|
616
|
+
def test_clade_relation
|
617
|
+
|
618
|
+
@phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
619
|
+
7.times do
|
620
|
+
@tree = @phyloxml.next_tree
|
621
|
+
end
|
622
|
+
cr = @tree.clade_relations[0]
|
623
|
+
assert_equal("b", cr.id_ref_0)
|
624
|
+
assert_equal("c", cr.id_ref_1)
|
625
|
+
assert_equal("network_connection", cr.type)
|
626
|
+
end
|
627
|
+
|
628
|
+
def test_sequence_realations
|
629
|
+
@phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
630
|
+
5.times do
|
631
|
+
@tree = @phyloxml.next_tree
|
632
|
+
end
|
633
|
+
|
634
|
+
sr = @tree.sequence_relations[0]
|
635
|
+
|
636
|
+
assert_equal("x", sr.id_ref_0)
|
637
|
+
assert_equal("y", sr.id_ref_1)
|
638
|
+
assert_equal("paralogy", sr.type)
|
639
|
+
end
|
640
|
+
|
641
|
+
|
642
|
+
end
|
643
|
+
|
644
|
+
class TestPhyloXML5 < Test::Unit::TestCase
|
645
|
+
|
646
|
+
#testing file made_up.xml
|
647
|
+
def setup
|
648
|
+
@phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.made_up_xml)
|
649
|
+
end
|
650
|
+
|
651
|
+
def test_phylogeny_confidence
|
652
|
+
tree = @phyloxml.next_tree()
|
653
|
+
assert_equal("bootstrap", tree.confidences[0].type)
|
654
|
+
assert_equal(89, tree.confidences[0].value)
|
655
|
+
assert_equal("probability", tree.confidences[1].type)
|
656
|
+
assert_equal(0.71, tree.confidences[1].value)
|
657
|
+
end
|
658
|
+
|
659
|
+
def test_to_biotreenode_probability
|
660
|
+
tree = @phyloxml.next_tree()
|
661
|
+
node = tree.get_node_by_name('c').to_biotreenode
|
662
|
+
assert_equal(nil, node.bootstrap)
|
663
|
+
end
|
664
|
+
|
665
|
+
def test_polygon
|
666
|
+
2.times do
|
667
|
+
@tree = @phyloxml.next_tree
|
668
|
+
end
|
669
|
+
polygon = @tree.get_node_by_name('A').distributions[0].polygons[0]
|
670
|
+
assert_equal(3, polygon.points.length)
|
671
|
+
assert_equal(47.481277, polygon.points[0].lat)
|
672
|
+
assert_equal("m", polygon.points[0].alt_unit)
|
673
|
+
assert_equal(136.915863, polygon.points[1].long)
|
674
|
+
assert_equal(452, polygon.points[2].alt)
|
675
|
+
polygon = @tree.get_node_by_name('A').distributions[0].polygons[1]
|
676
|
+
#making sure can read in second polygon
|
677
|
+
assert_equal(3, polygon.points.length)
|
678
|
+
assert_equal(40.481277, polygon.points[0].lat)
|
679
|
+
end
|
680
|
+
|
681
|
+
def test_reference
|
682
|
+
3.times do
|
683
|
+
@tree = @phyloxml.next_tree
|
684
|
+
end
|
685
|
+
references = @tree.get_node_by_name('A').references
|
686
|
+
assert_equal("10.1093/bioinformatics/btm619", references[0].doi)
|
687
|
+
assert_equal("Phyutility: a phyloinformatics tool for trees, alignments and molecular data", references[0].desc)
|
688
|
+
assert_equal("10.1186/1471-2105-9-S1-S23", references[1].doi)
|
689
|
+
end
|
690
|
+
|
691
|
+
|
692
|
+
def test_single_clade
|
693
|
+
4.times do
|
694
|
+
@tree = @phyloxml.next_tree()
|
695
|
+
end
|
696
|
+
assert_equal("A", @tree.root.name)
|
697
|
+
end
|
698
|
+
|
699
|
+
def test_domain_architecture
|
700
|
+
5.times {@tree = @phyloxml.next_tree()}
|
701
|
+
node = @tree.get_node_by_name("22_MOUSE")
|
702
|
+
assert_equal("22_MOUSE", node.name)
|
703
|
+
assert_equal("MOUSE", node.taxonomies[0].code)
|
704
|
+
domain_arch = node.sequences[0].domain_architecture
|
705
|
+
assert_equal(1249, domain_arch.length)
|
706
|
+
assert_equal(6, domain_arch.domains[0].from)
|
707
|
+
assert_equal(90, domain_arch.domains[0].to)
|
708
|
+
assert_in_delta(7.0E-26, domain_arch.domains[0].confidence, 1E-26)
|
709
|
+
assert_equal("CARD", domain_arch.domains[0].value)
|
710
|
+
assert_equal("x", domain_arch.domains[0].id)
|
711
|
+
assert_equal(733, domain_arch.domains[5].from)
|
712
|
+
assert_equal(771, domain_arch.domains[5].to)
|
713
|
+
assert_in_delta(4.7E-14, domain_arch.domains[5].confidence, 1E-15)
|
714
|
+
assert_equal("WD40", domain_arch.domains[5].value)
|
715
|
+
assert_equal(1168, domain_arch.domains.last.from)
|
716
|
+
assert_equal(1204, domain_arch.domains.last.to)
|
717
|
+
assert_equal(0.3, domain_arch.domains.last.confidence)
|
718
|
+
assert_equal("WD40", domain_arch.domains.last.value)
|
719
|
+
end
|
720
|
+
|
721
|
+
def test_clade_width
|
722
|
+
@tree = @phyloxml.next_tree
|
723
|
+
assert_equal(0.2, @tree.root.width)
|
724
|
+
end
|
725
|
+
|
726
|
+
def test_binary_characters
|
727
|
+
6.times do
|
728
|
+
@tree = @phyloxml.next_tree
|
729
|
+
end
|
730
|
+
bc =@tree.get_node_by_name("cellular_organisms").binary_characters
|
731
|
+
assert_equal("parsimony inferred", bc.bc_type)
|
732
|
+
assert_equal(0, bc.lost_count)
|
733
|
+
assert_equal(0, bc.gained_count)
|
734
|
+
assert_equal([], bc.lost)
|
735
|
+
|
736
|
+
bc2 = @tree.get_node_by_name("Eukaryota").binary_characters
|
737
|
+
assert_equal(2, bc2.gained_count)
|
738
|
+
assert_equal(["Cofilin_ADF", "Gelsolin"], bc2.gained)
|
739
|
+
assert_equal(["Cofilin_ADF", "Gelsolin"], bc2.present)
|
740
|
+
end
|
741
|
+
|
742
|
+
def test_rerootable2
|
743
|
+
6.times do
|
744
|
+
@tree = @phyloxml.next_tree
|
745
|
+
end
|
746
|
+
assert_equal(false, @tree.rerootable)
|
747
|
+
end
|
748
|
+
|
749
|
+
def test_phylogeny_attributes
|
750
|
+
@tree = @phyloxml.next_tree
|
751
|
+
assert_equal(true, @tree.rooted)
|
752
|
+
assert_equal(false, @tree.rerootable)
|
753
|
+
#@todo make this test pass
|
754
|
+
#assert_equal("1", @tree.branch_length_unit)
|
755
|
+
|
756
|
+
end
|
757
|
+
|
758
|
+
def test_taxonomy_synonym
|
759
|
+
5.times do
|
760
|
+
@tree = @phyloxml.next_tree
|
761
|
+
end
|
762
|
+
node = @tree.get_node_by_name('22_MOUSE')
|
763
|
+
t = node.taxonomies[0]
|
764
|
+
assert_equal("murine", t.synonyms[0])
|
765
|
+
assert_equal("vermin", t.synonyms[1])
|
766
|
+
|
767
|
+
end
|
768
|
+
|
769
|
+
def test_annotation_property
|
770
|
+
5.times do
|
771
|
+
@tree =@phyloxml.next_tree
|
772
|
+
end
|
773
|
+
node = @tree.get_node_by_name('22_MOUSE')
|
774
|
+
prop = node.sequences[0].annotations[0].properties[0]
|
775
|
+
assert_equal("1200", prop.value)
|
776
|
+
end
|
777
|
+
|
778
|
+
end
|
779
|
+
class TestPhyloXML5 < Test::Unit::TestCase
|
780
|
+
|
781
|
+
def test_each
|
782
|
+
phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
783
|
+
count = 0
|
784
|
+
phyloxml.each do |tree|
|
785
|
+
count +=1
|
786
|
+
end
|
787
|
+
assert_equal(13, count)
|
788
|
+
end
|
789
|
+
|
790
|
+
def test_other
|
791
|
+
phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
792
|
+
assert_equal(nil, phyloxml.other[0])
|
793
|
+
phyloxml.each do |tree|
|
794
|
+
#iterate through all trees, to get to the end
|
795
|
+
end
|
796
|
+
o = phyloxml.other[0]
|
797
|
+
assert_equal('align:alignment', o.element_name)
|
798
|
+
assert_equal('seq', o.children[0].element_name)
|
799
|
+
assert_equal('aggtcgcggcctgtggaagtcctctcct', o.children[1].value)
|
800
|
+
assert_equal("C", o.children[2].attributes["name"])
|
801
|
+
|
802
|
+
end
|
803
|
+
|
804
|
+
def test_array_behaviour
|
805
|
+
phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.example_xml)
|
806
|
+
tree = phyloxml[2]
|
807
|
+
assert_equal("same example, with support of type \"bootstrap\"",
|
808
|
+
tree.name)
|
809
|
+
end
|
810
|
+
|
811
|
+
|
812
|
+
# def test_get_tree_by_name
|
813
|
+
# @phyloxml = Bio::PhyloXML::Parser.open(TestPhyloXMLData.made_up_xml)
|
814
|
+
# tree = @phyloxml.get_tree_by_name "testing confidence"
|
815
|
+
#
|
816
|
+
# end
|
817
|
+
|
818
|
+
end
|
819
|
+
|
820
|
+
|
821
|
+
end if defined?(LibXML) #end module Bio
|