-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdephylip_tree.pl
executable file
·71 lines (63 loc) · 1.74 KB
/
dephylip_tree.pl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
# Script: dephylip_tree.pl
# Description: Dephylips Newick tree files
# Author: Steven Ahrendt
# email: [email protected]
# Date: 11.15.13
######################################
# Usage: dephylip_tree.pl -i treefile -c codefile
######################################
use warnings;
use strict;
use Bio::TreeIO;
use Getopt::Long;
#####-----Global variables-----#####
my $treefile;
my $code_filename;
my %hash;
my ($help,$verb);
my $encode;
GetOptions ("i|input=s" => \$treefile,
"c|code=s" => \$code_filename,
"h|help" => \$help,
"v|verbose" => \$verb,
"e|encode" => \$encode);
my $usage = "Usage: dephylip_tree.pl -i treefile -c codefile [-e]\n Use -e to encode\n Output to files\n";
die $usage if ($help);
die $usage if (!$treefile or !$code_filename);
my $treeIn = Bio::TreeIO->new(-file => $treefile,
-format => 'newick');
my $treeOutNwk = Bio::TreeIO->new(-file => ">$treefile\.newick",
-format => 'newick');
my $treeOutNex = Bio::TreeIO->new(-file => ">$treefile\.nex",
-format => 'nexus');
## Code files is in format: Name\s+Code
open(IN,"<$code_filename") || die "Can't open \"$code_filename\".\n";
foreach my $line (<IN>)
{
chomp $line;
my ($val,$key) = split(/\t/,$line);
if($encode)
{
my $tmp = $key;
$key = $val;
$val = $tmp;
}
$hash{$key} = $val;
}
close(IN);
my $tree_obj = $treeIn->next_tree;
my $n = 0;
for my $node ($tree_obj->get_leaf_nodes)
{
my $ID = $node->id;
my $newID = $hash{$ID};
print $node->id;
print " => ";
$node->id($newID);
print $node->id;
print "\n";
$n++;
}
$treeOutNwk->write_tree($tree_obj);
$treeOutNex->write_tree($tree_obj);