Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / io / SequenceAnnotationReport.java
index 95bd1cc..d2e8aba 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.io;
 
 import java.util.ArrayList;
+
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.LinkedHashMap;
@@ -29,6 +30,7 @@ import java.util.Locale;
 import java.util.Map;
 
 import jalview.api.FeatureColourI;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.DBRefSource;
 import jalview.datamodel.GeneLociI;
@@ -59,7 +61,7 @@ public class SequenceAnnotationReport
 
   private static String linkImageURL;
 
-  // public static final String[][] PRIMARY_SOURCES moved to DBRefSource.java
+ // public static final String[][] PRIMARY_SOURCES  moved to DBRefSource.java
 
   /*
    * Comparator to order DBRefEntry by Source + accession id (case-insensitive),
@@ -91,32 +93,32 @@ 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;
     }
 
-    // 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 isPrimarySource(String source)
+//    {
+//      for (String[] primary : DBRefSource.PRIMARY_SOURCES)
+//      {
+//        for (String s : primary)
+//        {
+//          if (source.equals(s))
+//          {
+//            return true;
+//          }
+//        }
+//      }
+//      return false;
+//    }
   };
 
   private boolean forTooltip;
@@ -150,9 +152,9 @@ public class SequenceAnnotationReport
    * @param minmax
    * @param maxlength
    */
-  public int appendFeatures(final StringBuilder sb, int residuePos,
-          List<SequenceFeature> features, FeatureRendererModel fr,
-          int maxlength)
+  public int appendFeatures(final StringBuilder sb,
+          int residuePos, List<SequenceFeature> features,
+          FeatureRendererModel fr, int maxlength)
   {
     for (int i = 0; i < features.size(); i++)
     {
@@ -293,7 +295,9 @@ public class SequenceAnnotationReport
         int linkindex = description.toLowerCase(Locale.ROOT).indexOf("<a ");
         boolean hasLink = linkindex > -1
                 && linkindex < MAX_DESCRIPTION_LENGTH;
-        if (description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
+        if (
+                // BH suggestion maxlength == 0 && 
+                description.length() > MAX_DESCRIPTION_LENGTH && !hasLink)
         {
           description = description.substring(0, MAX_DESCRIPTION_LENGTH)
                   + ELLIPSIS;
@@ -412,19 +416,21 @@ public class SequenceAnnotationReport
           {
             for (List<String> urllink : createLinksFrom(null, urlstring))
             {
-              sb.append("<br/> <a href=\"" + urllink.get(3) + "\" target=\""
-                      + urllink.get(0) + "\">"
-                      + (urllink.get(0).toLowerCase(Locale.ROOT).equals(
-                              urllink.get(1).toLowerCase(Locale.ROOT))
-                                      ? urllink.get(0)
-                                      : (urllink.get(0) + ":"
-                                              + urllink.get(1)))
-                      + "</a><br/>");
+              sb.append("<br> <a href=\""
+                      + urllink.get(3)
+                      + "\" target=\""
+                      + urllink.get(0)
+                      + "\">"
+                      + (urllink.get(0).toLowerCase(Locale.ROOT)
+                              .equals(urllink.get(1).toLowerCase(Locale.ROOT)) ? 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();
           }
         }
@@ -500,6 +506,27 @@ public class SequenceAnnotationReport
       ds = ds.getDatasetSequence();
     }
 
+    
+    /*
+     * add any annotation scores
+     */
+    AlignmentAnnotation[] anns = ds.getAnnotation();
+    if (anns!=null && anns.length>0) {
+      boolean first=true;
+      for (int i = 0; anns != null && i < anns.length; i++)
+      {
+        AlignmentAnnotation aa = anns[i];
+        if (aa != null && aa.hasScore() && aa.sequenceRef != null)
+        {
+          if (first) {
+                 sb.append("<br>").append("Annotation Scores<br>");
+                 first=false;
+          }
+          sb.append("<br>").append(aa.label).append(": ")
+                  .append(aa.getScore());
+        }
+      }
+    }
     if (showDbRefs)
     {
       maxWidth = Math.max(maxWidth, appendDbRefs(sb, ds, summary));
@@ -520,6 +547,20 @@ 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;
   }
@@ -548,7 +589,6 @@ public class SequenceAnnotationReport
     dbrefs = new ArrayList<DBRefEntry>();
 
     dbrefs.addAll(dbrefset);
-
     // note this sorts the refs held on the sequence!
     dbrefs.sort(comparator);
     boolean ellipsis = false;
@@ -627,8 +667,8 @@ public class SequenceAnnotationReport
           SequenceI sequence, boolean showDbRefs, boolean showNpFeats,
           FeatureRendererModel fr)
   {
-    int maxWidth = createSequenceAnnotationReport(tip, sequence, showDbRefs,
-            showNpFeats, fr, true);
+    int maxWidth = createSequenceAnnotationReport(tip, sequence,
+            showDbRefs, showNpFeats, fr, true);
 
     if (maxWidth > 60)
     {