| Trees | Indices | Help |
|---|
|
|
1 # Copyright 2001 by Tarjei Mikkelsen. All rights reserved.
2 # Copyright 2007 by Michiel de Hoon. All rights reserved.
3 # This code is part of the Biopython distribution and governed by its
4 # license. Please see the LICENSE file that should have been included
5 # as part of this package.
6
7 """
8 This module provides code to work with the KEGG Ligand/Compound database.
9
10
11 Classes:
12 Record
13 """
14
15 # other Biopython stuff
16 from Bio.KEGG import _write_kegg
17 from Bio.KEGG import _wrap_kegg
18
19
20 # Set up line wrapping rules (see Bio.KEGG._wrap_kegg)
21 name_wrap = [0, "",
22 (" ","$",1,1),
23 ("-","$",1,1)]
24 id_wrap = lambda indent : [indent, "",
25 (" ","",1,0)]
26 struct_wrap = lambda indent : [indent, "",
27 (" ","",1,1)]
28
30 """Holds info from a KEGG Ligand/Compound record.
31
32 Members:
33 entry The entry identifier.
34 name A list of the compund names.
35 formula The chemical formula for the compound
36 mass The molecular weight for the compound
37 pathway A list of 3-tuples: (database, id, pathway)
38 enzyme A list of 2-tuples: (enzyme id, role)
39 structures A list of 2-tuples: (database, list of struct ids)
40 dblinks A list of 2-tuples: (database, list of link ids)
41
42 """
44 """__init___(self)
45
46 Create a new Record.
47 """
48 self.entry = ""
49 self.name = []
50 self.formula = ""
51 self.mass = ""
52 self.pathway = []
53 self.enzyme = []
54 self.structures = []
55 self.dblinks = []
57 """__str__(self)
58
59 Returns a string representation of this Record.
60 """
61 return self._entry() + \
62 self._name() + \
63 self._formula() + \
64 self._mass() + \
65 self._pathway() + \
66 self._enzyme() + \
67 self._structures() + \
68 self._dblinks() + \
69 "///"
74 return _write_kegg("NAME",
75 map(lambda l:
76 _wrap_kegg(l, wrap_rule = name_wrap),
77 self.name))
81
85
87 s = []
88 for entry in self.pathway:
89 s.append(entry[0] + ": " + entry[1] + " " + entry[2])
90 return _write_kegg("PATHWAY",
91 [_wrap_kegg(l, wrap_rule = id_wrap(16)) \
92 for l in s])
94 s = ""
95 for entry in self.enzyme:
96 if entry[1]:
97 t = entry[0] + " (" + entry[1] + ")"
98 else:
99 t = entry[0]
100 s = s + t.ljust(16)
101 return _write_kegg("ENZYME",
102 [_wrap_kegg(s, wrap_rule = id_wrap(0))])
104 s = []
105 for entry in self.structures:
106 s.append(entry[0] + ": " + " ".join(entry[1]) + " ")
107 return _write_kegg("STRUCTURES",
108 [_wrap_kegg(l, wrap_rule = struct_wrap(5)) \
109 for l in s])
111 s = []
112 for entry in self.dblinks:
113 s.append(entry[0] + ": " + " ".join(entry[1]))
114 return _write_kegg("DBLINKS",
115 [_wrap_kegg(l, wrap_rule = id_wrap(9)) \
116 for l in s])
117
118
120 record = Record()
121 for line in handle:
122 if line[:3]=="///":
123 yield record
124 record = Record()
125 continue
126 if line[:12]!=" ":
127 keyword = line[:12]
128 data = line[12:].strip()
129 if keyword=="ENTRY ":
130 words = data.split()
131 record.entry = words[0]
132 elif keyword=="NAME ":
133 data = data.strip(";")
134 record.name.append(data)
135 elif keyword=="ENZYME ":
136 while data:
137 column = data[:16]
138 data = data[16:]
139 if '(' in column:
140 entry = column.split()
141 enzyme = (entry[0], entry[1][1:-1])
142 else:
143 enzyme = (column.strip(), "")
144 record.enzyme.append(enzyme)
145 elif keyword=="PATHWAY ":
146 if data[:5]=='PATH:':
147 path, map, name = data.split(None,2)
148 pathway = (path[:-1], map, name)
149 record.pathway.append(pathway)
150 else:
151 pathway = record.pathway[-1]
152 path, map, name = pathway
153 name = name + " " + data
154 pathway = path, map, name
155 record.pathway[-1] = pathway
156 elif keyword=="FORMULA ":
157 record.formula = data
158 elif keyword=="MASS ":
159 record.mass = data
160 elif keyword=="DBLINKS ":
161 if ":" in data:
162 key, values = data.split(":")
163 values = values.split()
164 row = (key, values)
165 record.dblinks.append(row)
166 else:
167 row = record.dblinks[-1]
168 key, values = row
169 values.extend(data.split())
170 row = key, values
171 record.dblinks[-1] = row
172
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Mon Sep 15 09:24:42 2008 | http://epydoc.sourceforge.net |