JAL-1793 spike branch updated to latest
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index c3b076c..6d819d3 100644 (file)
@@ -26,6 +26,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.io.gff.GffConstants;
 import jalview.util.MessageManager;
+import jalview.util.StringUtils;
 import jalview.util.UrlLink;
 
 import java.util.Arrays;
@@ -58,7 +59,7 @@ public class SequenceAnnotationReport
 
   /*
    * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
-   * with 'Primary' sources placed before others
+   * with 'Primary' sources placed before others, and 'chromosome' first of all
    */
   private static Comparator<DBRefEntry> comparator = new Comparator<DBRefEntry>()
   {
@@ -66,6 +67,14 @@ public class SequenceAnnotationReport
     @Override
     public int compare(DBRefEntry ref1, DBRefEntry ref2)
     {
+      if (ref1.isChromosome())
+      {
+        return -1;
+      }
+      if (ref2.isChromosome())
+      {
+        return 1;
+      }
       String s1 = ref1.getSource();
       String s2 = ref2.getSource();
       boolean s1Primary = isPrimarySource(s1);
@@ -78,14 +87,14 @@ public class SequenceAnnotationReport
       {
         return 1;
       }
-      int comp = s1 == null ? -1 : (s2 == null ? 1 : s1
-              .compareToIgnoreCase(s2));
+      int comp = s1 == null ? -1
+              : (s2 == null ? 1 : s1.compareToIgnoreCase(s2));
       if (comp == 0)
       {
         String a1 = ref1.getAccessionId();
         String a2 = ref2.getAccessionId();
-        comp = a1 == null ? -1 : (a2 == null ? 1 : a1
-                .compareToIgnoreCase(a2));
+        comp = a1 == null ? -1
+                : (a2 == null ? 1 : a1.compareToIgnoreCase(a2));
       }
       return comp;
     }
@@ -151,8 +160,7 @@ public class SequenceAnnotationReport
           sb.append("<br>");
         }
         sb.append(feature.getType()).append(" ").append(feature.getBegin())
-                .append(":")
-                .append(feature.getEnd());
+                .append(":").append(feature.getEnd());
       }
     }
     else
@@ -176,56 +184,17 @@ public class SequenceAnnotationReport
           sb.append(" ").append(feature.end);
         }
 
-        if (feature.getDescription() != null
-                && !feature.description.equals(feature.getType()))
+        String description = feature.getDescription();
+        if (description != null && !description.equals(feature.getType()))
         {
-          String tmpString = feature.getDescription();
-          String tmp2up = tmpString.toUpperCase();
-          int startTag = tmp2up.indexOf("<HTML>");
-          if (startTag > -1)
-          {
-            tmpString = tmpString.substring(startTag + 6);
-            tmp2up = tmp2up.substring(startTag + 6);
-          }
-          int endTag = tmp2up.indexOf("</BODY>");
-          if (endTag > -1)
-          {
-            tmpString = tmpString.substring(0, endTag);
-            tmp2up = tmp2up.substring(0, endTag);
-          }
-          endTag = tmp2up.indexOf("</HTML>");
-          if (endTag > -1)
-          {
-            tmpString = tmpString.substring(0, endTag);
-          }
-
-          if (startTag > -1)
-          {
-            sb.append("; ").append(tmpString);
-          }
-          else
-          {
-            if (tmpString.indexOf("<") > -1 || tmpString.indexOf(">") > -1)
-            {
-              // The description does not specify html is to
-              // be used, so we must remove < > symbols
-              tmpString = tmpString.replaceAll("<", "&lt;");
-              tmpString = tmpString.replaceAll(">", "&gt;");
-
-              sb.append("; ");
-              sb.append(tmpString);
-            }
-            else
-            {
-              sb.append("; ").append(tmpString);
-            }
-          }
+          description = StringUtils.stripHtmlTags(description);
+          sb.append("; ").append(description);
         }
         // check score should be shown
         if (!Float.isNaN(feature.getScore()))
         {
-          float[][] rng = (minmax == null) ? null : minmax.get(feature
-                  .getType());
+          float[][] rng = (minmax == null) ? null
+                  : minmax.get(feature.getType());
           if (rng != null && rng[0] != null && rng[0][0] != rng[0][1])
           {
             sb.append(" Score=").append(String.valueOf(feature.getScore()));
@@ -269,21 +238,19 @@ public class SequenceAnnotationReport
           {
             for (List<String> urllink : createLinksFrom(null, urlstring))
             {
-              sb.append("<br/> <a href=\""
-                      + urllink.get(3)
-                      + "\" target=\""
-                      + urllink.get(0)
-                      + "\">"
+              sb.append("<br/> <a href=\"" + urllink.get(3) + "\" target=\""
+                      + urllink.get(0) + "\">"
                       + (urllink.get(0).toLowerCase()
-                              .equals(urllink.get(1).toLowerCase()) ? urllink
-                              .get(0) : (urllink.get(0) + ":" + urllink
-                              .get(1)))
+                              .equals(urllink.get(1).toLowerCase())
+                                      ? urllink.get(0)
+                                      : (urllink.get(0) + ":"
+                                              + urllink.get(1)))
                       + "</a></br>");
             }
           } catch (Exception x)
           {
-            System.err.println("problem when creating links from "
-                    + urlstring);
+            System.err.println(
+                    "problem when creating links from " + urlstring);
             x.printStackTrace();
           }
         }
@@ -478,8 +445,8 @@ public class SequenceAnnotationReport
           SequenceI sequence, boolean showDbRefs, boolean showNpFeats,
           Map<String, float[][]> minmax)
   {
-    int maxWidth = createSequenceAnnotationReport(tip, sequence,
-            showDbRefs, showNpFeats, minmax, true);
+    int maxWidth = createSequenceAnnotationReport(tip, sequence, showDbRefs,
+            showNpFeats, minmax, true);
 
     if (maxWidth > 60)
     {