JAL-2136 Introduced DynamicData model, modified AnnotionFile to store Phyre meta...
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index a855aa2..3a7ee65 100644 (file)
@@ -22,6 +22,7 @@ package jalview.io;
 
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
+import jalview.datamodel.DynamicData;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
@@ -450,15 +451,71 @@ public class SequenceAnnotationReport
       }
     }
     sb.append("</i>");
+    List<PDBEntry> pdbEntries = ds.getAllPDBEntries();
+    sb.append(getToolTipTextFromPDBEntries(pdbEntries));
+    return maxWidth;
+  }
 
-    for (PDBEntry pdb : ds.getAllPDBEntries())
+  private String getToolTipTextFromPDBEntries(List<PDBEntry> pdbEntries)
+  {
+    String tooltip = "";
+    if (pdbEntries.isEmpty())
     {
-      if (pdb != null && pdb.getProperty("PHYRE2_MODEL_INFO") != null)
+      return tooltip;
+    }
+    if (pdbEntries.size() > 1)
+    {
+      int x = 0;
+      PDBEntry bestRanked = null;
+      for (PDBEntry pdb : pdbEntries)
       {
-        sb.append(pdb.getProperty("PHYRE2_MODEL_INFO"));
+        if (pdb.getProperty("DYNAMIC_DATA_PHYRE2") != null)
+        {
+          x++;
+        }
+        // best ranked entry must be from a Phyre
+        if (x > 0 && bestRanked == null)
+        {
+          bestRanked = pdb;
+        }
       }
+      tooltip = (x > 0) ? "<table border=\"1\" width=100%><tr><td>Contains <b>"
+              + x
+              + "</b> Phyre2 model structure(s)</td></tr>"
+              + "<tr><td>Best ranked Phyre2 model is <b>"
+              + bestRanked.getId() + "</b></td></tr></table>"
+              : "";
     }
-    return maxWidth;
+    else
+    {
+      PDBEntry pdb = pdbEntries.iterator().next();
+      if (pdb.getProperty("DYNAMIC_DATA_PHYRE2") != null)
+      {
+        tooltip = getPhyreToolTipFromDynamicData((List<DynamicData>) pdb
+                .getProperty("DYNAMIC_DATA_PHYRE2"));
+      }
+    }
+    return tooltip;
+  }
+
+  private String getPhyreToolTipFromDynamicData(
+          List<DynamicData> dynamicDataList)
+  {
+    StringBuilder phyre2InfoBuilder = new StringBuilder();
+    phyre2InfoBuilder
+            .append("<html><table border=\"1\" width=100%>")
+            .append("<tr><td colspan=\"2\"><strong>Phyre2 Template Info</strong></td></tr>");
+    for (DynamicData data : dynamicDataList)
+    {
+      if (data.isDisplay())
+      {
+        phyre2InfoBuilder.append("<tr><td>").append(data.getFieldTitle())
+                .append("</td><td>").append(data.getFieldValue())
+                .append("</td></tr>");
+      }
+    }
+    phyre2InfoBuilder.append("</table></html>");
+    return phyre2InfoBuilder.toString();
   }
 
   public void createTooltipAnnotationReport(final StringBuilder tip,