Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improved error message for non standard node funcs #274 #275

Merged
merged 2 commits into from
Mar 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions graphein/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def annotate_edge_metadata(G: nx.Graph, funcs: List[Callable]) -> nx.Graph:

def annotate_node_metadata(G: nx.Graph, funcs: List[Callable]) -> nx.Graph:
"""
Annotates nodes with metadata. Each function in ``funcs`` must take two arguments ``n`` and ``d``, where ``n`` is the node and ``d`` is the node data dictionary.
Annotates nodes with metadata. Each function in ``funcs`` must take two arguments ``n`` and ``d``, where ``n`` is the node and ``d`` is the node data dictionary. Some functions, like esm residue embeddings, should be used as graph metadata functions as they require access to the whole sequence.

Additional parameters can be provided by using partial functions.

Expand All @@ -109,7 +109,13 @@ def annotate_node_metadata(G: nx.Graph, funcs: List[Callable]) -> nx.Graph:

for func in funcs:
for n, d in G.nodes(data=True):
func(n, d)
try:
func(n, d)
except (TypeError, AttributeError) as e:
raise type(e)(
str(e)
+ "Please ensure that provided node metadata functions match the f(n: str, d: Dict) function signature, where n is the node ID and d is the node data dictionary "
).with_traceback(sys.exc_info()[2])
return G


Expand Down