Skip to content

Commit 0103ed2

Browse files
committed
Fix heatmaps to handle NaN values in CDT
The heatmap files were not appropriately handling NaN entries. Any values in CDT that throw a NumberFormatException when parsing into a Double object are now treated as NaN and take the appropriate color value accordingly (default gray).
1 parent 8a8153f commit 0103ed2

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/scripts/Figure_Generation/ThreeColorHeatMap.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ public static ArrayList<double[]> rebinMatrix(ArrayList<double[]> oldmatrix) {
373373
double[] newRow = new double[c];
374374
for (int j = 0; j < C; j += (C / c)) {
375375
double AVG = 0, count = 0;
376-
;
377376
for (int x = i; x < i + (R / r); x++) {
378377
for (int y = j; y < j + (C / c); y++) {
379378
AVG += oldmatrix.get(x)[y];
@@ -429,7 +428,7 @@ public static double[] getQuantile_nonZero(ArrayList<double[]> matrix, double p_
429428
ArrayList<Double> nonZero = new ArrayList<Double>();
430429
for (int x = 0; x < matrix.size(); x++) {
431430
for (int y = 0; y < matrix.get(x).length; y++) {
432-
if (matrix.get(x)[y] != 0) {
431+
if (matrix.get(x)[y] != 0 && !Double.isNaN(matrix.get(x)[y])) {
433432
nonZero.add(Double.valueOf(matrix.get(x)[y]));
434433
}
435434
}
@@ -479,7 +478,11 @@ public static ArrayList<double[]> loadMatrix(File input) throws UnsupportedEncod
479478
if (!temp[0].contains("YORF") && currentRow >= startROW) {
480479
double[] ARRAY = new double[temp.length - startCOL];
481480
for (int x = startCOL; x < temp.length; x++) {
482-
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
481+
try {
482+
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
483+
} catch (NumberFormatException nfe) {
484+
ARRAY[x - startCOL] = Double.NaN;
485+
}
483486
}
484487
matrix.add(ARRAY);
485488
}
@@ -494,7 +497,11 @@ public static ArrayList<double[]> loadMatrix(File input) throws UnsupportedEncod
494497
if (!temp[0].contains("YORF") && currentRow >= startROW) {
495498
double[] ARRAY = new double[temp.length - startCOL];
496499
for (int x = startCOL; x < temp.length; x++) {
497-
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
500+
try {
501+
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
502+
} catch (NumberFormatException nfe) {
503+
ARRAY[x - startCOL] = Double.NaN;
504+
}
498505
}
499506
matrix.add(ARRAY);
500507
}

src/scripts/Figure_Generation/TwoColorHeatMap.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void run() throws IOException {
7878
} else {
7979
COLOR_RATIO = getQuantile(newMatrix, quantile);
8080
}
81-
81+
8282
System.out.println("Contrast threshold: " + COLOR_RATIO);
8383
BufferedImage treeMap = generateHeatMap(newMatrix);
8484
picLabel = new JLabel(new ImageIcon(treeMap));
@@ -297,7 +297,6 @@ public static ArrayList<double[]> rebinMatrix(ArrayList<double[]> oldmatrix) {
297297
double[] newRow = new double[c];
298298
for (int j = 0; j < C; j += (C / c)) {
299299
double AVG = 0, count = 0;
300-
;
301300
for (int x = i; x < i + (R / r); x++) {
302301
for (int y = j; y < j + (C / c); y++) {
303302
AVG += oldmatrix.get(x)[y];
@@ -376,7 +375,11 @@ public static ArrayList<double[]> loadMatrix(File input) throws UnsupportedEncod
376375
if (!temp[0].contains("YORF") && currentRow >= startROW) {
377376
double[] ARRAY = new double[temp.length - startCOL];
378377
for (int x = startCOL; x < temp.length; x++) {
379-
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
378+
try {
379+
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
380+
} catch (NumberFormatException nfe) {
381+
ARRAY[x - startCOL] = Double.NaN;
382+
}
380383
}
381384
matrix.add(ARRAY);
382385
}
@@ -391,7 +394,11 @@ public static ArrayList<double[]> loadMatrix(File input) throws UnsupportedEncod
391394
if (!temp[0].contains("YORF") && currentRow >= startROW) {
392395
double[] ARRAY = new double[temp.length - startCOL];
393396
for (int x = startCOL; x < temp.length; x++) {
394-
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
397+
try {
398+
ARRAY[x - startCOL] = Double.parseDouble(temp[x]);
399+
} catch (NumberFormatException nfe) {
400+
ARRAY[x - startCOL] = Double.NaN;
401+
}
395402
}
396403
matrix.add(ARRAY);
397404
}

0 commit comments

Comments
 (0)