[Bioperl-l] module Bio::TreeIO

Jason Stajich jason at bioperl.org
Thu Jan 8 17:58:16 UTC 2009


Hi Valerie -

Please ask this on the mailing list it is better for everyone to hear  
and help with questions.

You want to do this:
my $treeout = Bio::TreeIO->new(-format => 'newick', -file =>  
">MYFILENAME.tre");


I guess we need to more clearly explain that the IO system in BioPerl  
for new people but it is the same idea for SeqIO, TreeIO, etc you  
specify a filename to write to just like you would when opening a  
filehandle in perl open($fh, ">OUTPUTNAME") or o::TreeIO->new(-format  
=> 'newick', -file => ">MYFILENAME.nh");
   Filenames and extensions are whatever you want them to be, no  
guessing of formats based on filename extensions.

Presumably you have seen the HOWTO as well
http://bioperl.org/wiki/HOWTO:Trees

If there are things that are unclear we'd appreciate you make that  
know by commenting on the Discussion page that is linked to it (tabs  
at the top of the page).

-jason
On Jan 8, 2009, at 9:30 AM, valerie storms wrote:

> Dear Jason,
>
> I would like to use the BioPerl modules to (1) construct a  
> phylogenetic tree from a distance matrix, (2) put this tree is the  
> Newick format
> and (3) save this tree in an output file.
> The first two steps (1,2) are fine by using  
> Bio::Tree::DistanceFactory and Bio::TreeIO!
> But I have no idea how I can get my tree saved in an output file  
> instaed of printed to the mean stream??
>
> Can you help me with this?
> Many Thanks in advance!
>
> Best regards,
>
> Storms Valerie
> Phd student
> KULeuven Belgium
>
>
> p.s. The code I use
>
>
> #!/usr/bin/perl -w
>
> my $myDEBUG = 1;
> use lib '/users/sista/vstorms/local/lib/perl5/';
> use Bio::Perl;
> use Bio::Tree::DistanceFactory;
> use Bio::TreeIO;
> use Bio::Tools::Phylo::Phylip::ProtDist;
>
> my $outfile_protdist = '/users/sista/vstorms/LEGENDO/motif_detection/ 
> inputfiles/selection2/distance_matrix.txt';
> my $tree_file = '/users/sista/vstorms/LEGENDO/motif_detection/ 
> inputfiles/selection2/Tree.txt';
> if (-e $tree_file){
>   my $rm = 'rm -f '.$tree_file;
>   system $rm;
> }   my $dist = Bio::Tools::Phylo::Phylip::ProtDist->new(
>                           -file=>"$outfile_protdist",
>                           -program=>"ProtDist");
> my $matrix = $dist->next_matrix;
> my $dfactory = Bio::Tree::DistanceFactory->new(-method => 'NJ');
> my $treein = Bio::TreeIO->new(-format => 'newick');
> my $treeout = Bio::TreeIO->new( -format => 'newick', -file =>  
> $tree_file);
> my $tree = $dfactory->make_tree($matrix);
> $treein->write_tree($tree);
> $treeout->write_tree($tree);
>
>
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
>

Jason Stajich
jason at bioperl.org






More information about the Bioperl-l mailing list