# # test/unit/bio/db/test_go.rb - Unit test for Bio::GO # # Copyright:: Copyright (C) 2010 Kazuhiro Hayashi # License:: The Ruby License # # loading helper routine for testing bioruby require 'pathname' load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 3, 'bioruby_test_helper.rb')).cleanpath.to_s # libraries needed for the tests require 'test/unit' require 'bio/db/go' module Bio class TestBioGOOntology < Test::Unit::TestCase TestDataFileName = File.join(BioRubyTestDataPath, 'go', 'selected_component.ontology') def setup @obj = Bio::GO::Ontology.new(File.read(TestDataFileName)) end def test_dag_edit_format_parser obj = Bio::GO::Ontology.new(File.read(TestDataFileName)) assert_equal(Bio::GO::Ontology,obj.class) end def test_goid2term assert_equal('cellular_component', @obj.goid2term('0005575')) assert_equal('cellular_component', @obj.goid2term('0008372')) end def test_parse_goids actual = Bio::GO::Ontology.parse_goids(""GO:0003845", :db=>"Wikipedia", :db_id=>"11beta-hydroxysteroid_dehydrogenase", :go_term=>"11-beta-hydroxysteroid dehydrogenase activity"}, {:go_id=>"GO:0047414", :db=>"Wikipedia", :db_id=> "2-(hydroxymethyl)-3-(acetamidomethylene)succinate_amidohydrolase_(deaminating\\,_decarboxylating)", :go_term=> "2-(hydroxymethyl)-3-(acetamidomethylene)succinate hydrolase activity"}, {:go_id=>"GO:0043718", :db=>"Wikipedia", :db_id=>"2-hydroxymethylglutarate_dehydrogenase", :go_term=>"2-hydroxymethylglutarate dehydrogenase activity"}] file = File.read(TestDataFileName) e2g = Bio::GO::External2go.parser(file) assert_equal(expected, e2g) assert_raise(RuntimeError){ Bio::GO::External2go.parser("probably this occurs error")} end def test_set_date e2g = Bio::GO::External2go.new e2g.set_date("$Date: 2010/06/11 01:01:37 $") assert_equal("$Date: 2010/06/11 01:01:37 $",e2g.header[:date]) end def test_set_desc e2g = Bio::GO::External2go.new e2g.set_desc([" Mapping of Gene Ontology terms to Wikipedia entries."," Wikipedia: http://en.wikipedia.org"]) assert_equal([" Mapping of Gene Ontology terms to Wikipedia entries."," Wikipedia: http://en.wikipedia.org"],e2g.header[:desc]) end def test_to_str assert_equal("!date: \n! version: $Revision: 1.17 $\n! date: $Date: 2010/06/11 01:01:37 $\n!\n! Generated from file ontology/editors/gene_ontology_write.obo,\n! CVS revision: 1.1296; date: 10:06:2010 16:16\n!\n! Mapping of Gene Ontology terms to Wikipedia entries.\n! Wikipedia: http://en.wikipedia.org\n! Last update at Thu Jun 10 17:21:44 2010 by the script /users/cjm/cvs/go-moose/bin/daily_from_obo.pl\n!\nWikipedia:11beta-hydroxysteroid_dehydrogenase > GO:11-beta-hydroxysteroid dehydrogenase activity ; GO:0003845\nWikipedia:2-(hydroxymethyl)-3-(acetamidomethylene)succinate_amidohydrolase_(deaminating\\,_decarboxylating) > GO:2-(hydroxymethyl)-3-(acetamidomethylene)succinate hydrolase activity ; GO:0047414\nWikipedia:2-hydroxymethylglutarate_dehydrogenase > GO:2-hydroxymethylglutarate dehydrogenase activity ; GO:0043718", @e2g.to_str) end def test_dbs assert_equal(["Wikipedia"], @e2g.dbs) end def test_db_ids assert_equal(["11beta-hydroxysteroid_dehydrogenase", "2-(hydroxymethyl)-3-(acetamidomethylene)succinate_amidohydrolase_(deaminating\\,_decarboxylating)", "2-hydroxymethylglutarate_dehydrogenase"], @e2g.db_ids) end def test_go_terms assert_equal(["11-beta-hydroxysteroid dehydrogenase activity", "2-(hydroxymethyl)-3-(acetamidomethylene)succinate hydrolase activity", "2-hydroxymethylglutarate dehydrogenase activity"], @e2g.go_terms) end def test_go_ids assert_equal(["GO:0003845", "GO:0047414", "GO:0043718"], @e2g.go_ids) end end end