Created
September 18, 2013 20:18
-
-
Save carlosp420/6615023 to your computer and use it in GitHub Desktop.
convert a TNT treefile to NEXUS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
#this script converts a tree ouput from TNT to NEXUS (1 tree per file) | |
# Carlos Peña 2011-03-16 | |
use strict; | |
use Bio::TreeIO; | |
my $usage = "script.pl INFILE OUTFILE\n"; | |
my $infile = shift or die $usage; | |
my $outfile = shift or die $usage; | |
# convert manually to newick format | |
open ( my $file, "<", $infile) or die $!; | |
my @data = <$file>; | |
my $tree = $data[1]; | |
$tree =~ s/\s{1}\)/\)/g; | |
$tree =~ s/\s{1}/,/g; | |
$tree =~ s/\)\(/\),\(/g; | |
$tree =~ s/;//g; | |
$tree =~ s/,$//g; | |
close($file); | |
open ( $file, ">", $infile) or die $!; | |
print $file $tree; | |
close($file); | |
my ($filein,$fileout) = @ARGV; | |
my ($format,$oformat) = qw(newick nexus); | |
my $in = Bio::TreeIO->new(-file => $infile, -format => $format); | |
my $out= Bio::TreeIO->new(-format => $oformat, -file => ">$outfile"); | |
while( my $t = $in->next_tree ) { | |
$out->write_tree($t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment