[Bioperl-l] Draw phylogenetic trees with bar chart
Florent Angly
florent.angly at gmail.com
Wed Nov 12 18:56:38 UTC 2008
Thank you all for your replies, they are very useful!
Since I am looking more for some non-interactive code that integrates
well in my existing Perl program, I will look at Chris' method that
involves modifying the SVG tree.
Cheers,
Florent
Malay wrote:
> Chris Bailey wrote:
>> 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.
>>
>
> FYI a very standard way to generate images like these is to use R's
> "ape" package.
>
> -Malay
>
More information about the Bioperl-l
mailing list