[Bioperl-l] Draw phylogenetic trees with bar chart
Chris Bailey
c.bailey at bham.ac.uk
Wed Nov 12 09:15:36 UTC 2008
Florent Angly wrote:
> Dear Bioperl users,
>
> I need to represent graphically phylogenetic trees as cladograms or
> phylograms using Perl. An additional requirement is that I would like
> to add graph data as bar chart on top of it as in this example:
> http://scums.sdsu.edu/Mapper/images/b.gif
>
> Now, I have read the BioPerl howto and know about the
> Bio::TreeIO::svggraph and Bio::Tree::Draw::Cladogram modules. The
> first one uses the SVG Perl module whereas the other one uses the
> PostScript module to create EPS images. I do not know why there are 2
> very similar modules to draw trees (in different locations), but none
> of them seem to able to plot additional information on the tree.
I'm not aware of any inbuilt code in any of these modules to do what
you're asking. In the past, the way I've added extra information into
trees is as follows:
1) Embed the data you want to graph into the alignment/tree file, such
that when the tree is drawn, for example, the length of the bar you want
drawn is part of the text on the tree node in question
2) Draw the tree as an SVG image using Bio::TreeIO.
3) Parse the SVG document using your XML parser of choice (I've used
XML::Simple for this in the past)
4) extract all the <text> elements and their CDATA.
5) the text element will contain an x and y co-ordinate and the CDATA
will contain the text string itself
6) pull out the data you need to draw the graph (the information you
added in 1) using regexps etc.
7) add an element to the SVG document (e.g. <rect x="80" y="500"
height="10" width="125" style="fill:blue" />) simply change the x and y
to match the coordinates of the text element (+ an offset to get
everything looking right), and change width to the value you extracted
in (6)
8) repeat steps 5 to 7 for all the text elements in your SVG document
9) output new SVG document to a file
10) ????
11) Profit
This pattern will also work for more complex data, since you can always
add more data to each text node, and it's more than possible to generate
any type of chart data you like with the right combination of shape
primitives.
Cheers,
Chris
>
> Is there any other Perl code that you know of that would facilitate
> doing what I want to do? If not, how should I modify one of the 2
> mentioned BioPerl modules to plot bar charts, and which one??
>
> Thanks,
>
> Florent
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
--
-----------------------
Chris Bailey
Centre for Systems Biology
School of Biosciences
University of Birmingham
Edgbaston, Birmingham, B15 2TT
United Kingdom
T: +44(0)121 414 8849
E: c.bailey at bham.ac.uk
More information about the Bioperl-l
mailing list