You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Load ChEBI graph from Hugging Face (if filename is None) or local file"""
11
12
iffilenameisNone:
12
-
print(f"Loading ChEBI graph from Hugging Face...")
13
+
print("Loading ChEBI graph from Hugging Face...")
13
14
file=download_model_files(
14
-
{
15
-
"repo_id": "chebai/chebifier",
16
-
"repo_type": "dataset",
17
-
"files": {"f": "chebi_graph.pkl"},
18
-
}
19
-
)["f"]
15
+
{
16
+
"repo_id": "chebai/chebifier",
17
+
"repo_type": "dataset",
18
+
"files": {"f": "chebi_graph.pkl"},
19
+
}
20
+
)["f"]
20
21
else:
21
22
print(f"Loading ChEBI graph from local {filename}...")
22
23
file=filename
23
24
returnpickle.load(open(file, "rb"))
24
25
26
+
25
27
defterm_callback(doc):
26
28
"""Similar to the chebai function, but reduced to the necessary fields. Also, ChEBI IDs are strings"""
27
29
parents= []
@@ -41,7 +43,7 @@ def term_callback(doc):
41
43
smiles=clause.raw_value().split('"')[1]
42
44
elifisinstance(clause, fastobo.term.IsAClause):
43
45
chebi_id=str(clause.term)
44
-
chebi_id=chebi_id[chebi_id.index(":") +1:]
46
+
chebi_id=chebi_id[chebi_id.index(":") +1:]
45
47
parents.append(chebi_id)
46
48
elifisinstance(clause, fastobo.term.NameClause):
47
49
name=str(clause.name)
@@ -51,14 +53,15 @@ def term_callback(doc):
51
53
# if the term document contains clause as obsolete as true, skips this document.
52
54
returnFalse
53
55
chebi_id=str(doc.id)
54
-
chebi_id=chebi_id[chebi_id.index(":") +1:]
56
+
chebi_id=chebi_id[chebi_id.index(":") +1:]
55
57
return {
56
58
"id": chebi_id,
57
59
"parents": parents,
58
60
"name": name,
59
61
"smiles": smiles,
60
62
}
61
63
64
+
62
65
defbuild_chebi_graph(chebi_version=241):
63
66
"""Creates a networkx graph for the ChEBI hierarchy. Usually, you don't want to call this function directly, but rather use the `load_chebi_graph` function."""
0 commit comments