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

Can't plot adjacency matrix of subgraph #177

Open
kamurani opened this issue Jun 5, 2022 · 8 comments
Open

Can't plot adjacency matrix of subgraph #177

kamurani opened this issue Jun 5, 2022 · 8 comments

Comments

@kamurani
Copy link
Contributor

kamurani commented Jun 5, 2022

Hi there,

Just getting started with Graphein and so far it's awesome, the docs are very helpful too -- my issue is with trying to plot a subgraph from a protein graph g.

Not sure if I'm doing something wrong, but I cannot plot the subgraph s_g using the adjacency matrix. I get the following error from plotly:

ValueError: The length of the y vector must match the length of the first dimension of the img matrix.

It seems to be the fact that my subgraph has 7 nodes, but the adjacency matrix still has all 760 nodes from the original protein.

Not sure why this is the case since I am using the recompute_distmat option?

My code:

k = 3
s_g = extract_k_hop_subgraph(g, central_node=phos_site, k=k, recompute_distmat=True)

print(s_g) # 7 nodes 
print(s_g.graph['dist_mat']) # all original 760 nodes?

fig = plot_distance_matrix(s_g)  # this line gives the error
fig.write_html("visual.html")

Thanks in advance, and apologies if i'm missing something.

@a-r-j
Copy link
Owner

a-r-j commented Jun 10, 2022

Hi @cimranm will check this out for you on the weekend. Could you true using filter_dataframe=True and maybe update_coords=True too?

@a-r-j
Copy link
Owner

a-r-j commented Jun 10, 2022

Figured it out, typo here:

g.graph["distmat"] = compute_distmat(g.graph["pdb_df"])

should be "dist_mat", not "distmat". Have pushed a fix to master.

@kamurani
Copy link
Contributor Author

Hey @a-r-j , yep I figured the same thing but was waiting to hear back from you -- I actually modified visualisation.py to use g.graph["distmat"] as I wasn't sure what behaviour you wanted (i.e. the original adjacency matrix should still be accessible from a subgraph?)

Anyway, thanks for the fix :)

@kamurani
Copy link
Contributor Author

@a-r-j another issue is when the subgraph is plotted, the node labels are assigned to the x and y axes randomly (but the actual distance matrix cols / rows are plotted in sequence order). At the moment i've fixed this using the following:

# in graphein.protein.visualisation.plot_distance_matrix

x_range = list(g.nodes)
x_range = sorted(x_range, key=lambda x: int(x.split(':')[-1]))

Hope that makes sense!

@a-r-j
Copy link
Owner

a-r-j commented Jun 12, 2022

Good spot. Seems like the start of a solution, but I think your solution breaks down with multichain proteins, no?

@kamurani
Copy link
Contributor Author

@a-r-j yep you're right, shall I give it a go and submit a pull request?

On another note, do you think it would be appropriate to allow other options for ordering the axes..? At the moment i'm trying to visualise a protein motif with the adjacency matrix and was thinking of ordering by distance from the central node (i.e. central node AA is the first; then AAs are in ascending order of euclidean distance). Would it make sense to have a feature within the plot functions that changes the ordering?

@a-r-j
Copy link
Owner

a-r-j commented Jun 13, 2022

Yep, go ahead with a PR. Happy to review & support :)

That's an interesting use case you've described. I think it would be a good addition. The plot functions accept a distance matrix (separately from a graph) which I anticipated could be used for this sort of thing. However, if this is something that would be really useful for you it's probably useful for others and so we should support it.

@a-r-j
Copy link
Owner

a-r-j commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants