-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdis_matr_ge.pl
55 lines (48 loc) · 1.19 KB
/
dis_matr_ge.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
use warnings;
use diagnostics;
die"*.pl <pair_distance.list> <sepcies number>" if @ARGV!=2;
open(IN,$ARGV[0])||die "can't open $ARGV[0]:$!";
#print "enter number of sp \n";
$spn=$ARGV[1];
%hash=();
%namecode=();
$ncode=0;
while($line=<IN>){
chomp $line;
($a,$b,$c)=(split "\t" ,$line)[0,1,2] ;
for $na($a,$b){
if (! exists $namecode{$na}) {
$name=sprintf "%03s", ++$ncode ;
$namecode='Species'.$name;
$namecode{$na}=$namecode;
};
}
$hash{$a}->{$b}=$c ;
$hash{$b}->{$a}=$c ;
#print $a,"\t",$b,"\t",$hash{$a}->{$b},"\n";
};
print $spn;
#print "===",$hash{'E_coli_UTI89'}->{'E_fer_ATCC_35469'},"===" ;
@ar=(keys %hash);
#print scalar @ar,"\n";
foreach $ele (@ar){
print "\n";
#printf "%-10s", substr($ele,-10,10); #phlip only accept sample name 9 or 10 in length !
print $namecode{$ele};
foreach $ele2(@ar){
# print $ele2 ;
print " ";
# print "***",$hash{$ele}->{$ele2},"^^^^" ;
if ($ele eq $ele2){
printf "%.10f" , 0 ;
}
else{
printf "%.10f" , exists $hash{$ele}->{$ele2}? $hash{$ele}->{$ele2} : $hash{$ele2}->{$ele} ;
;};
};
};
print "\n";
open(OUT, ">./namecode")||die"can't open: $!";
for (keys %namecode){
print OUT $_ ,"\t", $namecode{$_} ,"\n";
}