Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index dca53e1..d2e8aba 100644 (file)
  */
 package jalview.io;
 
-import java.util.Locale;
+import java.util.ArrayList;
 
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import jalview.api.FeatureColourI;
@@ -210,12 +211,27 @@ public class SequenceAnnotationReport
      * if this is a virtual features, convert begin/end to the
      * coordinates of the sequence it is mapped to
      */
-    int[] beginRange = null;
-    int[] endRange = null;
+    int[] beginRange = null; // feature start in local coordinates
+    int[] endRange = null; // feature end in local coordinates
     if (mf != null)
     {
-      beginRange = mf.getMappedPositions(begin, begin);
-      endRange = mf.getMappedPositions(end, end);
+      if (feature.isContactFeature())
+      {
+        /*
+         * map start and end points individually
+         */
+        beginRange = mf.getMappedPositions(begin, begin);
+        endRange = begin == end ? beginRange
+                : mf.getMappedPositions(end, end);
+      }
+      else
+      {
+        /*
+         * map the feature extent
+         */
+        beginRange = mf.getMappedPositions(begin, end);
+        endRange = beginRange;
+      }
       if (beginRange == null || endRange == null)
       {
         // something went wrong
@@ -240,7 +256,7 @@ public class SequenceAnnotationReport
       {
         if (sb0.length() > 6)
         {
-          sb.append("<br>");
+          sb.append("<br/>");
         }
         sb.append(feature.getType()).append(" ").append(begin).append(":")
                 .append(end);
@@ -250,7 +266,7 @@ public class SequenceAnnotationReport
 
     if (sb0.length() > 6)
     {
-      sb.append("<br>");
+      sb.append("<br/>");
     }
     // TODO: remove this hack to display link only features
     boolean linkOnly = feature.getValue("linkonly") != null;
@@ -483,7 +499,7 @@ public class SequenceAnnotationReport
       sb.append(tmp);
       maxWidth = Math.max(maxWidth, tmp.length());
     }
-
+    sb.append("\n");
     SequenceI ds = sequence;
     while (ds.getDatasetSequence() != null)
     {
@@ -515,6 +531,7 @@ public class SequenceAnnotationReport
     {
       maxWidth = Math.max(maxWidth, appendDbRefs(sb, ds, summary));
     }
+    sb.append("\n");
 
     /*
      * add non-positional features if wanted
@@ -530,8 +547,6 @@ public class SequenceAnnotationReport
         maxWidth = Math.max(maxWidth, sz);
       }
     }
-
-
     if (sequence.getAnnotation("Search Scores") != null)
     {
       sb.append("<br>");
@@ -547,7 +562,6 @@ public class SequenceAnnotationReport
       sb.append("<br>");
     }
     sb.append("</i>");
-
     return maxWidth;
   }
 
@@ -563,12 +577,18 @@ public class SequenceAnnotationReport
   protected int appendDbRefs(final StringBuilder sb, SequenceI ds,
           boolean summary)
   {
-    List<DBRefEntry> dbrefs = ds.getDBRefs();
-    if (dbrefs == null)
+    List<DBRefEntry> dbrefs, dbrefset = ds.getDBRefs();
+
+    if (dbrefset == null)
     {
       return 0;
     }
 
+    // PATCH for JAL-3980 defensive copy
+
+    dbrefs = new ArrayList<DBRefEntry>();
+
+    dbrefs.addAll(dbrefset);
     // note this sorts the refs held on the sequence!
     dbrefs.sort(comparator);
     boolean ellipsis = false;
@@ -605,7 +625,7 @@ public class SequenceAnnotationReport
       countForSource++;
       if (countForSource == 1 || !summary)
       {
-        sb.append("<br>");
+        sb.append("<br/>\n");
       }
       if (countForSource <= MAX_REFS_PER_SOURCE || !summary)
       {
@@ -613,7 +633,7 @@ public class SequenceAnnotationReport
         lineLength += accessionId.length() + 1;
         if (countForSource > 1 && summary)
         {
-          sb.append(", ").append(accessionId);
+          sb.append(",\n ").append(accessionId);
           lineLength++;
         }
         else
@@ -631,11 +651,11 @@ public class SequenceAnnotationReport
     }
     if (moreSources)
     {
-      sb.append("<br>").append(source).append(COMMA).append(ELLIPSIS);
+      sb.append("<br/>\n").append(source).append(COMMA).append(ELLIPSIS);
     }
     if (ellipsis)
     {
-      sb.append("<br>(");
+      sb.append("<br/>\n(");
       sb.append(MessageManager.getString("label.output_seq_details"));
       sb.append(")");
     }