[BioPython] Cladograms

Renato Alves rjalves at igc.gulbenkian.pt
Fri Nov 28 12:03:48 EST 2008


Quoting Peter Cock on 11/28/2008 11:29 AM:
> Hi Renato,
>   
Hi Peter,
>> My goal is something that resembles a heatmap[1] but where the trees will be
>> cladograms[2] instead of the result of clustering steps.
>>     
> In my heatmap example you cited (using R), you can in principle supply
> the tree to be used (instead of it defaulting to doing a hierarchical
> clustering).  If you like the images from the R heatmap function, I
> would suggest you look at loading phylogenetic trees into R and
> passing them to the heatmap function.  I have not tried this myself.
>   
R's heatmap.2 is giving me what I need so far, it even reorders the 
columns/rows according to a pre-calculated dendrogram.
The only thing that I don't like that much is how the dendrograms are 
plotted when multiple branches are at the same levels, but I can live 
with it :)
>> I know that probably I won't find modules doing exactly what I want, which
>> is why I'm searching for tools to do each step separately and try to glue
>> them somehow.
>>     
> I can understand the idea here, but in practice the "glueing" the
> images together may not be trivial.  You'll have to make sure that
> they are drawn using vector image formats (allowing you to scale the
> images to match), or if using bitmaps you'll need to be able to
> specify things pixel perfect.   You will also need to hope that the
> tree is drawn with equal vertical spacing between leaves, otherwise it
> won't match the grid of the heatmap.  That said, there a lot of tree
> drawing packages out there, and this could work.
>   
Well I was thinking of a naive approach such as "glue by hand" (shame on 
me). But for a real thing I would probably use matplotlib. Although 
given my current knowledge on the library it would take a while...
>> For the heatmap I have something already that will probably do
>> the job, but for the cladograms I couldn't find any decent module.
>> Do you happen to know any dark alley in BioPython or any other external
>> module that would allow me to do the cladogram?
>>     
> You could in principle use python and a package like reportlab to draw
> both the tree and the heatmap - but you'd end up writing a lot of your
> own code.  For example, I have used python and reportlab to draw
> colourful PDF trees with aligned columns of data, e.g. Supplementary
> figures 1 and 2 from: http://dx.doi.org/10.1099/mic.0.2007/013672-0
>   
Never used reportlab directly, only via other tools that did all the 
job. But it's good to know it does a good job at what it does.
The only time I messed with PDF libraries using python I ended up with 
pyPdf - http://pybrary.net/pyPdf/ - It was the only library that had the 
"limited" edit capabilities I needed.
> The script that drew these trees is actually rather complicated
> (partly due to showing two sets of bootstrap values).  If I recall
> correctly, it also used Thomas Mailund's Newick Tree module to parse
> the tree files, and not Biopython.  See
> http://www.daimi.au.dk/~mailund/newick.html
>   
That's also my problem when writing R code using rpy. Not very pythonic 
(mine at least), hard to read and reuse. Sometimes I end up writing code 
in the original language, dumping data to files and launching it with 
os.system/subprocess.call than using rpy. I hope this changes a bit with 
rpy2...
> Next time I need to draw a customised tree, I'll try to look at
> writing something more general purpose to go in Biopython under
> Bio.Graphics (using Bio.Nexus to load tree files).
>
> For now, I would suggest you explore the R heatmap function and its
> arguments (and perhaps call this via python if you need to - it would
> be simpler just to use R directly).
>   
I'm going straight to R for now. But I think this one should be simple 
and elegant to do in rpy.
> Peter
>   
Thanks a bunch for the nice tips and feedback.

Renato


More information about the BioPython mailing list