Add tests for memory leaks and weaken for Issue #81
[bioperl-live.git] / scripts / tree / bp_tree2pag.pl
blobcfde7e90bc813097883fa91d62fa26b225e7a622
1 #!perl
3 =head1 NAME
5 bp_tree2pag - convert Bio::TreeIO parseable format trees to pagel format
7 =head1 SYNOPSIS
9 bp_tree2pag -if nexus -i file.nexus > file.pag
11 # OR pipe in through STDIN, and use newick format instead
13 cat file.newick | bp_tree2pag -if newick > file.nh
15 # OR specify an output and input
17 bp_tree2pag -o file.pag -i file.newick
19 =head1 DESCRIPTION
21 Convert TreeIO parseable files into Pagel format tree files. Be
22 warned that pagel format only really supports a single tree per file
23 so. Also Pagel parsing is not yet available in bioperl.
25 =cut
27 use strict;
28 use warnings;
29 use Bio::TreeIO;
30 use Getopt::Long;
31 my ($iformat,$oformat) = ('newick', 'pag');
32 my ($outfile,$infile);
33 GetOptions(
34 'if|informat:s' => \$iformat,
35 'of|outformat:s' => \$oformat,
36 'i|in:s' => \$infile,
37 'o|out:s' => \$outfile,
38 'h|help' => sub { exec('perldoc', $0);
39 exit(0); },
41 my $in;
42 if( ! $infile ) {
43 $in = Bio::TreeIO->new(-format => $iformat,
44 -fh => \*ARGV);
45 } else {
46 $in = Bio::TreeIO->new(-format => $iformat,
47 -file => $infile);
50 my $out;
51 if( $outfile) {
52 $out = Bio::TreeIO->new(-format => $oformat,
53 -file => ">$outfile");
54 } else {
55 $out = Bio::TreeIO->new(-format => $oformat); #print to STDOUT instead
58 while( my $t = $in->next_tree ) {
59 $out->write_tree($t);