Back to index

python-biopython  1.60
test_KEGG.py
Go to the documentation of this file.
00001 """Tests the basic functionality of the KEGG parsers.
00002 """
00003 
00004 import os
00005 
00006 from Bio.KEGG import Enzyme
00007 from Bio.KEGG import Compound
00008 from Bio.KEGG import Map
00009 from Bio.Pathway import System
00010 
00011 test_KEGG_Enzyme_files   = ["enzyme.sample", "enzyme.irregular"]
00012 test_KEGG_Compound_files = ["compound.sample", "compound.irregular"] 
00013 test_KEGG_Map_files      = ["map00950.rea"]
00014 
00015 def t_KEGG_Enzyme(testfiles):
00016     """Tests Bio.KEGG.Enzyme functionality."""
00017     for file in testfiles:
00018         fh = open(os.path.join("KEGG", file))
00019         print "Testing Bio.KEGG.Enzyme on " + file + "\n\n"
00020         records = Enzyme.parse(fh)
00021         for record in records:
00022             print record
00023         print "\n"
00024         fh.close()
00025 
00026 def t_KEGG_Compound(testfiles):
00027     """Tests Bio.KEGG.Compound functionality."""
00028     for file in testfiles:
00029         fh = open(os.path.join("KEGG", file))
00030         print "Testing Bio.KEGG.Compound on " + file + "\n\n"
00031         records = Compound.parse(fh)
00032         for record in records:
00033             print record
00034         print "\n"
00035         fh.close()
00036 
00037 def t_KEGG_Map(testfiles):
00038     """Tests Bio.KEGG.Map functionality."""
00039     for file in testfiles:
00040         fh = open(os.path.join("KEGG", file))
00041         print "Testing Bio.KEGG.Map on " + file + "\n\n"
00042         reactions = Map.parse(fh)
00043         system = System()
00044         for reaction in reactions:
00045             system.add_reaction(reaction)
00046         # sort the reaction output by the string names, so that the
00047         # output will be consistent between python versions
00048         #def str_cmp(first, second):
00049         #    return cmp(str(first), str(second))
00050         rxs = system.reactions()
00051         #sort: key instead of compare function (for py3 support)
00052         #  The function str_cmp above can be removed if the
00053         #  solution below proves resilient
00054         rxs.sort(key=lambda x:str(x))
00055         for x in rxs:
00056             print str(x)
00057         fh.close()
00058 
00059 
00060 t_KEGG_Enzyme(test_KEGG_Enzyme_files)
00061 t_KEGG_Compound(test_KEGG_Compound_files)
00062 t_KEGG_Map(test_KEGG_Map_files)
00063 
00064