JAL-2136 Introduced DynamicData model, modified AnnotionFile to store Phyre meta...
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index 6c8f40f..3a7ee65 100644 (file)
@@ -22,6 +22,8 @@ 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;
 import jalview.io.gff.GffConstants;
@@ -449,9 +451,73 @@ public class SequenceAnnotationReport
       }
     }
     sb.append("</i>");
+    List<PDBEntry> pdbEntries = ds.getAllPDBEntries();
+    sb.append(getToolTipTextFromPDBEntries(pdbEntries));
     return maxWidth;
   }
 
+  private String getToolTipTextFromPDBEntries(List<PDBEntry> pdbEntries)
+  {
+    String tooltip = "";
+    if (pdbEntries.isEmpty())
+    {
+      return tooltip;
+    }
+    if (pdbEntries.size() > 1)
+    {
+      int x = 0;
+      PDBEntry bestRanked = null;
+      for (PDBEntry pdb : pdbEntries)
+      {
+        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>"
+              : "";
+    }
+    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,
           SequenceI sequence, boolean showDbRefs, boolean showNpFeats,
           Map<String, float[][]> minmax)