[Bioperl-l] Getting started with Bio::TreeIO
Howard Ross
h.ross@auckland.ac.nz
Mon, 17 Jun 2002 09:45:18 +1200
Dear folks,
I would like to be able to read in a phylogenetic tree, manipulate its
branching structure by repositioning clades, and then write it to file.
The Bio::Tree modules seem the obvious tool. I'm have trouble getting
started and would appreciate a bit of help.
In working with the Bio::Tree modules recently, I have deduced:
- they do not support Newick trees WITHOUT branch lengths,
although this is a legitimate format, and
- ancestor is defined only for rooted trees (this makes sense)
Can I suggest that these get put into the POD sections, to save the
next person's time.
I have successfully read in a tree, and then written it out to file.
But, I have been totally unsuccessful at making any changes to the
tree and then saving it to file.
The following piece of code should swap nodes C and G in the tree
(shown below) but it only recreates the input tree.
#===============================================================
#!/usr/bin/perl
use Bio::TreeIO;
my $treeio = new Bio::TreeIO(-format => 'newick', -file =>
'rooted8tree.tre');
my $treeout = new Bio::TreeIO(-format => 'newick', -file => ">saveme.txt" );
my $tree = $treeio->next_tree;
my @nodes = $tree->get_nodes;
my $i, $c, $g;
for ($i = 0; $i <= $#nodes; $i++) {
if ($nodes[$i]->id eq 'C') {
$c = $i;
}
if ($nodes[$i]->id eq 'G') {
$g = $i;
}
}
my $cancestor = $nodes[$c]->ancestor;
my $gancestor = $nodes[$g]->ancestor;
$nodes[$c]->ancestor($gancestor);
$nodes[$g]->ancestor($cancestor);
$treeout->write_tree($tree);
#==============================================================
-rooted8tree.tre-
(((A:1,B:1):1,(C:1,D:1):1):1,((E:1,F:1):1,(G:1,H:1):1):1);
I have also tried to rearrange the tree by adding nodes and defining
the descendents, again without success.
So, the big question is how do you rearrange nodes in these trees:
- To specify a node-node relationship, do you need to specify both the
ancestor and the descendent fields of the respective nodes?
- Can (should) you have more than one tree in memory?
- How do you specify which tree a particular node belongs to?
- Do all nodes in a particular tree have to be defined in the same array?
- Given the situation with ancestor and unrooted trees, how do you
(re)define node-node relationships for this type of tree?
Your help would be much appreciated.
Howard
--
==========================================================
Dr. Howard Ross, Research Fellow,
School of Biological Sciences, The University of Auckland,
Private Bag 92019, Auckland, New Zealand
email: h.ross@auckland.ac.nz phone: 64-9-373-7599 ext 6160
==========================================================