/usr/share/ampliconnoise/Scripts/Diversity.pl is in ampliconnoise 1.29-6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #!/usr/bin/perl
$line = <STDIN>;
chomp($line);
@samples = split(/,/,$line);
my @vector = ();
shift(@samples);
$nSamples = scalar(@samples);
$j = 0;
while($line = <STDIN>){
chomp($line);
my @tokens = split(/,/,$line);
shift(@tokens);
for($i = 0; $i < $nSamples; $i++){
$vector[$i][$j] = $tokens[$i];
}
$j++;
}
$nOTUs = $j;
my @total = ();
my @S = ();
my @chao = ();
my @shannon = ();
my @P = ();
for($i = 0; $i < $nSamples; $i++){
my $n1 = 0;
my $n2 = 0;
for($j = 0; $j < $nOTUs; $j++){
$total[$i]+=$vector[$i][$j];
if($vector[$i][$j] > 0){
$S[$i]++;
}
if($vector[$i][$j] == 1){
$n1++;
}
if($vector[$i][$j] == 2){
$n2++;
}
}
for($j = 0; $j < $nOTUs; $j++){
if($vector[$i][$j] > 0){
$p = $vector[$i][$j] / $total[$i];
$shannon[$i] += -$p*log($p);
}
}
$P[$i] = $shannon[$i]/log($S[$i]);
if($n1 > 0 && $n2 > 0){
$chao[$i] = $S[$i] + 0.5*(($n1*$n1)/$n2);
}
}
printf("%s,%s\n","Diversity",join(',',@samples));
printf("%s,%s\n","N",join(',',@total));
printf("%s,%s\n","S",join(',',@S));
print "Chao,";
for($i = 0; $i < $nSamples; $i++){
printf("%.2f,",$chao[$i]);
}
printf("\n");
print "Shannon,";
for($i = 0; $i < $nSamples; $i++){
printf("%.2f,",$shannon[$i]);
}
printf("\n");
print "Pielou,";
for($i = 0; $i < $nSamples; $i++){
printf("%.2f,",$P[$i]);
}
printf("\n");
|