PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/test/unit/bio/db/test_phyloxml.rb

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