annotate PanExplorer_workflow/Perl/convertANI.pl @ 2:97e4e3e818b6 draft

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