JAL-3725 restrict mapped virtual feature location to mapped region
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index 27c1652..9ffdf21 100644 (file)
@@ -20,7 +20,8 @@
  */
 package jalview.io;
 
-import java.util.Arrays;
+import java.util.Locale;
+
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.LinkedHashMap;
@@ -58,9 +59,7 @@ public class SequenceAnnotationReport
 
   private static String linkImageURL;
 
-  private static final String[][] PRIMARY_SOURCES = new String[][] {
-      DBRefSource.CODINGDBS, DBRefSource.DNACODINGDBS,
-      DBRefSource.PROTEINDBS };
+ // public static final String[][] PRIMARY_SOURCES  moved to DBRefSource.java
 
   /*
    * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
@@ -82,8 +81,8 @@ public class SequenceAnnotationReport
       }
       String s1 = ref1.getSource();
       String s2 = ref2.getSource();
-      boolean s1Primary = isPrimarySource(s1);
-      boolean s2Primary = isPrimarySource(s2);
+      boolean s1Primary = DBRefSource.isPrimarySource(s1);
+      boolean s2Primary = DBRefSource.isPrimarySource(s2);
       if (s1Primary && !s2Primary)
       {
         return -1;
@@ -104,20 +103,20 @@ public class SequenceAnnotationReport
       return comp;
     }
 
-    private boolean isPrimarySource(String source)
-    {
-      for (String[] primary : PRIMARY_SOURCES)
-      {
-        for (String s : primary)
-        {
-          if (source.equals(s))
-          {
-            return true;
-          }
-        }
-      }
-      return false;
-    }
+//    private boolean isPrimarySource(String source)
+//    {
+//      for (String[] primary : DBRefSource.PRIMARY_SOURCES)
+//      {
+//        for (String s : primary)
+//        {
+//          if (source.equals(s))
+//          {
+//            return true;
+//          }
+//        }
+//      }
+//      return false;
+//    }
   };
 
   private boolean forTooltip;
@@ -210,12 +209,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
@@ -276,7 +290,7 @@ public class SequenceAnnotationReport
          * truncate overlong descriptions unless they contain an href
          * before the truncation point (as truncation could leave corrupted html)
          */
-        int linkindex = description.toLowerCase().indexOf("<a ");
+        int linkindex = description.toLowerCase(Locale.ROOT).indexOf("<a ");
         boolean hasLink = linkindex > -1
                 && linkindex < MAX_DESCRIPTION_LENGTH;
         if (description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
@@ -403,8 +417,8 @@ public class SequenceAnnotationReport
                       + "\" target=\""
                       + urllink.get(0)
                       + "\">"
-                      + (urllink.get(0).toLowerCase()
-                              .equals(urllink.get(1).toLowerCase()) ? urllink
+                      + (urllink.get(0).toLowerCase(Locale.ROOT)
+                              .equals(urllink.get(1).toLowerCase(Locale.ROOT)) ? urllink
                               .get(0) : (urllink.get(0) + ":" + urllink
                                               .get(1)))
                       + "</a><br/>");
@@ -522,14 +536,14 @@ public class SequenceAnnotationReport
   protected int appendDbRefs(final StringBuilder sb, SequenceI ds,
           boolean summary)
   {
-    DBRefEntry[] dbrefs = ds.getDBRefs();
+    List<DBRefEntry> dbrefs = ds.getDBRefs();
     if (dbrefs == null)
     {
       return 0;
     }
 
     // note this sorts the refs held on the sequence!
-    Arrays.sort(dbrefs, comparator);
+    dbrefs.sort(comparator);
     boolean ellipsis = false;
     String source = null;
     String lastSource = null;