Git Product home page Git Product logo

Comments (7)

OliverBScott avatar OliverBScott commented on August 12, 2024

Hi, I am not sure if you found the answer. The visualization utilities will be available in the next release. If you want to use them now you can install from the master branch.

from scaffoldgraph.

707-Moira avatar 707-Moira commented on August 12, 2024

Hi, I am not sure if you found the answer. The visualization utilities will be available in the next release. If you want to use them now you can install from the master branch.

I may have solved the problem by copying the source code directly to my envs. Iโ€™m wondering if there is a function to output what I have arranged in the interactive window as picture format, as I currently havenโ€™t found how to realize it in the source code. I presume this may be achieved directly through ipycytoscape, but there seems no such information in that repository (or maybe I missed sth). I have to consider using networkx to finish the drawing now...

from scaffoldgraph.

OliverBScott avatar OliverBScott commented on August 12, 2024

There isn't a function for exporting the window as an image within scaffoldgraph. I am not even sure there is one in ipycytoscape unfortunately, although I think this would be a great feature! I found this issue related to saving/exporting images although it seems like not much progress has been made, it may be worth making a comment on that thread. For now, I have been using screenshots of the window although I realise this is not ideal.

Concerning networkx, I always found the drawing code particularly clunky, although if you end up using it and create something decent, I would love to integrate a networkx (or any other tool) based visualisation tool into the scaffoldgraph source code.

I have also found this tool based on cytoscapejs/plotly. Looks like it supports image export too. Let me know if you find a good solution.

from scaffoldgraph.

707-Moira avatar 707-Moira commented on August 12, 2024

There isn't a function for exporting the window as an image within scaffoldgraph. I am not even sure there is one in ipycytoscape unfortunately, although I think this would be a great feature! I found this issue related to saving/exporting images although it seems like not much progress has been made, it may be worth making a comment on that thread. For now, I have been using screenshots of the window although I realise this is not ideal.

Concerning networkx, I always found the drawing code particularly clunky, although if you end up using it and create something decent, I would love to integrate a networkx (or any other tool) based visualisation tool into the scaffoldgraph source code.

I have also found this tool based on cytoscapejs/plotly. Looks like it supports image export too. Let me know if you find a good solution.

Many thanks to the tool 'dash' and I found it quite useful (even for other kind of figures). And I'm trying to integrate the drawing function of rdkit in it. More important function of visualization to me is the change of color with each node, as we always need to give value to each node and see all that distribution. Maybe the change of the color of each node will be a good choice, though the background of the drawing of the mol seems need to be set as trasparent, which I haven't found a way to realize. Just the same as the figure shown in the orignal paper of scaffold tree which is shown below (the author may not generate the figure automatically but I'd like to have a try as my data may be a little huge). Anyway, this provides an alternative worth trying.
image

from scaffoldgraph.

OliverBScott avatar OliverBScott commented on August 12, 2024

There isn't a function for exporting the window as an image within scaffoldgraph. I am not even sure there is one in ipycytoscape unfortunately, although I think this would be a great feature! I found this issue related to saving/exporting images although it seems like not much progress has been made, it may be worth making a comment on that thread. For now, I have been using screenshots of the window although I realise this is not ideal.
Concerning networkx, I always found the drawing code particularly clunky, although if you end up using it and create something decent, I would love to integrate a networkx (or any other tool) based visualisation tool into the scaffoldgraph source code.
I have also found this tool based on cytoscapejs/plotly. Looks like it supports image export too. Let me know if you find a good solution.

Many thanks to the tool 'dash' and I found it quite useful (even for other kind of figures). And I'm trying to integrate the drawing function of rdkit in it. More important function of visualization to me is the change of color with each node, as we always need to give value to each node and see all that distribution. Maybe the change of the color of each node will be a good choice, though the background of the drawing of the mol seems need to be set as trasparent, which I haven't found a way to realize. Just the same as the figure shown in the orignal paper of scaffold tree which is shown below (the author may not generate the figure automatically but I'd like to have a try as my data may be a little huge). Anyway, this provides an alternative worth trying.
image

I am going to have a go at playing around with a dash based visualization utility, although I don't know when I will have enough time to create something viable. The dash-cytoscape implementation shouldn't be too different from the ipycytoscape implementation as they both use cytoscapejs. The style-sheet used here should be transferable.

Concerning colouring the background of a node this is a little trickier (to get a nice color map, yet entirely possible!), rather it would be much easier to colour the node border by adding a 'color' attribute to each node and updating the stylesheet accordingly.

I drafted some quick ideas colouring the border/background based on the scaffolds hierarchy. Of course, this could be extended to any scaffold/molecule attribute:

import scaffoldgraph as sg
import matplotlib.pyplot as plt
import matplotlib as mpl

from scaffoldgraph.vis.notebook import cytoscape


def f2hex(f2rgb, f):
    rgb = f2rgb.to_rgba(f)[:3]
    return '#%02x%02x%02x' % tuple([int(255 * fc) for fc in rgb])


# Create graph.
tree = sg.ScaffoldTree.from_sdf('my_mols.sdf')

# Create color map based on 'hierarchy' attribute.
vmin, vmax = 1, 6
cmap = plt.get_cmap('inferno_r')
cnorm = mpl.colors.Normalize(vmin, vmax)
scalarmap = mpl.cm.ScalarMappable(norm=cnorm, cmap=cmap)

# Map colors to nodes based on 'hierarchy attribute'.
for node, data in tree.get_scaffold_nodes(True):
    c = f2hex(scalarmap, data['hierarchy'])
    data['color'] = c
  
# Create style for nodes with a 'color' attribute.
border_style = {
    "selector": "node[color]",
    "style": {
        "border-color": "data(color)",
        "border-width": "6",
    }
}

# Create visualizer.
vis = cytoscape.CytoscapeVisualizer(tree)
vis.style.append(border_style)  # Add border style.

# Render for a scaffold.
vis.draw_for_scaffold('c1ccccc1')

Screen Shot 2021-01-06 at 12 00 07

And to colour the backgrounds (I created a custom colour map based on the figure you showed from the paper):

from scaffoldgraph.vis import embed_node_mol_images
from rdkit.Chem.Draw import rdMolDraw2D

# Make backgrounds transparent.
drawOpts = rdMolDraw2D.MolDrawOptions()
drawOpts.clearBackground = False

# Embed images into nodes.
embed_node_mol_images(tree, draw_options=drawOpts, skip_existing=False)

# Custom cmap (no colours that are too dark).
cmap = mpl.colors.LinearSegmentedColormap.from_list('white2yellow', ['#FFFFFF', '#F2EC54'])
cnorm = mpl.colors.Normalize(vmin, vmax)
scalarmap = mpl.cm.ScalarMappable(norm=cnorm, cmap=cmap)

# Map colors to nodes.
for node, data in tree.nodes(data=True):
    if data['type'] == 'molecule':  # Neutral color for molecules.
        data['color'] = '#EEEEEE'
    elif data['type'] == 'scaffold':  # scaffold color based on hierarchy.
        c = f2hex(scalarmap, data['hierarchy'])
        data['color'] = c

# Create background style.
background_style = {
    "selector": "node[color]",
    "style": {
        "background-color": "data(color)",
    }
}

# Create visualizer.
vis = cytoscape.CytoscapeVisualizer(tree)
vis.style.append(background_style)  # Add background style.

# Render for scaffold.
vis.draw_for_scaffold('c1ccccc1')

Screen Shot 2021-01-06 at 11 27 37

I am not sure whether the mol images should have a transparent background by default or whether I should add it as an option to the visualizer. I will also probably add some functions to create colour maps based on node attributes and adding these as attributes to the graph to make this process easier.

from scaffoldgraph.

707-Moira avatar 707-Moira commented on August 12, 2024

Another problem may lie on the compatibility on different python versions. I ran quite well on python 3.7. However, considering version 3.5 and 3.6, there seem some bugs, especially that python 3.5 cannot support f-string, which relates to some outputs. If this currently must be run on python 3.7 (as rdkit may not support well beyond 3.7), maybe you can consider illustrate it in README

from scaffoldgraph.

OliverBScott avatar OliverBScott commented on August 12, 2024

Another problem may lie on the compatibility on different python versions. I ran quite well on python 3.7. However, considering version 3.5 and 3.6, there seem some bugs, especially that python 3.5 cannot support f-string, which relates to some outputs. If this currently must be run on python 3.7 (as rdkit may not support well beyond 3.7), maybe you can consider illustrate it in README

I agree with respect to python 3.5, I will make a note of this in the README. What issues have you witnessed with python 3.6? All of the tests are successful using python 3.6 (travis-ci), although the vis modules currently have no tests.As for rdkit the conda-forge channel seems to have builds for 3.6, 7, 8 and 9. The rdkit channel seems to only have builds for 3.6 and 3.7 although is also a version behind.

from scaffoldgraph.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.