annotate Perl/convertANI.pl @ 15:dbde253606c5 draft

Uploaded
author dereeper
date Wed, 11 Dec 2024 08:25:06 +0000
parents 5a5c9a6b047b
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
14
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
8
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
9 my %strains;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
10 open(F,$metadata);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
11 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
12 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
13 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
14 my ($path_genome,$strain) = split(/\t/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
15 $strains{$path_genome} = $strain;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
16 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
17 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
18
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
19 my %ANIs;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
20 my %genomes;
14
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
21 my %genome_names;
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
22 my $num_line = 0;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
23 open(F,$file);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
24 <F>;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
25 while(<F>){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
26 $num_line++;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
27 my $line = $_;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
28 $line =~s/\n//g;$line =~s/\r//g;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
29 my @infos = split(/\t/,$line);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
30 my $genome = $infos[0];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
31 $genome = $strains{$genome};
14
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
32 $genome_names{$genome}++;
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
33 if ($genome_names{$genome} > 1){
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
34 $genome = $genome . ".". $genome_names{$genome};
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
35 }
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
36
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
37 $genomes{$num_line} = $genome;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
38 for (my $i = 1; $i <= $#infos; $i++){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
39 $ANIs{$i}{$num_line} = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
40 $ANIs{$num_line}{$i} = $infos[$i];
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
41 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
42 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
43 close(F);
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
44
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
45 print "Genomes";
14
5a5c9a6b047b Uploaded
dereeper
parents: 3
diff changeset
46
3
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
47 foreach my $i(sort keys(%ANIs)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
48 print "\t".$genomes{$i};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
49 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
50 print "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
51 foreach my $i(sort keys(%ANIs)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
52 print $genomes{$i};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
53 foreach my $j(sort keys(%ANIs)){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
54 my $ani = $ANIs{$i}{$j};
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
55 if ($ani eq "NA"){$ani = 0;}
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
56 if (!$ani && $i == $j){
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
57 $ani = 100;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
58 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
59 print "\t".$ani;
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
60 }
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
61 print "\n";
e42d30da7a74 Uploaded
dereeper
parents:
diff changeset
62 }