src/lib/numObscure.c 1.3
1.3 2009/12/01 06:49:39 kent
Adding rangeIncludingZero logic to rangeFromMinMaxMeanStd in case when min/max/mean are the same.
Index: src/lib/numObscure.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/numObscure.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -b -B -U 4 -r1.2 -r1.3
--- src/lib/numObscure.c 1 Dec 2009 05:34:02 -0000 1.2
+++ src/lib/numObscure.c 1 Dec 2009 06:49:39 -0000 1.3
@@ -1,35 +1,42 @@
/* numObscure - obscure but sometimes useful numerical functions. */
#include "common.h"
#include "obscure.h"
-void rangeRoundUp(double start, double end, double *retStart, double *retEnd)
-/* Round start and end so that they cover a slightly bigger range, but with more round
- * numbers. For instance 0.23:9.89 becomes 0:10 */
+static void rangeIncludingZero(double start, double end, double *retStart, double *retEnd)
+/* If start == end, then make range go from zero to the start/end value. */
{
-double size = end - start;
-if (size < 0)
- errAbort("start (%g) after end (%g) in rangeRoundUp", start, end);
-
-/* Flat ranges get moved to include zero for scale. */
-if (size == 0.0)
- {
- if (start < 0.0)
+if (start < 0.0)
{
*retStart = start;
*retEnd = 0;
}
- else if (start > 0.0)
+else if (start > 0.0)
{
*retStart = 0;
*retEnd = end;
}
- else
+else
{
*retStart = 0;
*retEnd = 1;
}
- return;
+return;
+}
+
+void rangeRoundUp(double start, double end, double *retStart, double *retEnd)
+/* Round start and end so that they cover a slightly bigger range, but with more round
+ * numbers. For instance 0.23:9.89 becomes 0:10 */
+{
+double size = end - start;
+if (size < 0)
+ errAbort("start (%g) after end (%g) in rangeRoundUp", start, end);
+
+/* Flat ranges get moved to include zero for scale. */
+if (size == 0.0)
+ {
+ rangeIncludingZero(start, end, &start, &end);
+ size = end - start;
}
/* Figure out "increment", which will be 1, 2, 5, or 10, or a multiple of 10 of these
* Want to have at least two increments in range. */
@@ -70,18 +77,27 @@
{
double start,end;
if (isnan(std))
{
+ /* Handle a case that occurred in version 1 bigWigs and bigBeds due to fault in
+ * sumSquares calculation. */
start = mean-5;
end = mean+5;
+ if (start < minVal) start = minVal;
+ if (end > maxVal) end = maxVal;
+ }
+else if (std == 0)
+ {
+ start = end = mean;
+ rangeIncludingZero(start, end, &start, &end);
}
else
{
start = mean - 5*std;
end = mean + 5*std;
+ if (start < minVal) start = minVal;
+ if (end > maxVal) end = maxVal;
}
-if (start < minVal) start = minVal;
-if (end > maxVal) end = maxVal;
*retStart = start;
*retEnd = end;
}