JAL-629 add AF examples for FER1_SPIOL. Link and display PAE matrix annotation
[jalview.git] / src / jalview / ws / dbsources / EBIAlfaFold.java
index 4ed28fc..672f0ac 100644 (file)
@@ -358,6 +358,14 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
   }
 
   public static boolean importPaeJSONAsContactMatrixToSequence(
+          AlignmentI pdbAlignment, File paeFile, int index, String seqId)
+          throws FileNotFoundException, IOException, ParseException
+  {
+    return importPaeJSONAsContactMatrixToSequence(pdbAlignment,
+            new FileInputStream(paeFile), index, seqId);
+  }
+
+  public static boolean importPaeJSONAsContactMatrixToSequence(
           AlignmentI pdbAlignment, InputStream pae_input, int index,
           String seqId) throws IOException, ParseException
   {
@@ -382,6 +390,24 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
       }
     }
 
+    JSONObject paeDict = parseJSONtoPAEContactMatrix(pae_input);
+    if (paeDict == null)
+    {
+      Console.debug("JSON file did not parse properly.");
+      return false;
+    }
+    ContactMatrixI matrix = new PAEContactMatrix(sequence,
+            (Map<String, Object>) paeDict);
+
+    AlignmentAnnotation cmannot = sequence.addContactList(matrix);
+    pdbAlignment.addAnnotation(cmannot);
+
+    return true;
+  }
+
+  public static JSONObject parseJSONtoPAEContactMatrix(
+          InputStream pae_input) throws IOException, ParseException
+  {
     Object paeJson = Platform.parseJSON(pae_input);
     JSONObject paeDict = null;
     if (paeJson instanceof JSONObject)
@@ -395,18 +421,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
         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>) paeDict);
-
-    AlignmentAnnotation cmannot = sequence.addContactList(matrix);
-    pdbAlignment.addAnnotation(cmannot);
-
-    return true;
+    return paeDict;
   }
 
   public static boolean importPaeJSONAsContactMatrixToStructure(
@@ -424,11 +439,18 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
   }
 
   public static boolean importPaeJSONAsContactMatrixToStructure(
+          StructureMapping sm, File paeFile)
+          throws FileNotFoundException, IOException, ParseException
+  {
+    return importPaeJSONAsContactMatrixToStructure(sm,
+            new FileInputStream(paeFile));
+  }
+
+  public static boolean importPaeJSONAsContactMatrixToStructure(
           StructureMapping sm, InputStream paeInput)
           throws IOException, ParseException
   {
-
-    List<Object> pae_obj = (List<Object>) Platform.parseJSON(paeInput);
+    JSONObject pae_obj = parseJSONtoPAEContactMatrix(paeInput);
     if (pae_obj == null)
     {
       Console.debug("JSON file did not parse properly.");
@@ -436,7 +458,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy
     }
 
     ContactMatrixI matrix = new PAEContactMatrix(sm.getSequence(),
-            (Map<String, Object>) pae_obj.get(0));
+            (Map<String, Object>) pae_obj);
 
     AlignmentAnnotation cmannot = sm.getSequence().addContactList(matrix);
     // sm.getSequence().addAlignmentAnnotation(cmannot);