comparison Perl/convertANI.pl @ 14:5a5c9a6b047b draft

Uploaded
author dereeper
date Tue, 10 Dec 2024 16:20:53 +0000
parents e42d30da7a74
children
comparison
equal deleted inserted replaced
13:152d7c43478b 14:5a5c9a6b047b
2 2
3 use strict; 3 use strict;
4 4
5 my $file = $ARGV[0]; 5 my $file = $ARGV[0];
6 my $metadata = $ARGV[1]; 6 my $metadata = $ARGV[1];
7
7 8
8 my %strains; 9 my %strains;
9 open(F,$metadata); 10 open(F,$metadata);
10 while(<F>){ 11 while(<F>){
11 my $line = $_; 12 my $line = $_;
15 } 16 }
16 close(F); 17 close(F);
17 18
18 my %ANIs; 19 my %ANIs;
19 my %genomes; 20 my %genomes;
21 my %genome_names;
20 my $num_line = 0; 22 my $num_line = 0;
21 open(F,$file); 23 open(F,$file);
22 <F>; 24 <F>;
23 while(<F>){ 25 while(<F>){
24 $num_line++; 26 $num_line++;
25 my $line = $_; 27 my $line = $_;
26 $line =~s/\n//g;$line =~s/\r//g; 28 $line =~s/\n//g;$line =~s/\r//g;
27 my @infos = split(/\t/,$line); 29 my @infos = split(/\t/,$line);
28 my $genome = $infos[0]; 30 my $genome = $infos[0];
29 $genome = $strains{$genome}; 31 $genome = $strains{$genome};
32 $genome_names{$genome}++;
33 if ($genome_names{$genome} > 1){
34 $genome = $genome . ".". $genome_names{$genome};
35 }
36
30 $genomes{$num_line} = $genome; 37 $genomes{$num_line} = $genome;
31 for (my $i = 1; $i <= $#infos; $i++){ 38 for (my $i = 1; $i <= $#infos; $i++){
32 $ANIs{$i}{$num_line} = $infos[$i]; 39 $ANIs{$i}{$num_line} = $infos[$i];
33 $ANIs{$num_line}{$i} = $infos[$i]; 40 $ANIs{$num_line}{$i} = $infos[$i];
34 } 41 }
35 } 42 }
36 close(F); 43 close(F);
37 44
38 print "Genomes"; 45 print "Genomes";
46
39 foreach my $i(sort keys(%ANIs)){ 47 foreach my $i(sort keys(%ANIs)){
40 print "\t".$genomes{$i}; 48 print "\t".$genomes{$i};
41 } 49 }
42 print "\n"; 50 print "\n";
43 foreach my $i(sort keys(%ANIs)){ 51 foreach my $i(sort keys(%ANIs)){