Skip to content

Commit e789470

Browse files
committed
reformat with black
1 parent 6132fa2 commit e789470

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

chebifier/inconsistency_resolution.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import torch
44
from pathlib import Path
55

6+
67
def get_disjoint_groups(disjoint_files):
78
if disjoint_files is None:
89
disjoint_files = os.path.join("data", "chebi-disjoints.owl")

chebifier/utils.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
from chebifier.hugging_face import download_model_files
77
import pickle
88

9+
910
def load_chebi_graph(filename=None):
1011
"""Load ChEBI graph from Hugging Face (if filename is None) or local file"""
1112
if filename is None:
12-
print(f"Loading ChEBI graph from Hugging Face...")
13+
print("Loading ChEBI graph from Hugging Face...")
1314
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"]
2021
else:
2122
print(f"Loading ChEBI graph from local {filename}...")
2223
file = filename
2324
return pickle.load(open(file, "rb"))
2425

26+
2527
def term_callback(doc):
2628
"""Similar to the chebai function, but reduced to the necessary fields. Also, ChEBI IDs are strings"""
2729
parents = []
@@ -41,7 +43,7 @@ def term_callback(doc):
4143
smiles = clause.raw_value().split('"')[1]
4244
elif isinstance(clause, fastobo.term.IsAClause):
4345
chebi_id = str(clause.term)
44-
chebi_id = chebi_id[chebi_id.index(":") + 1:]
46+
chebi_id = chebi_id[chebi_id.index(":") + 1 :]
4547
parents.append(chebi_id)
4648
elif isinstance(clause, fastobo.term.NameClause):
4749
name = str(clause.name)
@@ -51,14 +53,15 @@ def term_callback(doc):
5153
# if the term document contains clause as obsolete as true, skips this document.
5254
return False
5355
chebi_id = str(doc.id)
54-
chebi_id = chebi_id[chebi_id.index(":") + 1:]
56+
chebi_id = chebi_id[chebi_id.index(":") + 1 :]
5557
return {
5658
"id": chebi_id,
5759
"parents": parents,
5860
"name": name,
5961
"smiles": smiles,
6062
}
6163

64+
6265
def build_chebi_graph(chebi_version=241):
6366
"""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."""
6467
chebi_path = os.path.join("data", f"chebi_v{chebi_version}", "chebi.obo")
@@ -73,9 +76,9 @@ def build_chebi_graph(chebi_version=241):
7376
elements = []
7477
for term_doc in fastobo.loads(chebi):
7578
if (
76-
term_doc
77-
and isinstance(term_doc.id, fastobo.id.PrefixedIdent)
78-
and term_doc.id.prefix == "CHEBI"
79+
term_doc
80+
and isinstance(term_doc.id, fastobo.id.PrefixedIdent)
81+
and term_doc.id.prefix == "CHEBI"
7982
):
8083
term_dict = term_callback(term_doc)
8184
if term_dict:
@@ -121,8 +124,8 @@ def get_disjoint_files():
121124

122125

123126
if __name__ == "__main__":
124-
#chebi_graph = build_chebi_graph(chebi_version=241)
127+
# chebi_graph = build_chebi_graph(chebi_version=241)
125128
# save the graph to a file
126-
#pickle.dump(chebi_graph, open("chebi_graph.pkl", "wb"))
129+
# pickle.dump(chebi_graph, open("chebi_graph.pkl", "wb"))
127130
chebi_graph = load_chebi_graph()
128-
print(chebi_graph)
131+
print(chebi_graph)

0 commit comments

Comments
 (0)