rcsb.utils.ec 0.27__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rcsb/__init__.py +1 -0
- rcsb/utils/__init__.py +1 -0
- rcsb/utils/ec/EnzymeDatabaseProvider.py +491 -0
- rcsb/utils/ec/__init__.py +0 -0
- rcsb_utils_ec-0.27.dist-info/METADATA +62 -0
- rcsb_utils_ec-0.27.dist-info/RECORD +8 -0
- rcsb_utils_ec-0.27.dist-info/WHEEL +4 -0
- rcsb_utils_ec-0.27.dist-info/licenses/LICENSE +201 -0
rcsb/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
rcsb/utils/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
|
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
##
|
|
2
|
+
# File: EnzymeDatabaseProvider.py
|
|
3
|
+
# Author: J. Westbrook
|
|
4
|
+
# Date: 24-Jan-2019
|
|
5
|
+
# Version: 0.001
|
|
6
|
+
#
|
|
7
|
+
# Update:
|
|
8
|
+
# 21-Jul-2021 jdw Make this provider a subclass of StashableBase
|
|
9
|
+
# 8-May-2024 dwp Add additional data quality check to file download (in case data file is empty)
|
|
10
|
+
#
|
|
11
|
+
##
|
|
12
|
+
"""
|
|
13
|
+
Various utilities for extracting data Enzyme database export data files
|
|
14
|
+
and returning lineage details.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import collections
|
|
18
|
+
import copy
|
|
19
|
+
import logging
|
|
20
|
+
import os
|
|
21
|
+
|
|
22
|
+
from bs4 import BeautifulSoup
|
|
23
|
+
|
|
24
|
+
from rcsb.utils.io.FileUtil import FileUtil
|
|
25
|
+
from rcsb.utils.io.MarshalUtil import MarshalUtil
|
|
26
|
+
from rcsb.utils.io.StashableBase import StashableBase
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class EnzymeDatabaseProvider(StashableBase):
|
|
32
|
+
"""Various utilities for extracting data Enzyme database export data files
|
|
33
|
+
and returning lineage details.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, **kwargs):
|
|
37
|
+
dirName = "ec"
|
|
38
|
+
if "cachePath" in kwargs:
|
|
39
|
+
cachePath = os.path.abspath(kwargs.get("cachePath", None))
|
|
40
|
+
enzymeDirPath = os.path.join(cachePath, dirName)
|
|
41
|
+
else:
|
|
42
|
+
enzymeDirPath = kwargs.get("enzymeDirPath", ".")
|
|
43
|
+
cachePath, dirName = os.path.split(os.path.abspath(enzymeDirPath))
|
|
44
|
+
super(EnzymeDatabaseProvider, self).__init__(cachePath, [dirName])
|
|
45
|
+
#
|
|
46
|
+
urlTarget = kwargs.get("urlTarget", "https://www.enzyme-database.org/downloads/enzyme-data.xml.gz")
|
|
47
|
+
urlTargetFallback = "https://github.com/rcsb/py-rcsb_exdb_assets/raw/master/fall_back/enzyme-data.xml.gz"
|
|
48
|
+
|
|
49
|
+
useCache = kwargs.get("useCache", True)
|
|
50
|
+
enzymeDataFileName = kwargs.get("enzymeDataFileName", "enzyme-data.json")
|
|
51
|
+
|
|
52
|
+
self.__debug = False
|
|
53
|
+
#
|
|
54
|
+
self.__mU = MarshalUtil(workPath=enzymeDirPath)
|
|
55
|
+
self.__enzD = self.__reload(urlTarget, urlTargetFallback, enzymeDirPath, enzymeDataFileName=enzymeDataFileName, useCache=useCache)
|
|
56
|
+
|
|
57
|
+
def testCache(self):
|
|
58
|
+
logger.info("Length class dict %d", len(self.__enzD["class"]) if "class" in self.__enzD else 0)
|
|
59
|
+
if "class" in self.__enzD and len(self.__enzD["class"]) > 7600:
|
|
60
|
+
return True
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
def replaced(self, ecId):
|
|
64
|
+
nS = hS = None
|
|
65
|
+
try:
|
|
66
|
+
nS = self.__enzD["replaced"][ecId]["note"]
|
|
67
|
+
except Exception:
|
|
68
|
+
pass
|
|
69
|
+
try:
|
|
70
|
+
hS = self.__enzD["replaced"][ecId]["history"]
|
|
71
|
+
except Exception:
|
|
72
|
+
pass
|
|
73
|
+
return nS, hS
|
|
74
|
+
|
|
75
|
+
def exists(self, ecId):
|
|
76
|
+
try:
|
|
77
|
+
return ecId in self.__enzD["class"]
|
|
78
|
+
except Exception:
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
def normalize(self, ecId):
|
|
82
|
+
"""Normalize the input class identifier removing any ambiguity markers.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
ecId (str): EC class identifier
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
(str) : normalized EC identifier
|
|
89
|
+
"""
|
|
90
|
+
retId = None
|
|
91
|
+
try:
|
|
92
|
+
oL = []
|
|
93
|
+
tvL = ecId.strip().split(".")
|
|
94
|
+
for tv in tvL:
|
|
95
|
+
if not tv.isdigit():
|
|
96
|
+
break
|
|
97
|
+
oL.append(tv)
|
|
98
|
+
retId = ".".join(oL)
|
|
99
|
+
except Exception as e:
|
|
100
|
+
logger.exception("Failing normalizing %r with %s", ecId, str(e))
|
|
101
|
+
return retId
|
|
102
|
+
|
|
103
|
+
def getClass(self, ecId):
|
|
104
|
+
try:
|
|
105
|
+
return self.__enzD["class"][ecId]
|
|
106
|
+
except Exception:
|
|
107
|
+
pass
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
def getLineage(self, ecId):
|
|
111
|
+
try:
|
|
112
|
+
return self.__enzD["lineage"][ecId]
|
|
113
|
+
except Exception:
|
|
114
|
+
pass
|
|
115
|
+
return None
|
|
116
|
+
|
|
117
|
+
def getTreeNodeList(self):
|
|
118
|
+
treeL = self.__exportTreeNodeList(self.__enzD)
|
|
119
|
+
return treeL
|
|
120
|
+
|
|
121
|
+
def __reload(self, urlTarget, urlTargetFallback, dirPath, enzymeDataFileName, useCache=True):
|
|
122
|
+
"""Reload input XML database dump file and return data transformed lineage data objects.
|
|
123
|
+
'
|
|
124
|
+
Returns:
|
|
125
|
+
dictionary[ec_id] = {'name_list': ... , 'id_list': ... 'depth_list': ... }
|
|
126
|
+
"""
|
|
127
|
+
enzD = {}
|
|
128
|
+
#
|
|
129
|
+
mU = MarshalUtil()
|
|
130
|
+
fU = FileUtil()
|
|
131
|
+
ok, okFetch = False, False
|
|
132
|
+
fn = fU.getFileName(urlTarget)
|
|
133
|
+
xmlFilePath = os.path.join(dirPath, fn)
|
|
134
|
+
enzymeDataPath = os.path.join(dirPath, enzymeDataFileName)
|
|
135
|
+
self.__mU.mkdir(dirPath)
|
|
136
|
+
#
|
|
137
|
+
if not useCache:
|
|
138
|
+
for fp in [xmlFilePath, enzymeDataPath]:
|
|
139
|
+
try:
|
|
140
|
+
os.remove(fp)
|
|
141
|
+
except Exception:
|
|
142
|
+
pass
|
|
143
|
+
#
|
|
144
|
+
if useCache and fU.exists(enzymeDataPath):
|
|
145
|
+
enzD = self.__mU.doImport(enzymeDataPath, fmt="json")
|
|
146
|
+
elif not useCache:
|
|
147
|
+
if useCache and fU.exists(xmlFilePath):
|
|
148
|
+
logger.info("Using an existing resource file %s", xmlFilePath)
|
|
149
|
+
ok = True
|
|
150
|
+
else:
|
|
151
|
+
logger.info("Fetching url %s to resource file %s", urlTarget, xmlFilePath)
|
|
152
|
+
okFetch = fU.get(urlTarget, xmlFilePath)
|
|
153
|
+
ok = fU.size(xmlFilePath) > 10000 and okFetch
|
|
154
|
+
logger.info("Enzyme data fetch status is %r, data integrity status is %r", okFetch, ok)
|
|
155
|
+
if not ok:
|
|
156
|
+
logger.info("Fetching fallback url %s to resource file %s", urlTargetFallback, xmlFilePath)
|
|
157
|
+
okFetch = fU.get(urlTargetFallback, xmlFilePath)
|
|
158
|
+
ok = fU.size(xmlFilePath) > 10000 and okFetch
|
|
159
|
+
logger.info("Enzyme data fallback fetch status is %r, data integrity status is %r", okFetch, ok)
|
|
160
|
+
if ok:
|
|
161
|
+
xrt = mU.doImport(xmlFilePath, fmt="xml")
|
|
162
|
+
if self.__debug:
|
|
163
|
+
self.__traverse(xrt, ns="")
|
|
164
|
+
rD = self.__extract(xrt)
|
|
165
|
+
enzD = self.__build(rD)
|
|
166
|
+
ok = self.__mU.doExport(enzymeDataPath, enzD, fmt="json", indent=3)
|
|
167
|
+
return enzD
|
|
168
|
+
|
|
169
|
+
def __build(self, rD):
|
|
170
|
+
"""Build the list of ancestor classifiers for each leaf classifier.
|
|
171
|
+
|
|
172
|
+
Source enzyme database exported data has the following organization:
|
|
173
|
+
|
|
174
|
+
"class": [
|
|
175
|
+
{
|
|
176
|
+
"id": "1",
|
|
177
|
+
"class": "1",
|
|
178
|
+
"subclass": "1",
|
|
179
|
+
"subsubclass": "0",
|
|
180
|
+
"heading": "Acting on the CH-OH group of donors",
|
|
181
|
+
"note": "This subclass contains dehydrogenases that act on primary alcohols,",
|
|
182
|
+
"last_change": "2006-05-18 10:47:54"
|
|
183
|
+
}, ...
|
|
184
|
+
|
|
185
|
+
"entry": [
|
|
186
|
+
{
|
|
187
|
+
"ec_num": "1.1.1.1",
|
|
188
|
+
"accepted_name": "alcohol dehydrogenase",
|
|
189
|
+
"reaction": "(1) a primary alcohol + NAD+ = an aldehyde + NADH + H+;;(2) a secondary alcohol + NAD+ = a ketone + NADH + H+",
|
|
190
|
+
"other_names": "aldehyde reductase; ADH; alcohol dehydrogenase (NAD); aliphatic alcohol dehydrogenase; ethanol dehydrogenase; NAD-dependent alcohol dehydrogenase;",
|
|
191
|
+
"sys_name": "alcohol:NAD+ oxidoreductase",
|
|
192
|
+
"comments": "A zinc protein. Acts on primary or secondary alcohols or hemi-acetals with very broad specificity; however the enzyme oxidizes ..... ",
|
|
193
|
+
"links": "BRENDA, EXPASY, GTD, IUBMB, KEGG, PDB, UM-BBD",
|
|
194
|
+
"class": "1",
|
|
195
|
+
"subclass": "1",
|
|
196
|
+
"subsubclass": "1",
|
|
197
|
+
"serial": "1",
|
|
198
|
+
"status": null,
|
|
199
|
+
"diagram": null,
|
|
200
|
+
"cas_num": "9031-72-5",
|
|
201
|
+
"glossary": null,
|
|
202
|
+
"last_change": "2012-02-17 13:19:04",
|
|
203
|
+
"id": "1"
|
|
204
|
+
}, ...
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
dictionary[ec_id] = {'name_list': ... , 'id_list': ... 'depth_list': ... }
|
|
209
|
+
|
|
210
|
+
"""
|
|
211
|
+
replacedD = {}
|
|
212
|
+
linD = {}
|
|
213
|
+
cD = {}
|
|
214
|
+
classD = {}
|
|
215
|
+
#
|
|
216
|
+
# list_of_words = your_string.split()
|
|
217
|
+
# next_word = list_of_words[list_of_words.index(your_search_word) + 1]
|
|
218
|
+
#
|
|
219
|
+
if "hist" in rD:
|
|
220
|
+
for dD in rD["hist"]:
|
|
221
|
+
ecId = dD["ec_num"]
|
|
222
|
+
ts1 = dD["note"] if "note" in dD and dD["note"] else None
|
|
223
|
+
if ts1:
|
|
224
|
+
replacedD[ecId] = {"note": ts1}
|
|
225
|
+
ts2 = dD["history"] if "history" in dD and dD["history"] else None
|
|
226
|
+
if ts2:
|
|
227
|
+
replacedD[ecId] = {"history": ts2}
|
|
228
|
+
|
|
229
|
+
if ts1 and any(xS in ts1 for xS in [" Now ", " transferred "]) and ("EC " in ts1):
|
|
230
|
+
logger.debug("%s note is %r", ecId, ts1)
|
|
231
|
+
if ts2 and any(xS in ts2 for xS in [" Now ", " transferred "]) and ("EC " in ts2):
|
|
232
|
+
logger.debug("%s hist is %r", ecId, ts2)
|
|
233
|
+
|
|
234
|
+
#
|
|
235
|
+
if "class" in rD:
|
|
236
|
+
for dD in rD["class"]:
|
|
237
|
+
clTup = tuple([dD[at] for at in ["class", "subclass", "subsubclass"]])
|
|
238
|
+
val = self.__stripMarkup(dD["heading"])
|
|
239
|
+
cD[clTup] = val
|
|
240
|
+
classD[".".join(clTup)] = val
|
|
241
|
+
|
|
242
|
+
for ecId in classD:
|
|
243
|
+
cL = ecId.split(".")
|
|
244
|
+
#
|
|
245
|
+
tt = cL
|
|
246
|
+
sscParent = tuple(tt)
|
|
247
|
+
tt = cL[:-1]
|
|
248
|
+
tt.append("0")
|
|
249
|
+
scParent = tuple(tt)
|
|
250
|
+
tt = cL[:-2]
|
|
251
|
+
tt.extend(["0", "0"])
|
|
252
|
+
cParent = tuple(tt)
|
|
253
|
+
#
|
|
254
|
+
try:
|
|
255
|
+
idL = [".".join(cL[:-2]), ".".join(cL[:-1]), ".".join(cL)]
|
|
256
|
+
classVal = cD[cParent] if cParent in cD else ""
|
|
257
|
+
subClassVal = cD[scParent] if scParent in cD else ""
|
|
258
|
+
subsubClassVal = cD[sscParent] if sscParent in cD else ""
|
|
259
|
+
nmL = [classVal, subClassVal, subsubClassVal]
|
|
260
|
+
depthL = [1, 2, 3]
|
|
261
|
+
#
|
|
262
|
+
logger.debug("%s idL %r", ecId, idL)
|
|
263
|
+
logger.debug("%s nmL %r", ecId, nmL)
|
|
264
|
+
fL = [t for t in cL if t != "0"]
|
|
265
|
+
fLen = len(fL)
|
|
266
|
+
for jj in range(1, fLen + 1):
|
|
267
|
+
tId = ".".join(cL[:jj])
|
|
268
|
+
if tId not in linD:
|
|
269
|
+
linD[tId] = [(depthL[ii], idL[ii], nmL[ii]) for ii in range(jj)]
|
|
270
|
+
logger.debug("%s %r", tId, linD[tId])
|
|
271
|
+
except Exception as e:
|
|
272
|
+
logger.exception("Failing with %s", str(e))
|
|
273
|
+
|
|
274
|
+
for k in sorted(classD):
|
|
275
|
+
logger.debug("%10s %s", k, classD[k])
|
|
276
|
+
#
|
|
277
|
+
if "entry" in rD:
|
|
278
|
+
for dD in rD["entry"]:
|
|
279
|
+
if "serial" not in dD:
|
|
280
|
+
logger.error("Missing serial field in %r", dD)
|
|
281
|
+
continue
|
|
282
|
+
cL = list([dD[at] for at in ["class", "subclass", "subsubclass", "serial"]])
|
|
283
|
+
#
|
|
284
|
+
tt = cL[:-1]
|
|
285
|
+
sscParent = tuple(tt)
|
|
286
|
+
tt = cL[:-2]
|
|
287
|
+
tt.append("0")
|
|
288
|
+
scParent = tuple(tt)
|
|
289
|
+
tt = cL[:-3]
|
|
290
|
+
tt.extend(["0", "0"])
|
|
291
|
+
cParent = tuple(tt)
|
|
292
|
+
#
|
|
293
|
+
try:
|
|
294
|
+
idL = [".".join(cL[:-3]), ".".join(cL[:-2]), ".".join(cL[:-1]), ".".join(cL)]
|
|
295
|
+
classVal = cD[cParent] if cParent in cD else ""
|
|
296
|
+
subClassVal = cD[scParent] if scParent in cD else ""
|
|
297
|
+
subsubClassVal = cD[sscParent] if sscParent in cD else ""
|
|
298
|
+
serialValue = dD["accepted_name"] if "accepted_name" in dD else ""
|
|
299
|
+
if serialValue is None or not serialValue:
|
|
300
|
+
serialValue = ""
|
|
301
|
+
logger.debug("Missing accepted name data for %s", ".".join(cL))
|
|
302
|
+
else:
|
|
303
|
+
serialValue = self.__stripMarkup(serialValue)
|
|
304
|
+
classD[".".join(cL)] = serialValue
|
|
305
|
+
|
|
306
|
+
nmL = [classVal, subClassVal, subsubClassVal, serialValue]
|
|
307
|
+
depthL = [1, 2, 3, 4]
|
|
308
|
+
# linD['.'.join(cL)] = {'name_list': nmL, 'id_list': idL, 'depth_list': depthL}
|
|
309
|
+
for jj in range(1, 5):
|
|
310
|
+
ecId = ".".join(cL[:jj])
|
|
311
|
+
if ecId not in linD:
|
|
312
|
+
linD[ecId] = [(depthL[ii], idL[ii], nmL[ii]) for ii in range(jj)]
|
|
313
|
+
|
|
314
|
+
except Exception as e:
|
|
315
|
+
logger.error("cL %r cParent %r scParent %r sscParent %r val %r", cL, cParent, scParent, sscParent, val)
|
|
316
|
+
logger.error("d is %r", dD)
|
|
317
|
+
logger.error("Failing with %s", str(e))
|
|
318
|
+
#
|
|
319
|
+
# strip 0 placeholders
|
|
320
|
+
#
|
|
321
|
+
rD = {}
|
|
322
|
+
for ky in classD:
|
|
323
|
+
ff = [t for t in ky.split(".") if t != "0"]
|
|
324
|
+
rD[".".join(ff)] = classD[ky]
|
|
325
|
+
|
|
326
|
+
#
|
|
327
|
+
enzD = {"class": rD, "lineage": linD, "replaced": replacedD}
|
|
328
|
+
return enzD
|
|
329
|
+
|
|
330
|
+
def __exportTreeNodeList(self, enzD):
|
|
331
|
+
""" """
|
|
332
|
+
# create parent dictionary
|
|
333
|
+
#
|
|
334
|
+
pL = []
|
|
335
|
+
pD = {}
|
|
336
|
+
for ecId in enzD["class"]:
|
|
337
|
+
ff = ecId.split(".")
|
|
338
|
+
if len(ff) == 1:
|
|
339
|
+
pEcId = None
|
|
340
|
+
pL.append(ecId)
|
|
341
|
+
else:
|
|
342
|
+
pEcId = ".".join(ff[:-1])
|
|
343
|
+
logger.debug("ecId %s parent %s", ecId, pEcId)
|
|
344
|
+
pD[ecId] = pEcId
|
|
345
|
+
#
|
|
346
|
+
logger.info("enzD %d pD %d", len(enzD["class"]), len(pD))
|
|
347
|
+
cD = {}
|
|
348
|
+
for cEcId, pEcId in pD.items():
|
|
349
|
+
cD.setdefault(pEcId, []).append(cEcId)
|
|
350
|
+
#
|
|
351
|
+
logger.info("cD %d", len(cD))
|
|
352
|
+
#
|
|
353
|
+
idL = []
|
|
354
|
+
for rootId in sorted(pL):
|
|
355
|
+
visited = set([rootId])
|
|
356
|
+
queue = collections.deque(visited)
|
|
357
|
+
while queue:
|
|
358
|
+
ecId = queue.popleft()
|
|
359
|
+
idL.append(ecId)
|
|
360
|
+
if ecId not in cD:
|
|
361
|
+
logger.debug("No children for ecId %s", ecId)
|
|
362
|
+
continue
|
|
363
|
+
for childId in cD[ecId]:
|
|
364
|
+
if childId not in visited:
|
|
365
|
+
queue.append(childId)
|
|
366
|
+
visited.add(childId)
|
|
367
|
+
#
|
|
368
|
+
dL = []
|
|
369
|
+
for ecId in idL:
|
|
370
|
+
displayName = enzD["class"][ecId]
|
|
371
|
+
pEcId = pD[ecId]
|
|
372
|
+
|
|
373
|
+
lL = [t[1] for t in enzD["lineage"][ecId]]
|
|
374
|
+
|
|
375
|
+
#
|
|
376
|
+
if pEcId is None:
|
|
377
|
+
dD = {"id": ecId, "name": displayName, "depth": 0}
|
|
378
|
+
else:
|
|
379
|
+
dD = {"id": ecId, "name": displayName, "parents": [pEcId], "depth": len(lL) - 1}
|
|
380
|
+
dL.append(dD)
|
|
381
|
+
|
|
382
|
+
return dL
|
|
383
|
+
|
|
384
|
+
def __extract(self, xrt):
|
|
385
|
+
"""Extract data from the input document and return a dictionary
|
|
386
|
+
of objects containing rows of dictionaries with attribute naming.
|
|
387
|
+
|
|
388
|
+
Args:
|
|
389
|
+
xrt: ElementTree root element
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
Extracted data (dict): dictionary organized by category with
|
|
393
|
+
XML native data names.
|
|
394
|
+
"""
|
|
395
|
+
rD = {}
|
|
396
|
+
for el in xrt.getroot():
|
|
397
|
+
logger.debug("-- Element tag %r name %r", el.tag, el.attrib["name"])
|
|
398
|
+
# rD.setdefault(el.tag, []).append(q)
|
|
399
|
+
#
|
|
400
|
+
for ch in el:
|
|
401
|
+
logger.debug("-- --> child element tag %r attrib %r", ch.tag, ch.attrib["name"])
|
|
402
|
+
#
|
|
403
|
+
if ch.tag == "table_data" and ch.attrib["name"] in ["class", "entry", "hist"]:
|
|
404
|
+
dL = self.__getTableData(ch)
|
|
405
|
+
rD[ch.attrib["name"]] = dL
|
|
406
|
+
|
|
407
|
+
# for gch in ch:
|
|
408
|
+
# logger.debug("-- -- --> grand child element tag %r attrib count %r" % (gch.tag, len(gch.attrib)))
|
|
409
|
+
# for ggch in gch:
|
|
410
|
+
# logger.debug("-- -- --> grand child element tag %r attrib %r" % (ggch.tag, ggch.attrib['name']))
|
|
411
|
+
# add parent cardinal attributes
|
|
412
|
+
return rD
|
|
413
|
+
#
|
|
414
|
+
|
|
415
|
+
def __getTableData(self, el):
|
|
416
|
+
"""Parse table data sections:
|
|
417
|
+
|
|
418
|
+
Example --
|
|
419
|
+
|
|
420
|
+
'table_data' {'name': 'cite'}
|
|
421
|
+
'row' {}
|
|
422
|
+
'field' {'name': 'cite_key'}
|
|
423
|
+
'field' {'name': 'ec_num'}
|
|
424
|
+
'field' {'name': 'ref_num'}
|
|
425
|
+
'field' {'name': 'acc_no'}
|
|
426
|
+
'field' {'name': 'last_change'}
|
|
427
|
+
'row' {}
|
|
428
|
+
'field' {'name': 'cite_key'}
|
|
429
|
+
'field' {'name': 'ec_num'}
|
|
430
|
+
'field' {'name': 'ref_num'}
|
|
431
|
+
'field' {'name': 'acc_no'}
|
|
432
|
+
'field' {'name': 'last_change'}
|
|
433
|
+
"""
|
|
434
|
+
dL = []
|
|
435
|
+
if el.tag != "table_data":
|
|
436
|
+
return dL
|
|
437
|
+
for ch in el:
|
|
438
|
+
if ch.tag == "row":
|
|
439
|
+
dD = {}
|
|
440
|
+
for gch in ch:
|
|
441
|
+
if gch.tag == "field":
|
|
442
|
+
nm = gch.attrib["name"]
|
|
443
|
+
val = gch.text
|
|
444
|
+
dD[nm] = val
|
|
445
|
+
logger.debug(" Field %s val %r", nm, val)
|
|
446
|
+
#
|
|
447
|
+
dL.append(copy.copy(dD))
|
|
448
|
+
return dL
|
|
449
|
+
|
|
450
|
+
def __stripMarkup(self, text):
|
|
451
|
+
try:
|
|
452
|
+
tS = text.replace("—", "-").replace("—", "-").replace("—", "-")
|
|
453
|
+
bs = BeautifulSoup(tS, features="lxml")
|
|
454
|
+
return bs.get_text()
|
|
455
|
+
except Exception as e:
|
|
456
|
+
logger.exception("Failing for %r with %s", text, str(e))
|
|
457
|
+
return ""
|
|
458
|
+
|
|
459
|
+
# -
|
|
460
|
+
def __traverse(self, xrt, ns):
|
|
461
|
+
"""Internal routine to traverse the dom covering/logging all elements and attributes.
|
|
462
|
+
|
|
463
|
+
Args:
|
|
464
|
+
xrt (object): ElementTree root element
|
|
465
|
+
ns (str): XML namespace
|
|
466
|
+
|
|
467
|
+
"""
|
|
468
|
+
|
|
469
|
+
for el in xrt.getroot():
|
|
470
|
+
pEl = el.tag.replace(ns, "")
|
|
471
|
+
logger.info("-- %r %r", pEl, el.attrib)
|
|
472
|
+
for ch in el:
|
|
473
|
+
chEl = ch.tag.replace(ns, "")
|
|
474
|
+
logger.info("-- --> %r %r", chEl, ch.attrib)
|
|
475
|
+
if ch.text is not None and ch.text:
|
|
476
|
+
logger.info("-- --> %s", ch.text)
|
|
477
|
+
for gch in ch:
|
|
478
|
+
gchEl = gch.tag.replace(ns, "")
|
|
479
|
+
logger.info("-- -- --> %r %r", gchEl, gch.attrib)
|
|
480
|
+
if gch.text is not None and gch.text:
|
|
481
|
+
logger.info("-- -- --> %s", gch.text)
|
|
482
|
+
for ggch in gch:
|
|
483
|
+
ggchEl = ggch.tag.replace(ns, "")
|
|
484
|
+
logger.info("-- -- -- --> %r %r", ggchEl, ggch.attrib)
|
|
485
|
+
if ggch.text is not None and ggch.text:
|
|
486
|
+
logger.info("-- -- -- --> %s", ggch.text)
|
|
487
|
+
for gggch in ggch:
|
|
488
|
+
gggchEl = gggch.tag.replace(ns, "")
|
|
489
|
+
logger.info("-- -- -- -- --> %r %r", gggchEl, gggch.attrib)
|
|
490
|
+
if gggch.text is not None and gggch.text:
|
|
491
|
+
logger.info("-- -- -- -- --> %s", gggch.text)
|
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rcsb.utils.ec
|
|
3
|
+
Version: 0.27
|
|
4
|
+
Summary: RCSB Python utility classes for processing EC classification data
|
|
5
|
+
Project-URL: Homepage, https://github.com/rcsb/py-rcsb_utils_ec
|
|
6
|
+
Author-email: John Westbrook <john.westbrook@rcsb.org>
|
|
7
|
+
Maintainer-email: Dennis Piehl <dennis.piehl@rcsb.org>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Requires-Dist: beautifulsoup4
|
|
18
|
+
Requires-Dist: lxml
|
|
19
|
+
Requires-Dist: rcsb-utils-io>=1.50
|
|
20
|
+
Provides-Extra: tests
|
|
21
|
+
Requires-Dist: black>=21.5b1; extra == 'tests'
|
|
22
|
+
Requires-Dist: check-manifest; extra == 'tests'
|
|
23
|
+
Requires-Dist: coverage; extra == 'tests'
|
|
24
|
+
Requires-Dist: flake8; extra == 'tests'
|
|
25
|
+
Requires-Dist: pylint; extra == 'tests'
|
|
26
|
+
Requires-Dist: tox; extra == 'tests'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# RCSB Python Enzyme Classification Data Utilities
|
|
30
|
+
|
|
31
|
+
[](https://dev.azure.com/rcsb/RCSB%20PDB%20Python%20Projects/_build/latest?definitionId=3&branchName=master)
|
|
32
|
+
|
|
33
|
+
## Introduction
|
|
34
|
+
|
|
35
|
+
Python utility classes for accessing Enzyme Commission classification data
|
|
36
|
+
|
|
37
|
+
### Installation
|
|
38
|
+
|
|
39
|
+
Download the library source software from the project repository:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
|
|
43
|
+
git clone --recurse-submodules https://github.com/rcsb/py-rcsb_utils_ec.git
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Optionally, run test suite (Python versions 3.9+) using
|
|
48
|
+
[tox](http://tox.readthedocs.io/en/latest/example/platform.html):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
tox
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Installation is via the program [pip](https://pypi.python.org/pypi/pip).
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install rcsb.utils.ec
|
|
58
|
+
|
|
59
|
+
or for the local repository:
|
|
60
|
+
|
|
61
|
+
pip install .
|
|
62
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
rcsb/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
|
|
2
|
+
rcsb/utils/__init__.py,sha256=ED6jHcYiuYpr_0vjGz0zx2lrrmJT9sDJCzIljoDfmlM,65
|
|
3
|
+
rcsb/utils/ec/EnzymeDatabaseProvider.py,sha256=ltEjjzlkqHSvq_5rBBvn1gVzkMFBJvzJ4IDLBmdNQ8w,18908
|
|
4
|
+
rcsb/utils/ec/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
rcsb_utils_ec-0.27.dist-info/METADATA,sha256=WyRmPEGpva49H3Gs6RM1F6MviiskqneL-La8BcUV2gY,1926
|
|
6
|
+
rcsb_utils_ec-0.27.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
7
|
+
rcsb_utils_ec-0.27.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
8
|
+
rcsb_utils_ec-0.27.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|