|
15 | 15 | }, |
16 | 16 | { |
17 | 17 | "cell_type": "code", |
18 | | - "execution_count": 10, |
| 18 | + "execution_count": 1, |
19 | 19 | "metadata": {}, |
20 | 20 | "outputs": [], |
21 | 21 | "source": [ |
|
35 | 35 | }, |
36 | 36 | { |
37 | 37 | "cell_type": "code", |
38 | | - "execution_count": 27, |
| 38 | + "execution_count": 2, |
39 | 39 | "metadata": {}, |
40 | 40 | "outputs": [ |
41 | 41 | { |
42 | 42 | "data": { |
43 | 43 | "application/vnd.jupyter.widget-view+json": { |
44 | | - "model_id": "d19cd6f1a72444d0bdbb976f3722b5cf", |
| 44 | + "model_id": "1b3cafb2bea34d4f8c77ecd284a6be91", |
45 | 45 | "version_major": 2, |
46 | 46 | "version_minor": 0 |
47 | 47 | }, |
|
86 | 86 | }, |
87 | 87 | { |
88 | 88 | "cell_type": "code", |
89 | | - "execution_count": 6, |
| 89 | + "execution_count": 3, |
90 | 90 | "metadata": {}, |
91 | 91 | "outputs": [], |
92 | 92 | "source": [ |
|
108 | 108 | }, |
109 | 109 | { |
110 | 110 | "cell_type": "code", |
111 | | - "execution_count": 19, |
| 111 | + "execution_count": 4, |
112 | 112 | "metadata": {}, |
113 | 113 | "outputs": [ |
114 | 114 | { |
115 | 115 | "data": { |
116 | 116 | "application/vnd.jupyter.widget-view+json": { |
117 | | - "model_id": "c3de0d5f8fe04244901098bccc3e3138", |
| 117 | + "model_id": "ed1b4914099d4a00804fd6df811cab1c", |
118 | 118 | "version_major": 2, |
119 | 119 | "version_minor": 0 |
120 | 120 | }, |
|
148 | 148 | }, |
149 | 149 | { |
150 | 150 | "cell_type": "code", |
151 | | - "execution_count": 21, |
| 151 | + "execution_count": 5, |
152 | 152 | "metadata": {}, |
153 | 153 | "outputs": [ |
154 | 154 | { |
155 | 155 | "data": { |
156 | 156 | "application/vnd.jupyter.widget-view+json": { |
157 | | - "model_id": "c33f4f8843474fa08fe80ba27f3ce68a", |
| 157 | + "model_id": "ac18776655314fb5af4bb64c530e33a0", |
158 | 158 | "version_major": 2, |
159 | 159 | "version_minor": 0 |
160 | 160 | }, |
|
182 | 182 | }, |
183 | 183 | { |
184 | 184 | "cell_type": "code", |
185 | | - "execution_count": 22, |
| 185 | + "execution_count": 6, |
186 | 186 | "metadata": {}, |
187 | 187 | "outputs": [ |
188 | 188 | { |
189 | 189 | "data": { |
190 | 190 | "application/vnd.jupyter.widget-view+json": { |
191 | | - "model_id": "90a9b007ca4044019846c10545c78d9e", |
| 191 | + "model_id": "9b62090602234268a15aa01167f5ae2b", |
192 | 192 | "version_major": 2, |
193 | 193 | "version_minor": 0 |
194 | 194 | }, |
|
211 | 211 | "cell_type": "markdown", |
212 | 212 | "metadata": {}, |
213 | 213 | "source": [ |
| 214 | + "# Further interactivity using ipywidgets \n", |
| 215 | + "\n", |
214 | 216 | "A user also has the ability to add further interactivity to the visualisations using the ipywidgets interact function, an example below shows an interactive visualisation where the user can select the molecule to display using a dropdown box and also update the layout." |
215 | 217 | ] |
216 | 218 | }, |
217 | 219 | { |
218 | 220 | "cell_type": "code", |
219 | | - "execution_count": 26, |
| 221 | + "execution_count": 7, |
220 | 222 | "metadata": {}, |
221 | 223 | "outputs": [ |
222 | 224 | { |
223 | 225 | "data": { |
224 | 226 | "application/vnd.jupyter.widget-view+json": { |
225 | | - "model_id": "33ca354a1d0647dbbd12751259795121", |
| 227 | + "model_id": "bd68bd2e87a74c2a9bf0aa6824f3dad1", |
226 | 228 | "version_major": 2, |
227 | 229 | "version_minor": 0 |
228 | 230 | }, |
|
259 | 261 | " layout=layouts\n", |
260 | 262 | ");" |
261 | 263 | ] |
| 264 | + }, |
| 265 | + { |
| 266 | + "cell_type": "markdown", |
| 267 | + "metadata": {}, |
| 268 | + "source": [ |
| 269 | + "# Style Customization\n", |
| 270 | + "\n", |
| 271 | + "The user also has the ability to customize various aspects of the widgets style. Fopr example the nodes can be coloured based on an attribute. The example shows how to colour scaffold nodes based on the 'hierarchy' attribute." |
| 272 | + ] |
| 273 | + }, |
| 274 | + { |
| 275 | + "cell_type": "code", |
| 276 | + "execution_count": 8, |
| 277 | + "metadata": {}, |
| 278 | + "outputs": [ |
| 279 | + { |
| 280 | + "data": { |
| 281 | + "application/vnd.jupyter.widget-view+json": { |
| 282 | + "model_id": "5ff71126406b4fad84a0eaeae7262566", |
| 283 | + "version_major": 2, |
| 284 | + "version_minor": 0 |
| 285 | + }, |
| 286 | + "text/plain": [ |
| 287 | + "CytoscapeWidget(cytoscape_layout={'name': 'dagre', 'nodeSpacing': 50, 'edgeLengthVal': 50}, cytoscape_style=[{…" |
| 288 | + ] |
| 289 | + }, |
| 290 | + "metadata": {}, |
| 291 | + "output_type": "display_data" |
| 292 | + } |
| 293 | + ], |
| 294 | + "source": [ |
| 295 | + "from scaffoldgraph.vis import color_scaffold_nodes_by_attribute\n", |
| 296 | + "from rdkit.Chem.Draw import rdMolDraw2D\n", |
| 297 | + "\n", |
| 298 | + "# Add a 'background-color' attribute to each scaffold node.\n", |
| 299 | + "# The cmap can either be a string or a matplotlib.cm.Colormap object.\n", |
| 300 | + "color_scaffold_nodes_by_attribute(tree, 'hierarchy', cmap='BuPu', label='color')\n", |
| 301 | + "\n", |
| 302 | + "# Create a style element for the visualizer.\n", |
| 303 | + "background_style = {\n", |
| 304 | + " \"selector\": \"node[color]\", # select nodes with an attribute 'color'\n", |
| 305 | + " \"style\": {\n", |
| 306 | + " \"background-color\": \"data(color)\", # set background-color from attribute.\n", |
| 307 | + " }\n", |
| 308 | + "}\n", |
| 309 | + "\n", |
| 310 | + "# We can also customize rdkit drawing options (need a transparent background).\n", |
| 311 | + "drawOpts = rdMolDraw2D.MolDrawOptions()\n", |
| 312 | + "drawOpts.clearBackground = False\n", |
| 313 | + "drawOpts.bondLineWidth = 4\n", |
| 314 | + "\n", |
| 315 | + "# Create a new visualizer with new options.\n", |
| 316 | + "vis = cytoscape.CytoscapeVisualizer(\n", |
| 317 | + " tree,\n", |
| 318 | + " refresh_images=True,\n", |
| 319 | + " rd_draw_options=drawOpts,\n", |
| 320 | + ")\n", |
| 321 | + "\n", |
| 322 | + "# Append the style element to the visualizer.\n", |
| 323 | + "vis.style.append(background_style)\n", |
| 324 | + "\n", |
| 325 | + "# Create visualization.\n", |
| 326 | + "widget = vis.draw_for_scaffold('c1ccncc1')\n", |
| 327 | + "widget.layout.height = '600px'\n", |
| 328 | + "widget\n" |
| 329 | + ] |
| 330 | + }, |
| 331 | + { |
| 332 | + "cell_type": "code", |
| 333 | + "execution_count": null, |
| 334 | + "metadata": {}, |
| 335 | + "outputs": [], |
| 336 | + "source": [] |
262 | 337 | } |
263 | 338 | ], |
264 | 339 | "metadata": { |
|
0 commit comments