JAL-629 fix a PAEMatrix casting error
[jalview.git] / src / jalview / ws / datamodel / alphafold / PAEContactMatrix.java
index 0ac3e00..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
 {
@@ -30,7 +31,6 @@ public class PAEContactMatrix implements ContactMatrixI
 
   @SuppressWarnings("unchecked")
   public PAEContactMatrix(SequenceI _refSeq, Map<String, Object> pae_obj)
-          throws Exception
   {
     refSeq = _refSeq;
     while (refSeq.getDatasetSequence() != null)
@@ -40,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;
@@ -60,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;
@@ -111,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
@@ -184,6 +189,5 @@ public class PAEContactMatrix implements ContactMatrixI
   public String getAnnotLabel()
   {
     return "pAE Matrix";
-
   }
 }