annotate Perl/convertANI.pl @ 5:4157f435fa89 draft

Uploaded
author dereeper
date Thu, 30 May 2024 12:11:25 +0000
parents e42d30da7a74
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
1 #!/usr/bin/perl
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
2
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
3 use strict;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
4
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
5 my $file = $ARGV[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
6 my $metadata = $ARGV[1];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
7
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
8 my %strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 open(F,$metadata);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 my ($path_genome,$strain) = split(/\t/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 $strains{$path_genome} = $strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18 my %ANIs;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 my %genomes;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 my $num_line = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
21 open(F,$file);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 $num_line++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 my @infos = split(/\t/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 my $genome = $infos[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 $genome = $strains{$genome};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 $genomes{$num_line} = $genome;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 for (my $i = 1; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
32 $ANIs{$i}{$num_line} = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
33 $ANIs{$num_line}{$i} = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
34 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
35 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
36 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 print "Genomes";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 foreach my $i(sort keys(%ANIs)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 print "\t".$genomes{$i};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 print "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 foreach my $i(sort keys(%ANIs)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44 print $genomes{$i};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 foreach my $j(sort keys(%ANIs)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
46 my $ani = $ANIs{$i}{$j};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 if ($ani eq "NA"){$ani = 0;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 if (!$ani && $i == $j){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 $ani = 100;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 print "\t".$ani;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 print "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 }