diff fasta-stats.pl @ 2:cd0874854f51 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/fasta_stats/ commit adc5e3616c1849551c9a712b651b0d1c6b0e88f1"
author iuc
date Mon, 26 Apr 2021 10:01:43 +0000
parents 16f1f3e2de42
children 56022eb50bbd
line wrap: on
line diff
--- a/fasta-stats.pl	Wed Apr 21 09:10:46 2021 +0000
+++ b/fasta-stats.pl	Mon Apr 26 10:01:43 2021 +0000
@@ -47,7 +47,7 @@
 # sort length array 
 # (should use hash here for efficiency with huge no of short reads?)
 
-@len = sort { $a <=> $b } @len;
+@len = sort { $b <=> $a } @len;
 
 # compute more stats
 
@@ -62,12 +62,12 @@
   
   # calculate n50
   my $thresh = int 0.5 * $stat{'num_bp'};
-  $stat{'len_N50'} = &calc_x50(@len, $thresh);
+  ($stat{'len_N50'}, $stat{'L50'}) = &calc_x50(\@len, $thresh);
   
   #calculate NG50
   if ($calc_ng50) {
-    my $thresh = int 0.5 * $genome_size * 1000000;
-    $stat{'len_NG50'} = &calc_x50(@len, $thresh);
+    my $thresh = int 0.5 * $genome_size;
+    ($stat{'len_NG50'}, $stat{'LG50'}) = &calc_x50(\@len, $thresh);
   }
 }
 
@@ -101,15 +101,16 @@
 # N50/NG50 calculation sub
 
 sub calc_x50{
-  my @x = shift;
+  my $ref = shift;
+  my @x = @$ref;
   my $thresh = shift;
   my $cum=0;
   for my $i (0 .. $#x) {
     $cum += $x[$i];
     if ($cum >= $thresh) {
-      return $x[$i];
+      return $x[$i], $i+1;
     }
   }
-  return 0;
+  return (0,0);
 }