JAL-629 Fasta sequence id reading whitespace fix. Flexioble pae json keys and structu...
[jalview.git] / src / jalview / ws / dbsources / EBIAlfaFold.java
index e5f1243..b3bcfd9 100644 (file)
@@ -30,6 +30,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 import org.json.simple.parser.ParseException;
 
 import com.stevesoft.pat.Regex;
@@ -375,7 +377,6 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
       for (int i = 0; i < seqs.length; i++)
       {
         SequenceI s = seqs[i];
-        Console.debug("******* sequences[" + i + "]='" + s.getName() + "'");
       }
     }
     /* end debug */
@@ -388,8 +389,6 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
     }
     if (sequence == null)
     {
-      Console.debug("***** Looking for sequence with id '" + seqId + "'");
-
       SequenceI[] sequences = pdbAlignment.findSequenceMatch(seqId);
       if (sequences == null || sequences.length < 1)
       {
@@ -403,17 +402,31 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
       }
     }
 
-    List<Object> pae_obj = (List<Object>) Platform.parseJSON(pae_input);
-    if (pae_obj == null)
+    Object paeJson = Platform.parseJSON(pae_input);
+    JSONObject paeDict = null;
+    if (paeJson instanceof JSONObject)
+    {
+      Console.debug("***** paeJson is a JSONObject");
+      paeDict = (JSONObject) paeJson;
+    }
+    else if (paeJson instanceof JSONArray)
+    {
+      JSONArray jsonArray = (JSONArray) paeJson;
+      if (jsonArray.size() > 0)
+        paeDict = (JSONObject) jsonArray.get(0);
+    }
+
+    if (paeDict == null)
     {
       Console.debug("JSON file did not parse properly.");
       return false;
     }
     ContactMatrixI matrix = new PAEContactMatrix(sequence,
-            (Map<String, Object>) pae_obj.get(0));
+            (Map<String, Object>) paeDict);
 
     AlignmentAnnotation cmannot = sequence.addContactList(matrix);
     pdbAlignment.addAnnotation(cmannot);
+
     return true;
   }