JAL-629 fix a PAEMatrix casting error
[jalview.git] / src / jalview / ws / datamodel / alphafold / PAEContactMatrix.java
index 3298a96..f282b9f 100644 (file)
@@ -9,6 +9,7 @@ import jalview.datamodel.ContactListImpl;
 import jalview.datamodel.ContactListProviderI;
 import jalview.datamodel.ContactMatrixI;
 import jalview.datamodel.SequenceI;
+import jalview.util.MapUtils;
 
 public class PAEContactMatrix implements ContactMatrixI
 {
@@ -39,7 +40,7 @@ public class PAEContactMatrix implements ContactMatrixI
     // convert the lists to primitive arrays and store
     length = _refSeq.getEnd() - _refSeq.getStart() + 1;
 
-    if (!pae_obj.containsKey("predicted_aligned_error"))
+    if (!MapUtils.containsAKey(pae_obj, "predicted_aligned_error", "pae"))
     {
       parse_version_1_pAE(pae_obj);
       return;
@@ -59,17 +60,22 @@ public class PAEContactMatrix implements ContactMatrixI
   {
     elements = new float[length][length];
     // this is never going to be reached by the integer rounding.. or is it ?
-    maxscore = ((Double) pae_obj.get("max_predicted_aligned_error"))
-            .floatValue();
-    Iterator<List<Long>> scoreRows = ((List<List<Long>>) pae_obj
-            .get("predicted_aligned_error")).iterator();
+    maxscore = ((Double) MapUtils.getFirst(pae_obj,
+            "max_predicted_aligned_error", "max_pae")).floatValue();
+    Iterator<List<Long>> scoreRows = ((List<List<Long>>) MapUtils
+            .getFirst(pae_obj, "predicted_aligned_error", "pae"))
+            .iterator();
     int row = 0, col = 0;
     while (scoreRows.hasNext())
     {
       Iterator<Long> scores = scoreRows.next().iterator();
       while (scores.hasNext())
       {
-        elements[row][col++] = scores.next();
+        Object d = scores.next();
+        if (d instanceof Double)
+          elements[row][col++] = ((Double) d).longValue();
+        else
+          elements[row][col++] = (float) d;
       }
       row++;
       col = 0;
@@ -110,8 +116,8 @@ public class PAEContactMatrix implements ContactMatrixI
       elements[row - 1][col - 1] = escore;
     }
 
-    maxscore = ((Double) pae_obj.get("max_predicted_aligned_error"))
-            .floatValue();
+    maxscore = ((Double) MapUtils.getFirst(pae_obj,
+            "max_predicted_aligned_error", "max_pae")).floatValue();
   }
 
   @Override