Merge branch 'alpha/JAL-3362_Jalview_212_alpha' into alpha/merge_212_JalviewJS_2112
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index 8328e7a..1a5072d 100644 (file)
@@ -20,7 +20,6 @@
  */
 package jalview.io;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.LinkedHashMap;
@@ -28,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 
 import jalview.api.FeatureColourI;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.GeneLociI;
@@ -58,9 +58,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 +80,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 +102,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;
@@ -216,6 +214,11 @@ public class SequenceAnnotationReport
     {
       beginRange = mf.getMappedPositions(begin, begin);
       endRange = mf.getMappedPositions(end, end);
+      if (beginRange == null || endRange == null)
+      {
+        // something went wrong
+        return false;
+      }
       begin = beginRange[0];
       end = endRange[endRange.length - 1];
     }
@@ -476,12 +479,27 @@ public class SequenceAnnotationReport
       sb.append(tmp);
       maxWidth = Math.max(maxWidth, tmp.length());
     }
+
     SequenceI ds = sequence;
     while (ds.getDatasetSequence() != null)
     {
       ds = ds.getDatasetSequence();
     }
 
+    /*
+     * add any annotation scores
+     */
+    AlignmentAnnotation[] anns = ds.getAnnotation();
+    for (int i = 0; anns != null && i < anns.length; i++)
+    {
+      AlignmentAnnotation aa = anns[i];
+      if (aa != null && aa.hasScore() && aa.sequenceRef != null)
+      {
+        sb.append("<br>").append(aa.label).append(": ")
+                .append(aa.getScore());
+      }
+    }
+
     if (showDbRefs)
     {
       maxWidth = Math.max(maxWidth, appendDbRefs(sb, ds, summary));
@@ -501,7 +519,24 @@ public class SequenceAnnotationReport
         maxWidth = Math.max(maxWidth, sz);
       }
     }
+
+
+    if (sequence.getAnnotation("Search Scores") != null)
+    {
+      sb.append("<br>");
+      String eValue = " E-Value: "
+              + sequence.getAnnotation("Search Scores")[0].getEValue();
+      String bitScore = " Bit Score: "
+              + sequence.getAnnotation("Search Scores")[0].getBitScore();
+      sb.append(eValue);
+      sb.append("<br>");
+      sb.append(bitScore);
+      maxWidth = Math.max(maxWidth, eValue.length());
+      maxWidth = Math.max(maxWidth, bitScore.length());
+    }
+    sb.append("<br>");
     sb.append("</i>");
+
     return maxWidth;
   }
 
@@ -517,14 +552,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;