Closed johnnytam100 closed 2 years ago
Hmm, I think I see what’s going on.
Could you try changing some combinations of the parameters in extract_subgraph_from_chains
- particularly update_coords=False
Hi Arian, thanks again for the suggestions!
With update_coords=False
, the pickle was successful.
But then seems the pickled subgraphs have some problems when fit into the machine learning model .
That I got an error:
RuntimeError: The expanded size of the tensor (1574) must match the existing size (904) at non-singleton dimension 0. Target sizes: [1574, 8]. Tensor sizes: [904, 1]
May I know what does update_coords=False
do?
Perfect!
So, update_coords
recomputes the the coordinate array in g.graph["coords"]
. Since we are taking a subgraph, we need to remove some of the coordinates from the original. The problem is this line which is a generator comprehension (which causes the pickling to fail). It's an easy fix to switch this to a list comprehension and I will do this today.
To fix your problem in the meantime, I think you can do something like:
g.graph["coords"] = np.array([
d["coords"] for d in g.nodes(data=True)]
)
After loading the pickle
I see! Thanks for the workaround! Hmmm, and I got the following error:
graph = pickle.load(f)
graph.graph["coords"] = np.array([d["coords"] for d in graph.nodes(data=True)])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
[<ipython-input-11-459a4f297166>](https://localhost:8080/#) in <module>()
32 with open(path, 'rb') as f: # notice the r instead of w
33 graph = pickle.load(f)
---> 34 graph.graph["coords"] = np.array([d["coords"] for d in graph.nodes(data=True)])
35 graph_list.append(graph)
36
[<ipython-input-11-459a4f297166>](https://localhost:8080/#) in <listcomp>(.0)
32 with open(path, 'rb') as f: # notice the r instead of w
33 graph = pickle.load(f)
---> 34 graph.graph["coords"] = np.array([d["coords"] for d in graph.nodes(data=True)])
35 graph_list.append(graph)
36
TypeError: tuple indices must be integers or slices, not str
Do you know how to deal with it? Thanks again!!!
Yep @johnnytam100, I made a typo. It should be:
g.graph["coords"] = np.array([
d["coords"] for _, d in g.nodes(data=True)]
)
Just running the tests to get these fixes merged in. 1.2.1
should be available tonight :)
Should be good to go! 🚀 pip install graphein==1.2.1
Thank you @a-r-j ! It is fine now with pip install graphein==1.2.1
! :)
Perfect! Don’t hesitate to open another issue if you find something else that’s not behaving as expected. It’s incredibly helpful :)
Hi Arian, I am trying the graphein.protein.subgraphs.extract_subgraph_from_chains() you suggested.
After that, I want to pickle the graph.
Originally, pickling with the original graph worked fine:
However, when the graphein.protein.subgraphs.extract_subgraph_from_chains() was called, the pickling of both the original graph and the subgraph became not to work.
Do you know why graphein.protein.subgraphs.extract_subgraph_from_chains() changed the behavior of pickle?
Thanks again!