Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Displaying Undirected Graph

by jpearl (Scribe)
on Mar 12, 2009 at 19:07 UTC ( [id://750235]=perlquestion: print w/replies, xml ) Need Help??

jpearl has asked for the wisdom of the Perl Monks concerning the following question:

I have an interesting problem. I have a set of related bacteria (the vertices) that are all related to each other by a distance scoring algorithm (weighted edges), so for example if there are two strains, strain1 has an edge to strain2 and strain3 (with edge weights of say .15 and .12 respectively); strain2 has edges to strain1 and strain3 (with edge weights of .15 and .13) etc.

So my problem is I'd like to display an image of what this graph might look like. My idea is of course to use Graph::Undirected to build the graph, but I was wondering if there was a good perl module that would make it simple to either create an image file of the graph, or display it via a gui. (either one is fine) Any ideas?
Update:
My solution to this problem was to build an mst using Graph, and then build a GraphViz object as per blockhead's suggestion. The next problem I ran into was scaling the output image so that it was legible. From ikegami's suggestion I scaled it logarithmically which basically solved my last major hurdle. Thanks all!

Replies are listed 'Best First'.
Re: Displaying Undirected Graph
by blokhead (Monsignor) on Mar 12, 2009 at 19:58 UTC
    You can use GraphViz, which is a layout engine for displaying graphs. When specifying an edge, you can give a len attribute to specify a preferred length. It will try to find a layout that is close possible to your suggestions. There are other GraphViz options like model that might be relevant as well.

    However, you should have low expectations that your arbitrary metric can be embedded into low-dimensional Euclidean space in a way that (approximately) preserves distances. Your data might be unavoidably high-dimensional, and so you simply may not be able to get good results with this approach.

    blokhead

      Thanks, I think you're right as well. There really is just no good way to view this data in 2d space. The person requesting this is probably not going to be happy :-P
Re: Displaying Undirected Graph
by Anonymous Monk on Mar 12, 2009 at 19:10 UTC
Re: Displaying Undirected Graph
by jethro (Monsignor) on Mar 12, 2009 at 19:37 UTC

    There is a book by O'Reilly "Perl Graphics Programming", if you want something to read. Perl has modules that interface to GD, to Image::Magick and even gimp and opengl. There are SVG or Flash/SWF, both might have some advantages if you want to look at it in a browser. And there is the all-in-one package of GraphViz, also usable through a perl module. I used GraphViz for a project and it was nice, but you don't have much input about the placement of the nodes

Re: Displaying Undirected Graph
by jpearl (Scribe) on Mar 12, 2009 at 19:42 UTC
    Ah, thanks guys. Yeah I'd definitely like to avoid having to actually figure out what x,y coordinates the undirected graph nodes would be. Hopefully one of the previously mentioned programs can figure that out for me ;-) Thanks for the tips!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://750235]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-19 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found