a-r-j / graphein

Protein Graph Library
https://graphein.ai/
MIT License
1.03k stars 131 forks source link

Getting 61 descriptors for amino acid residues from ExPaSY ProtScale #97

Closed diamondspark closed 2 years ago

diamondspark commented 2 years ago

@a-r-j I'm trying to get node features for residual level graph. Following is my code

new_prot_nodes = {"node_metadata_functions":[meiler_embedding,expasy_protein_scale]}
config_full = ProteinGraphConfig(**new_prot_nodes,**new_edge_funcs)
print (config_full.dict())
g = construct_graph(config=config_full, pdb_path=df.path[0])

How do I access these features?

a-r-j commented 2 years ago

Hi @diamondspark they’re stored as node attributes. You can check out the NetworkX docs for more info: https://networkx.org/documentation/stable/reference/classes/generated/networkx.Graph.nodes.html

https://networkx.org/documentation/stable/reference/generated/networkx.classes.function.get_node_attributes.html

In short:

g.nodes(data=True)

# Or iterate over them:
for n, d in g.nodes(data=True):
    …

Let me know how you get on :)

diamondspark commented 2 years ago

Thank you @a-r-j, this works. I further convert this to Pytorch geometric (Pyg) graph. I'm going through your code for GraphFormatConvertor and doesn't look like it captures node attributes in conversion. I think I need to add these features to PyG nodes manually unless I'm missing something.

Thank you once again for your work.

a-r-j commented 2 years ago

No worries, there’s the columns Parameter in the GraphFormatConvertor Object that you can use to save these features. https://graphein.ai/modules/graphein.ml.html#module-graphein.ml.conversion

diamondspark commented 2 years ago

Thank you! Works!