[Bioperl-guts-l] [16751] bioperl-live/trunk/Bio/Align/DNAStatistics.pm: [bug 2901] Deal with div by zero in cases where gaps exist (per Janet Young).

Christopher John Fields cjfields at dev.open-bio.org
Mon Jan 25 00:04:39 EST 2010


Revision: 16751
Author:   cjfields
Date:     2010-01-25 00:04:39 -0500 (Mon, 25 Jan 2010)
Log Message:
-----------
[bug 2901] Deal with div by zero in cases where gaps exist (per Janet Young).  In cases where this occurs, using 'NA' as a placeholder.  Passes all tests, but this may be changed to something else if warranted.

Modified Paths:
--------------
    bioperl-live/trunk/Bio/Align/DNAStatistics.pm

Modified: bioperl-live/trunk/Bio/Align/DNAStatistics.pm
===================================================================
--- bioperl-live/trunk/Bio/Align/DNAStatistics.pm	2010-01-25 03:54:32 UTC (rev 16750)
+++ bioperl-live/trunk/Bio/Align/DNAStatistics.pm	2010-01-25 05:04:39 UTC (rev 16751)
@@ -636,12 +636,14 @@
 	   my $m = ( $matrix->[0]->[0] + 
 		     $matrix->[1]->[1] +
 		     $matrix->[2]->[2] +
-		     $matrix->[3]->[3] ); 
-	   my $D = 1 - ( $m / ( $len - $gaps + ( $gaps * $gappenalty)));
+		     $matrix->[3]->[3] );
+       my $denom = ( $len - $gaps + ( $gaps * $gappenalty));
+       
+	   my $D = $denom ? 1 - ( $m / $denom) : 'NA';
 	   # fwd and rev lookup
 	   $dist{$names[$i]}->{$names[$j]} = [$i,$j];
-	   $dist{$names[$j]}->{$names[$i]} = [$i,$j];	   
-	   $values[$j][$i] = $values[$i][$j] = sprintf($precisionstr,$D);
+	   $dist{$names[$j]}->{$names[$i]} = [$i,$j];
+	   $values[$j][$i] = $values[$i][$j] = $denom ? sprintf($precisionstr,$D) : $D;
            # (diagonals) distance is 0 for same sequence
 	   $dist{$names[$j]}->{$names[$j]} = [$j,$j];	   
 	   $values[$j][$j] = sprintf($precisionstr,0); 



More information about the Bioperl-guts-l mailing list