Merge branch 'develop' into features/JAL-1793VCF
[jalview.git] / src / jalview / datamodel / SequenceFeature.java
index 6834341..420ade1 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.datamodel;
 
 import jalview.datamodel.features.FeatureLocationI;
+import jalview.util.StringUtils;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -29,10 +30,9 @@ import java.util.TreeMap;
 import java.util.Vector;
 
 /**
- * DOCUMENT ME!
- * 
- * @author $author$
- * @version $Revision$
+ * A class that models a single contiguous feature on a sequence. If flag
+ * 'contactFeature' is true, the start and end positions are interpreted instead
+ * as two contact points.
  */
 public class SequenceFeature implements FeatureLocationI
 {
@@ -52,6 +52,8 @@ public class SequenceFeature implements FeatureLocationI
   // private key for ENA location designed not to conflict with real GFF data
   private static final String LOCATION = "!Location";
 
+  private static final String ROW_DATA = "<tr><td>%s</td><td>%s</td></tr>";
+
   /*
    * map of otherDetails special keys, and their value fields' delimiter
    */
@@ -60,6 +62,8 @@ public class SequenceFeature implements FeatureLocationI
   static
   {
     INFO_KEYS.put("CSQ", ",");
+    // todo capture second level metadata (CSQ FORMAT)
+    // and delimiter "|" so as to report in a table within a table?
   }
 
   /*
@@ -548,26 +552,28 @@ public class SequenceFeature implements FeatureLocationI
   }
 
   /**
-   * Answers a formatted text report of feature details
+   * Answers an html-formatted report of feature details
    * 
    * @return
    */
   public String getDetailsReport()
   {
     StringBuilder sb = new StringBuilder(128);
-    if (begin == end)
+    sb.append("<br>");
+    sb.append("<table>");
+    sb.append(String.format(ROW_DATA, "Type", type));
+    sb.append(String.format(ROW_DATA, "Start/end", begin == end ? begin
+            : begin + (isContactFeature() ? ":" : "-") + end));
+    String desc = StringUtils.stripHtmlTags(description);
+    sb.append(String.format(ROW_DATA, "Description", desc));
+    if (!Float.isNaN(score) && score != 0f)
     {
-      sb.append(String.format("%s %d %s", type, begin, description));
-    }
-    else
-    {
-      sb.append(String.format("%s %d-%d %s", type, begin, end, description));
+      sb.append(String.format(ROW_DATA, "Score", score));
     }
     if (featureGroup != null)
     {
-      sb.append(" (").append(featureGroup).append(")");
+      sb.append(String.format(ROW_DATA, "Group", featureGroup));
     }
-    sb.append("\n\n");
 
     if (otherDetails != null)
     {
@@ -587,16 +593,24 @@ public class SequenceFeature implements FeatureLocationI
           /*
            * split selected INFO data by delimiter over multiple lines
            */
-          sb.append(key).append("\n");
           String delimiter = INFO_KEYS.get(key);
-          sb.append(entry.getValue().toString().replace(delimiter, "\n"));
+          String[] values = entry.getValue().toString().split(delimiter);
+          for (String value : values)
+          {
+            sb.append("<tr><td>").append(key).append("</td><td>")
+                    .append(value)
+                    .append("</td></tr>");
+          }
         }
         else
-        {
-          sb.append(key + "=" + entry.getValue().toString() + "\n");
+        { // tried <td title="key"> but it failed to provide a tooltip :-(
+          sb.append("<tr><td>").append(key).append("</td><td>");
+          sb.append(entry.getValue().toString()).append("</td></tr>");
         }
       }
     }
+    sb.append("</table>");
+
     String text = sb.toString();
     return text;
   }