Back to index

python-biopython  1.60
__init__.py
Go to the documentation of this file.
00001 # Copyright 2001 by Tarjei Mikkelsen. All rights reserved.
00002 # Copyright 2007 by Michiel de Hoon. All rights reserved.
00003 # This code is part of the Biopython distribution and governed by its
00004 # license.  Please see the LICENSE file that should have been included
00005 # as part of this package.
00006 
00007 """
00008 This module provides code to import KEGG Pathway maps for use with
00009 the Biopython Pathway module.
00010 
00011 The pathway maps are in the format:
00012 
00013 RXXXXX:[X.X.X.X:] A + 2 B <=> C
00014 RXXXXX:[X.X.X.X:] 3C <=> 2 D + E
00015 ...
00016 
00017 where RXXXXX is a five-digit reaction id, and X.X.X.X is the optional
00018 EC number of the enzyme that catalyze the reaction.
00019 """
00020 
00021 from Bio.Pathway import Reaction
00022 
00023 
00024 def parse(handle):
00025     for line in handle:
00026         data, catalysts, reaction = line.split(":")
00027         catalysts = [(catalysts,)]
00028         reactants = {}
00029         before, after = reaction.split("<=>")
00030         compounds = before.split(" + ")
00031         for compound in compounds:
00032             compound = compound.strip()
00033             try:
00034                number, compound = compound.split()
00035                number = -int(number)
00036             except ValueError:
00037                number = -1
00038             reactants[compound] = number
00039         compounds = after.split(" + ")
00040         for compound in compounds:
00041             compound = compound.strip()
00042             try:
00043                number, compound = compound.split()
00044                number = int(number)
00045             except ValueError:
00046                number = +1
00047             reactants[compound] = number
00048         yield Reaction(reactants, catalysts, True, data)