Skip to content

Commit 043b9bb

Browse files
author
Oliver Scott
committed
Add method for removing embedded images to utils __init__.py.
1 parent bcc5837 commit 043b9bb

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

scaffoldgraph/vis/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from scaffoldgraph.core import ScaffoldGraph
1010
from scaffoldgraph.utils import canonize_smiles
1111

12+
from .utils import remove_node_mol_images
13+
1214

1315
class Visualizer(ABC):
1416
"""Base class for ScaffoldGraph visualizers.
@@ -21,7 +23,7 @@ class Visualizer(ABC):
2123
scaffoldgraph.vis.notebook.cytoscape.CytoscapeVisualizer
2224
2325
"""
24-
def __init__(self, graph, requires_tree=False):
26+
def __init__(self, graph, requires_tree=False, refresh_images=False):
2527
"""Initialize the visualizer.
2628
2729
Parameters
@@ -31,9 +33,14 @@ def __init__(self, graph, requires_tree=False):
3133
requires_tree : bool, optional
3234
Whether the visualizer requires a tree
3335
structure to create a visualization.
36+
refresh_images: bool, optional
37+
If True remove all embeded images from the
38+
input graph and regenerate when required.
39+
The default is False.
3440
3541
"""
3642
self._requires_tree = requires_tree
43+
self._refresh = refresh_images
3744
self._graph = self._validate_graph(graph)
3845

3946
@property
@@ -56,6 +63,8 @@ def _validate_graph(self, graph):
5663
msg = '{} requires a tree/forest structured graph'
5764
msg.format(self.__class__.__name__)
5865
raise ValueError(msg)
66+
if self._refresh is True:
67+
remove_node_mol_images(graph)
5968
return graph
6069

6170
def _subgraph_from_mol(self, molecule):

scaffoldgraph/vis/notebook/cytoscape.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CytoscapeVisualizer(Visualizer):
8989
>>> visualizer.draw_for_scaffold('c1ccc(CNc2ccccc2)cc1')
9090
9191
"""
92-
def __init__(self, graph, style=None):
92+
def __init__(self, graph, style=None, refresh_images=False):
9393
"""Initialize the cytoscape visualizer.
9494
9595
Parameters
@@ -102,9 +102,17 @@ def __init__(self, graph, style=None):
102102
see the ipycytoscape documentation. If None
103103
a default style is used and can be updated
104104
after initialization.
105+
refresh_images: bool, optional
106+
If True remove all embeded images from the
107+
input graph and regenerate when required.
108+
The default is False.
105109
106110
"""
107-
super(CytoscapeVisualizer, self).__init__(graph, requires_tree=False)
111+
super(CytoscapeVisualizer, self).__init__(
112+
graph,
113+
requires_tree=False,
114+
refresh_images=refresh_images,
115+
)
108116
self._style = style if style else read_style_file(DEFAULT_STYLE)
109117

110118
@property

0 commit comments

Comments
 (0)