File: bp_nexus2nh

package info (click to toggle)
bioperl 1.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 35,788 kB
  • sloc: perl: 94,019; xml: 14,811; makefile: 20
file content (47 lines) | stat: -rw-r--r-- 830 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl

=head1 NAME

bp_nexus2nh - convert nexus format trees (from PAUP* and MrBayes) to new hampshire

=head1 SYNOPSIS

 bp_nexus2nh file.nexus > file.nh

 # OR pipe in through STDIN

 cat file.nexus | bp_nexus2nh > file.nh

 # OR specify an output

 bp_nexus2nh -o file.nh file.nexus

=head1 DESCRIPTION

Convert Nexus Tree files into Newick/New Hampshire format tree files.


=cut

use strict;
use warnings;
use Bio::TreeIO;
use Getopt::Long;

my $outfile;

GetOptions('o|out|outfile:s' => \$outfile);

my $in = Bio::TreeIO->new(-format => 'nexus', -fh => \*ARGV);
my $out;
if( $outfile ) { 
    $out= Bio::TreeIO->new(-format => 'newick',
			   -file   => ">$outfile");
} else { 
    # write to STDOUT
    $out= Bio::TreeIO->new(-format => 'newick');
}

while( my $t = $in->next_tree ) {
    $out->write_tree($t);
}