-
Notifications
You must be signed in to change notification settings - Fork 0
/
label_tree_nodes3.pl
executable file
·43 lines (31 loc) · 1.03 KB
/
label_tree_nodes3.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
#!/usr/bin/perl
#v3.1
# This inputs a "tree", parses it with library, prints all of the node IDs,
# and then changes the non-leaf nodes to be identified by a number indicating
# the sequential order they were parsed into, then displays / outputs the
# complete tree (after the lists of the IDs?) to stdout. - JN
# ~/script/label_tree_nodes.pl outtree > outtree_nodes_labeled
no warnings 'deprecated';
use Bio::TreeIO;
use Bio::TreeIO::newick;
my $intree=$ARGV[0];
my $treeio = new Bio::TreeIO(-file => "$intree",
-format => "newick");
my $tree = $treeio->next_tree;
@nodes=$tree->get_nodes();
my $count_nodes=0;
#print @nodes;
foreach $node (@nodes) {
my $id=$node->id;
#print "$id\n";
if ($node->is_Leaf) {
#Don't change the name
} else {
#if (!defined $id) {
# Relabel with numbers. Delete any previous label.
$count_nodes++;
$node->id($count_nodes);
}
}
my $treeio_nodes_named = new Bio::TreeIO( -format => "newick");
print $treeio_nodes_named->write_tree($tree),"\n";