[Bioperl-l] BioPerl and NHX tree

Aaron Mackey amackey at pcbi.upenn.edu
Thu Dec 20 15:32:19 UTC 2007


The NHX writer will only add the [&&NHX] block when there are tags to
be written.  Your code reads in a Newick tree without tags, and then
writes it back out without adding any new tags.  So yes, you need to
1) read the Newick tree, 2) traverse the tree, calling
$node->nhx_tag({T => $taxon_id}) for each node with each corresponding
$taxon_id, and then 3) write out the NHX tree.

-Aaron

On Dec 20, 2007 9:07 AM, Laurence Amilhat
<Laurence.Amilhat at toulouse.inra.fr> wrote:
> Dear Mr MacKey,
>
>
> I am pretty new in Tree parsing and writing with BioPerl.
> I am trying to convert a Newick tree file to a NHX tree file with adding
> the Taxid for the node in the NHX tree file.
>
> I saw the module Bio::Tree::NodeNHX, but very few examples...
>
> I don't know where do i need to start, I tried the easy way with
> Bio::TreeIO,
> but the resulting tree doesn't have the [&&NHX] in the internal node,
> and I don't know how to add the tag [&&NHX:T=xxxx] on the node,
> Do I need to use the nhx_tag method to do this?
>
> Maybe you have an example that use NHX tag in tree node, that might be
> very helpfull for me to get to understand how it works...
>
>
> Have a nice holidays,
>
>
> Best regards,
>
>
> Laurence Amilhat.
>
>
>
>
> This is the simple code that I use to convert a tree from  newick to nhx:
>
> use Bio::TreeIO;
> use Getopt::Long;
> my $tree_file;
> my $outfile;
>
> GetOptions('f|file:s' =>\$tree_file, 'o|out:s' =>\$outfile);
>
> my $treeio = new Bio::TreeIO (-format => 'newick', -file => "$tree_file");
> my $treeout= new Bio::TreeIO (-format => 'nhx', -file =>">$outfile");
>
> while (my $tree= $treeio->next_tree)
> {
>    $treeout->write_tree($tree);
> }
>
> --
> ====================================================================
> = Laurence Amilhat    INRA Toulouse 31326 Castanet-Tolosan         =
> = Tel: 33 5 61 28 53 34   Email: laurence.amilhat at toulouse.inra.fr =
> ====================================================================
>
>
>
>



More information about the Bioperl-l mailing list