1
2
3
4
5
6
7 """
8 This module provides code to import KEGG Pathway maps for use with
9 the Biopython Pathway module.
10
11 The pathway maps are in the format:
12
13 RXXXXX:[X.X.X.X:] A + 2 B <=> C
14 RXXXXX:[X.X.X.X:] 3C <=> 2 D + E
15 ...
16
17 where RXXXXX is a five-digit reaction id, and X.X.X.X is the optional
18 EC number of the enzyme that catalyze the reaction.
19
20
21 Classes:
22 Iterator -- Iterates through a file of map file.
23
24 """
25
26 from Bio.Pathway import Reaction
27
29 """Iterator to read a file of KEGG reactions one at a time.
30 """
31 - def __init__(self, handle, parser = None):
32 """Initialize the iterator.
33
34 Arguments:
35 o handle - A handle to a map file to iterate through.
36 """
37 import warnings
38 warnings.warn("Bio.KEGG.Map.Iterator(handle, parser) is deprecated. Please use Bio.KEGG.Map.parse(handle) instead. It also returns an iterator.", DeprecationWarning)
39 self.records = parse(handle)
40
41
43 """Return the next Pathway.Reaction object from the handle.
44
45 Will return None if we ran out of records.
46 """
47 return self.records.next()
48
50 return iter(self.next, None)
51
52
54 for line in handle:
55 data, catalysts, reaction = line.split(":")
56 catalysts = [(catalysts,)]
57 reactants = {}
58 before, after = reaction.split("<=>")
59 compounds = before.split(" + ")
60 for compound in compounds:
61 compound = compound.strip()
62 try:
63 number, compound = compound.split()
64 number = -int(number)
65 except ValueError:
66 number = -1
67 reactants[compound] = number
68 compounds = after.split(" + ")
69 for compound in compounds:
70 compound = compound.strip()
71 try:
72 number, compound = compound.split()
73 number = int(number)
74 except ValueError:
75 number = +1
76 reactants[compound] = number
77 yield Reaction(reactants, catalysts, True, data)
78