-
-
Notifications
You must be signed in to change notification settings - Fork 137
Graph plots #197
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
Open
kamurani
wants to merge
29
commits into
a-r-j:master
Choose a base branch
from
kamurani:graph_plots
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Graph plots #197
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
622d7b8
Fix param name typo in function docstring
kamurani 8a3f3a4
add scaling node size by "rsa" feature as well as degree
kamurani 9c9520b
add option for scaling node size by meiler embedding dimensions. Tak…
kamurani 44a0bf8
remove walrus operator := for compatability
kamurani 920e14e
Merge pull request #1 from a-r-j/master
kamurani efc69bb
Merge pull request #2 from a-r-j/master
kamurani a2806b6
Add type hints
a-r-j 024e7a0
Update changelog
a-r-j 7569751
add support for sizing nodes by RSA and colouring by hydrophobicity i…
kamurani 66baf18
Merge remote-tracking branch 'origin/master' into graph_plots
kamurani 3513e0c
Merge branch 'master' into graph_plots
a-r-j 21d496a
add amino acid 3-letter code mapping to hydrophobicity scales from th…
kamurani 2f4f0ee
add amino acid 3-letter code mapping to hydrophobicity scales from th…
kamurani fbac7ea
colour by hydrophobicity implemented for different scales
kamurani 5878e4f
refactor `_node_feature` function; colour_by and size_by msupported w…
kamurani 8948b1f
fix import statement to use graphein actual
kamurani 1212d5e
add `hydrophobicity()`. not sure if should be passed a parameter dec…
kamurani 6b29498
"Add a utility for getting the names of node, edge and graph attribut…
a-r-j 00f99a5
fix edge attribute selection in util
a-r-j 28b0ee1
add test for attribute name selection util
a-r-j 8f22fed
use typing_extensions Literal for 3.7 support and update changelog
a-r-j 2b69d6e
docstring, black
a-r-j 9743332
black
a-r-j 43bc240
fix type import; black
a-r-j c5e6d83
Merge branch 'master' into graph_plots
a-r-j f43f5e7
Merge branch 'master' into graph_plots
a-r-j fd1f996
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 37aaee8
Merge branch 'master' into graph_plots
a-r-j 34c816b
Merge branch 'master' into graph_plots
a-r-j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
# Code Repository: https://github.com/a-r-j/graphein | ||
from __future__ import annotations | ||
|
||
import re | ||
import logging | ||
import re | ||
from itertools import count | ||
|
@@ -714,6 +715,7 @@ def asteroid_plot( | |
node_id: str, | ||
k: int = 2, | ||
colour_nodes_by: str = "shell", # residue_name | ||
size_nodes_by: str = "degree", | ||
colour_edges_by: str = "kind", | ||
edge_colour_map: plt.cm.Colormap = plt.cm.plasma, | ||
edge_alpha: float = 1.0, | ||
|
@@ -724,6 +726,7 @@ def asteroid_plot( | |
use_plotly: bool = True, | ||
show_edges: bool = False, | ||
show_legend: bool = True, | ||
node_size_min: float = 20, | ||
node_size_multiplier: float = 10, | ||
) -> Union[plotly.graph_objects.Figure, matplotlib.figure.Figure]: | ||
"""Plots a k-hop subgraph around a node as concentric shells. | ||
|
@@ -738,6 +741,8 @@ def asteroid_plot( | |
:type k: int | ||
:param colour_nodes_by: Colour the nodes by this attribute. Currently only ``"shell"`` is supported. | ||
:type colour_nodes_by: str | ||
:param size_nodes_by: Size the nodes by an attribute. | ||
:type size_nodes_by: str | ||
:param colour_edges_by: Colour the edges by this attribute. Currently only ``"kind"`` is supported. | ||
:type colour_edges_by: str | ||
:param edge_colour_map: Colour map for edges. Defaults to ``plt.cm.plasma``. | ||
|
@@ -756,8 +761,10 @@ def asteroid_plot( | |
:type show_edges: bool | ||
:param show_legend: Whether to show the legend of the edges. Fefaults to `True``. | ||
:type show_legend: bool | ||
:param node_size_min: Specifies node minimum size. Defaults to ``20.0``. | ||
:type node_size_min: float | ||
:param node_size_multiplier: Multiplier for the size of the nodes. Defaults to ``10``. | ||
:type node_size_multiplier: float. | ||
:type node_size_multiplier: float | ||
:returns: Plotly figure or matplotlib figure. | ||
:rtpye: Union[plotly.graph_objects.Figure, matplotlib.figure.Figure] | ||
""" | ||
|
@@ -817,21 +824,61 @@ def asteroid_plot( | |
node_x.append(x) | ||
node_y.append(y) | ||
|
||
degrees = [ | ||
subgraph.degree(n) * node_size_multiplier for n in subgraph.nodes() | ||
] | ||
def node_size_function(g: nx.Graph, feature: str): | ||
if feature == 'degree': | ||
return lambda k : g.degree(k) | ||
elif feature == 'rsa': | ||
return lambda k : g.nodes(data=True)[k]['rsa'] | ||
else: | ||
raise NotImplementedError(f"Size by {size_nodes_by} not implemented.") | ||
|
||
node_size = node_size_function(subgraph, size_nodes_by) | ||
node_sizes = [node_size_min + node_size(n) * node_size_multiplier for n in subgraph.nodes()] | ||
|
||
if colour_nodes_by == "shell": | ||
node_colours = [] | ||
for n in subgraph.nodes(): | ||
for k, v in nodes.items(): | ||
if n in v: | ||
node_colours.append(k) | ||
elif colour_nodes_by == "hydrophobicity": | ||
|
||
""" | ||
TODO Does a function like this already exist somewhere? | ||
""" | ||
def hydrophobicity_of_residue(res: str, mapping: str = 'a'): | ||
a-r-j marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hmap = { | ||
"ILE" : 4.5, | ||
"VAL" : 4.2, | ||
"LEU" : 3.8, | ||
"PHE" : 2.8, | ||
"CYS" : 2.5, | ||
"MET" : 1.9, | ||
"ALA" : 1.8, | ||
"GLY" : -0.4, | ||
"THR" : -0.7, | ||
"SER" : -0.8, | ||
"TRP" : -0.9, | ||
"TYR" : -1.3, | ||
"PRO" : -1.6, | ||
"HIS" : -3.2, | ||
"GLU" : -3.5, | ||
"GLN" : -3.5, | ||
"ASP" : -3.5, | ||
"ASN" : -3.5, | ||
"LYS" : -3.9, | ||
"ARG" : -4.5, | ||
} | ||
return hmap[res] | ||
|
||
node_colours = [] | ||
for n in subgraph.nodes(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you can replace this nested loop with: for n, d in subgraph.nodes(data=True)
... |
||
for k, v in nodes.items(): | ||
if n in v: | ||
node_colours.append(hydrophobicity_of_residue(n.split(':')[1])) | ||
else: | ||
raise NotImplementedError( | ||
f"Colour by {colour_nodes_by} not implemented." | ||
) | ||
# TODO colour by AA type | ||
raise NotImplementedError(f"Colour by {colour_nodes_by} not implemented.") | ||
|
||
node_trace = go.Scatter( | ||
x=node_x, | ||
y=node_y, | ||
|
@@ -841,13 +888,13 @@ def asteroid_plot( | |
textposition="bottom center", | ||
showlegend=False, | ||
marker=dict( | ||
colorscale="YlGnBu", | ||
colorscale="viridis", | ||
reversescale=True, | ||
color=node_colours, | ||
size=degrees, | ||
size=node_sizes, | ||
colorbar=dict( | ||
thickness=15, | ||
title="Shell", | ||
title=str.capitalize(colour_nodes_by), | ||
tickvals=list(range(k)), | ||
xanchor="left", | ||
titleside="right", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.