[BioRuby] Drawing a phylogeny ASCII tree

Pjotr Prins pjotr.public14 at thebird.nl
Fri Mar 16 13:51:53 UTC 2012


Anyone interesting in a little coding challenge? I wrote a feature
for drawing a phylogeny ASCII tree:

When you have an alignment, with a Newick tree attached, as supported
by the bio-alignment gem, I would like to get the following ASCII 
drawings:

And draw the MSA with the tree
  """
  +--9.69----------------------------------------- seq7  ----------PTIIFSGCSKACSGK-----VCGIFHAVRSFM
  |                                   ,--1.19----- seq1  ----SNSFSRPTIIFSGCSTACSGK--SELVCGFRSFMLSDV
  |                          ,--1.79--|        ,-- seq2  SSIISNSFSRPTIIFSGCSTACSGK--SEQVCGFR---LSDV
  |                 ,--1.07--+        `--1.19--+-- seq3  SSIISNSFSRPTIIFSGCSTACSGKLTSEQVCGFR---LSDV
  |                 |        |--1.79--+--1.19----- seq5  ----------PTIIFSGCSKACSGKGLSELVCGFRSFMLSDV
  |        ,--1.31--|                 `--1.19----- seq8  --------PTIIFSGCSKACSGK--SELVCGFRSFMLSAV
  |--4.34--|        `--4.05----------------------- seq4  ----PKLFSRPTIIFSGCSTACSGK--SEPVCGFRSFMLSDV
           `--5.36-------------------------------- seq6  ----------PTIIFSGCSKACSGK-----FRSFRSFMLSAV
  """
Then draw MSA with the short tree
  """
  +----------------- seq7  ----------PTIIFSGCSKACSGK-----VCGIFHAVRSFM
  |           ,----- seq1  ----SNSFSRPTIIFSGCSTACSGK--SELVCGFRSFMLSDV
  |        ,--|  ,-- seq2  SSIISNSFSRPTIIFSGCSTACSGK--SEQVCGFR---LSDV
  |     ,--+  `--+-- seq3  SSIISNSFSRPTIIFSGCSTACSGKLTSEQVCGFR---LSDV
  |     |  |--+----- seq5  ----------PTIIFSGCSKACSGKGLSELVCGFRSFMLSDV
  |  ,--|     `----- seq8  --------PTIIFSGCSKACSGK--SELVCGFRSFMLSAV
  |--|  `----------- seq4  ----PKLFSRPTIIFSGCSTACSGK--SEPVCGFRSFMLSDV
     `-------------- seq6  ----------PTIIFSGCSKACSGK-----FRSFRSFMLSAV
  """

BioPerl has someting similar here, but less useful:

  http://doc.bioperl.org/releases/bioperl-1.4/Bio/TreeIO/tabtree.html

And there are some good Ruby examples trees at

  http://www.rubyquiz.com/quiz40.html

The full feature description is here, and the bio-alignment module
allows for loading and traversing trees. It is only a matter of
getting the algorithm right :) See

  https://github.com/pjotrp/bioruby-alignment/blob/master/features/tree.feature

and 

  https://github.com/pjotrp/bioruby-alignment/blob/master/features/tree-feature.rb

The same algorithm will be used for a HTML drawing.

Pj.

On Tue, Mar 13, 2012 at 11:23:26PM +0900, Naohisa GOTO wrote:
> Hi Pjotr,
> 
> The design of Bio::Tree that a nod has no tree information and
> only tree object have node information was what I intended.
> This makes easy to split a tree into subtrees, to build a tree
> from scratch, to concatenate trees, to replace nodes and edges, etc.
> However, as you described, for traversing a static tree,
> indirect operations are needed which are sometimes annoying.
> 
> Naohisa Goto
> ngoto at gen-info.osaka-u.ac.jp / ng at bioruby.org
> 
> 
> On Mon, 12 Mar 2012 17:24:38 +0100
> Pjotr Prins <pjotr.public14 at thebird.nl> wrote:
> 
> > On Mon, Mar 12, 2012 at 03:18:48PM +0900, Naohisa GOTO wrote:
> > > When writing HOWTO based on BioPerl HOWTO:Trees,
> > > (http://bioruby.open-bio.org/wiki/HOWTO:Trees but still incomplete)
> > > I'm thinking to add/modify some API about speficying nodes/edges.
> > 
> > After some trying I agree. The Bio::Tree::Node object should know
> > 'more' about its state. I would like to do something like:
> > 
> >   root.leaf?.should == false
> >   node = root.childeren.first
> >   node.leaf?.should == false
> >   node2 == node.childeren.first
> >   node.leaf?.should == true
> >   node2.edge(node).distance.should == 1.34
> > 
> > now I need to do something like 
> > 
> >   tree = @tree
> >   node = tree.get_node_by_name('node')
> >   tree.get_edge(node, tree.parent(node)).distance.should == 1.34
> > 
> > which uses the tree state to get a node edge, and does not feel that
> > intuitive.
> > 
> > I'll try to extend Bio::Tree for bio-alignment, see what works.
> > 
> > Pj.
> 



More information about the BioRuby mailing list