-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.pl
More file actions
46 lines (40 loc) · 976 Bytes
/
tree.pl
File metadata and controls
46 lines (40 loc) · 976 Bytes
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
#! perl -w
use strict;
use Bio::TreeIO;
my $infile=shift;
my $input=new Bio::TreeIO(-file=>$infile,
-format=>"newick",
-internal_node_id=>"bootstrap");
while(my $tree=$input->next_tree){
$tree->move_id_to_bootstrap;
my %dis;
my $max=0;
my $refseq=$tree->find_node(-id=>"GU131785");
for my $taxa($tree->get_leaf_nodes){
my $d=$tree->distance(-nodes=>[$refseq,$taxa]);
$dis{$taxa->id}=$d;
if($max<$d){
$max=$d;
}
}
#foreach my $key(sort {$dis{$b}<=>$dis{$a}} keys %dis){
# print $key.":".$dis{$key}."\n";
#}
my $interval=$max/100;
my @group;
for(my $i=0;$i<=$max-$interval;$i+=$interval){
my %t;
foreach my $key(sort {$dis{$b}<=>$dis{$a}} keys %dis){
if($i<$dis{$key} && $dis{$key}<=$i+$interval){
$t{$key}=$dis{$key};
}
}
push @group,\%t;
}
foreach my $item(@group){
next unless %$item;
my $key=shift @{[sort {$dis{$b}<=>$dis{$a}} keys %$item]};
print $key."\t".$item->{$key}."\n";
#print $key."\n";
}
}