-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabelTree_AlleleCount-new3.pl
executable file
·104 lines (80 loc) · 2.21 KB
/
labelTree_AlleleCount-new3.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl
#v3.0
# labelTree_AlleleCount.pl tree_nodeLabel Node_SNP_counts tree_AlleleCounts tree_nodeAllelecounts
# labelTree_AlleleCount.pl tree_nodeLabel Node_SNP_counts tree_AlleleCounts tree_nodeAllelecounts 1
# defaults to not number nodes (last arg 0), just show SNP counts.
no warnings 'deprecated';
use Bio::TreeIO;
my $intree=$ARGV[0];
my $countFile=$ARGV[1];
my $new_treefile=$ARGV[2];
my $new_treefile_sametips=$ARGV[3];
my $number_nodes=0;
if ($ARGV[4] > 0 ) {
$number_nodes=1;
}
my %nh=();
open IN,"$countFile";
my @lines=<IN>;
close IN;
chomp @lines;
foreach my $line (@lines) {
if ($line =~ /node\:\s(.*)\sNumberTargets\:\s(\d+)\sNumber\S+\:\s(\d+)/) {
$node=$1;
$count_alleles=$3;
$nh{$node}=$count_alleles;
}
}
#foreach my $nodeID (keys %nh) {
# print "$nodeID\n";
#}
#sleep(3);
my $treeio = new Bio::TreeIO(-file => "$intree",
-format => "newick");
my $tree = $treeio->next_tree;
@nodes=$tree->get_nodes();
#print @nodes;
foreach $node (@nodes) {
my $oldid=$node->id;
if (!defined $nh{$oldid}) {
$nh{$oldid}=0;
}
my $newid="";
if ($node->is_Leaf) {
$newid=$oldid."_".$nh{$oldid};
} elsif ( $number_nodes== 0) {
$newid=$nh{$oldid};
} else {
$newid=$oldid."_".$nh{$oldid};
}
# print "old id: $oldid\n";
# print "new id: $newid\n";
$node->id($newid);
}
my $treeio_nodes_named = new Bio::TreeIO( -file => ">$new_treefile",
-format => "newick");
$treeio_nodes_named->write_tree($tree);
$treeio = new Bio::TreeIO(-file => "$intree",
-format => "newick");
$tree = $treeio->next_tree;
@nodes2=$tree->get_nodes();
foreach $node (@nodes2) {
my $oldid=$node->id;
if (!defined $nh{$oldid}) {
$nh{$oldid}=0;
}
my $newid="";
if ($node->is_Leaf) {
$newid=$oldid;
} elsif ( $number_nodes== 0) {
$newid=$nh{$oldid};
} else {
$newid=$oldid."_".$nh{$oldid};
}
# print "old id: $oldid\n";
# print "new id: $newid\n";
$node->id($newid);
}
$treeio_nodes_named = new Bio::TreeIO( -file => ">$new_treefile_sametips",
-format => "newick");
$treeio_nodes_named->write_tree($tree);