Mapping nodes sizes and adding legends in cytoscape network - python

I used networkx package in python to construct multiple networks, where each represents a biological experiment. I then exported these networks as gml files to visualize in cytoscape and make comparisons. In each file, I have two attributes for nodes- i.e., count and color. In cytoscape, I assign the node size to its count. However, there is a huge difference between the counts of nodes, for instance some have a count of 100 while others have a count of 50,000. I would like map the sizes of all nodes in all cytoscape networks to one scale and also have a legend indicating the relative sizes. An example is shown in right side of the image below! I hope you can help me!
Image source

The answer to the first part of the question is to construct a log(count) column. That should give you a better range to map into node size.
The best 'shipping' solution to creating a legend in a command called 'Create Legend...' found in the Style control panel pop-up menu. That exports a graphics file, but doesn't do an adequate job of it. I'm working on an app called Legend Creator, which will add annotations to the canvas for a legend. It's in development on the github/cytoscape repo.

Related

Generate schematic (geographic) diagram from graph

I would like to know how best to generate a schematic diagram, something like this, from a graph (created using the Python NetworkX library) that contains the latitude and longitude of each node (city) and the lines connecting them in the Indian railway network.
The cities (nodes) should be located reasonably close to their actual position, but not necessarily exactly. I am OK with using the plate carrée projection that simply maps lat/long onto X/Y in the diagram.
The rail lines (edges) can be straight lines or even curves if it fits better.
On the diagram should be displayed the cities (preferably as dots) along with a short (max 4 characters) label for each, the lines connecting them, and a single label for each line (the given example has quite long labels for the lines).
Preferably the amount of manual tweaking of coordinates to get things to fit should be minimised.
Using Graphviz was my first idea. But I don't know how well neato/fdp (required for fixed positioning of nodes) will perform with large numbers of nodes/edges. Also, making Graphviz display labels separately outside the nodes (rather than inline) seems to need a lot of manual positioning of each label, which would be pretty boring. Is there any better way to get this kind of layout?
Doable (https://forum.graphviz.org/t/another-stupid-graphviz-trick-geographic-graphs/256), but does not seem to use many Graphviz features. In addition to tools mentioned in the link, maybe consider pikchr (https://pikchr.org/home/doc/trunk/homepage.md)

A framework for animating a network graph algorithm in Python

I’m looking for a way to animate a network graph algorithm in Python.
What I need to do is to draw a (large) network graph and manipulate it (add/remove vertices, add/remove edges, change vertices size and/or color, change edges colors, etc.), without having to redraw the entire graph for every frame.
I found several similar questions (this one for example) but they all either regard static plotting of network graphs or are very old and the examples doesn't work.
3Blue1Brown's manim animation engine may be something to consider. It supports LaTeX-style graphics and has quite an active community.

Generating Network graph in python

I am trying to generate a network graph for 200+ nodes and 300+ edges using networkx using python from a file. I was able to generate and plot the graph using matplotlib in my Juypter Notebook, but its not looking good and nodes are so tightly packed.
Is there any other python package help to generate network graph ??.
My aim is to generate graph for whole data set so that I can find dependency between nodes.
If nodes being too close together is the issue, try using the draw_spring()function of networkx.
https://networkx.github.io/documentation/networkx-2.0/reference/generated/networkx.drawing.nx_pylab.draw_spring.html#networkx.drawing.nx_pylab.draw_spring
It simulates what would happen if each edge were a spring and the network were picked up and spun around, seperating the nodes, especially the ones which are not connected via many paths.
If this does not work initially, you can use the parameters of the function that draw_spring() wraps, the spring_layout() function. Try adjusting the k value parameter. This should allow you to manipulate the rough distance between nodes.
https://networkx.github.io/documentation/networkx-2.0/reference/generated/networkx.drawing.layout.spring_layout.html#networkx.drawing.layout.spring_layout
Alternatively, there are additional draw functions you might find more useful than draw_spring(). You can find them in the draw section here: https://networkx.github.io/documentation/networkx-2.0/reference/drawing.html
I can recommend using Netwulf. Input a networkx.Graph object to netwulf.visualize, and launch the visualization in a new browser window. The result and data can be posted back to Python.
Disclaimer: I co-author Netwulf.

How to draw a graph that can indicate the values when the mouse moves to some part of the graph in python and put it on the web page?

I'm writing a web interface for a database of genes values of some experiments with CGI in Python and I want to draw a graph for the data queried. I'm using matplotlib.pyplot, draw a graph, save it, and perform it on the web page. But usually there are many experiments queried hence there are a lot of values. Sometimes I want to know which experiment does one value belong to because it's a big value, whereas it's hard to identify because the picture is small in size. The names of the experiments are long strings so that it will mess the x axis if I put all the experiment names on the x axis.
So I wonder if there is a way to draw a graph that can interact with users, i.e. if I point my mouse to some part on the graph, there would be one small window appears and tells me the exact value and what is the experiment name here. And the most important is, I can use this function when I put the graph on the web page.
Thank you.
What you want is basically D3.js rendering of your plots. As far as I know, there are currently three great ways of achieving this, all under rapid development:
MPLD3 for creating graphs with Matplotlib and serving them as interactive web graphics (see examples in Jake's blog post).
Plotly where you can either generate the plots directly via Plotly or from Matplotlib figures (e.g. using matplotlylib) and have them served by Plotly.
Bokeh if you do not mind moving away from Matplotlib.

Directed graph in python

I am trying to depict the relationship of different data entities with my ETL (extraction transformation loading) pipeline. The final output is a large directed graph. So far I am using Python to extract data relationship. Pydot helps me generate svg file which I can open up using a browser. The graph that I generate is static.
Pydot lets me setup tooltip and allows me to link other html pages with nodes or edges. I am looking for more than that.
A small portion of the graph is shown below
I want to do several things with this graph.
Every node can have several attributes (including name). It is not possible for me to display those attributes because of paucity of space. But as users mouse over (or do other mouse based action) I would like those attributes to show up as "floating" table which user can dismiss if not interested.
Not all node attributes are integer or strings. It can be graphs as well. For example for one of the nodes I may have a bar chart showing how often this data entity is getting loaded in last 7 days. I would like that bar chart to float over as the user moves (clicks) mouse over that node. Currently I am using matplotlib to generate bar / pie charts associated (please see above) with nodes. I link those diagrams with my original directed graph using setURL in pydot. But the user experience is not great since it takes user over to a new page.
I am happy with node layout etc that I get by default from Pydot/GraphViz. I prefer not to do everything from ground up unless it is absolutely necessary.
Ability to highlight only certain part of the graph based on query in node or edge attributes
I read this forum and came across several options in response to questions similar to mine.
gephi
igraph (I played around with igraph which lets me query by vertex
or edge. I couldn't figure out how I can make my final graph
interactive based on user input e.g. floating table on mouse over of
a node etc)
Javascript libraries - sigma.js, arbor.js, d3.js nodebox
networkX
nodebox
I have Python skill but quite novice on Javascript side. I would like to know from experts what can be my best bet (from functionality and ease of use point of view). A browser based solution is preferred.
Any suggestion / help will be really appreciated.
Thanks
Abhijit
Try NetworkX. Node attributes can be anything hashable, so that addresses (at least) your first two bullets.
You will still be using matplotlib to generate the charts. I don't know of a better solution than that.

Categories

Resources