Merge branch 'JAL-1373_precision' into develop
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Mon, 2 Sep 2013 17:14:45 +0000 (18:14 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Mon, 2 Sep 2013 17:14:45 +0000 (18:14 +0100)
src/jalview/analysis/AAFrequency.java
src/jalview/analysis/StructureFrequency.java
src/jalview/datamodel/SequenceGroup.java
src/jalview/gui/AnnotationPanel.java
src/jalview/workers/ConsensusThread.java
src/jalview/workers/StrucConsensusThread.java

index 50b1b4b..656cdcb 100755 (executable)
@@ -19,6 +19,7 @@ package jalview.analysis;
 
 import java.util.*;
 
+import jalview.util.Format;
 import jalview.datamodel.*;
 
 /**
@@ -194,14 +195,15 @@ public class AAFrequency
    * @param width
    * @param ignoreGapsInConsensusCalculation
    * @param includeAllConsSymbols
+   * @param nseq 
    */
   public static void completeConsensus(AlignmentAnnotation consensus,
           Hashtable[] hconsensus, int iStart, int width,
           boolean ignoreGapsInConsensusCalculation,
-          boolean includeAllConsSymbols)
+          boolean includeAllConsSymbols, long nseq)
   {
     completeConsensus(consensus, hconsensus, iStart, width,
-            ignoreGapsInConsensusCalculation, includeAllConsSymbols, null); // new
+            ignoreGapsInConsensusCalculation, includeAllConsSymbols, null, nseq); // new
                                                                             // char[]
     // { 'A', 'C', 'G', 'T', 'U' });
   }
@@ -209,7 +211,7 @@ public class AAFrequency
   public static void completeConsensus(AlignmentAnnotation consensus,
           Hashtable[] hconsensus, int iStart, int width,
           boolean ignoreGapsInConsensusCalculation,
-          boolean includeAllConsSymbols, char[] alphabet)
+          boolean includeAllConsSymbols, char[] alphabet, long nseq)
   {
     float tval, value;
     if (consensus == null || consensus.annotations == null
@@ -219,6 +221,17 @@ public class AAFrequency
       // initialised properly
       return;
     }
+    String fmtstr="%3.1f";
+    int precision=2;
+    while (nseq>100) {
+      precision++;
+      nseq/=10;
+    }
+    if (precision>2)
+    {
+      fmtstr = "%"+(2+precision)+"."+precision+"f";
+    }
+    Format fmt = new Format(fmtstr);
     for (int i = iStart; i < width; i++)
     {
       Hashtable hci;
@@ -229,7 +242,6 @@ public class AAFrequency
         consensus.annotations[i] = null;
         continue;
       }
-
       value = 0;
       Float fv;
       if (ignoreGapsInConsensusCalculation)
@@ -265,7 +277,7 @@ public class AAFrequency
             tval = profile[0][alphabet[c]] * 100f
                     / profile[1][ignoreGapsInConsensusCalculation ? 1 : 0];
             mouseOver += ((c == 0) ? "" : "; ") + alphabet[c] + " "
-                    + ((int) tval) + "%";
+                    + fmt.form(tval) + "%";
           }
         }
         else
@@ -288,7 +300,7 @@ public class AAFrequency
                       * 100f
                       / profile[1][ignoreGapsInConsensusCalculation ? 1 : 0];
               mouseOver += ((p == 0) ? "" : "; ") + ((char[]) ca[c])[0]
-                      + " " + ((int) tval) + "%";
+                      + " " + fmt.form(tval) + "%";
               p++;
 
             }
@@ -298,7 +310,7 @@ public class AAFrequency
       }
       else
       {
-        mouseOver += ((int) value + "%");
+        mouseOver += (fmt.form(value) + "%");
       }
       consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
               value);
index 32a4e29..cae5da2 100644 (file)
@@ -21,6 +21,7 @@ package jalview.analysis;
 
 import java.util.*;
 
+import jalview.util.Format;
 import jalview.datamodel.*;
 
 /**
@@ -344,7 +345,7 @@ public class StructureFrequency
   public static void completeConsensus(AlignmentAnnotation consensus,
           Hashtable[] hconsensus, int iStart, int width,
           boolean ignoreGapsInConsensusCalculation,
-          boolean includeAllConsSymbols)
+          boolean includeAllConsSymbols, long nseq)
   {
     float tval, value;
     if (consensus == null || consensus.annotations == null
@@ -354,6 +355,18 @@ public class StructureFrequency
       // initialised properly
       return;
     }
+    String fmtstr="%3.1f";
+    int precision=2;
+    while (nseq>100) {
+      precision++;
+      nseq/=10;
+    }
+    if (precision>2)
+    {
+      fmtstr = "%"+(2+precision)+"."+precision+"f";
+    }
+    Format fmt = new Format(fmtstr);
+    
     for (int i = iStart; i < width; i++)
     {
       Hashtable hci;
@@ -430,7 +443,7 @@ public class StructureFrequency
             tval = (vl[c] * 100f / profile[1][ignoreGapsInConsensusCalculation ? 1
                     : 0]);
             mouseOver += ((p == 0) ? "" : "; ") + (char) ((int[]) ca[c])[0]
-                    + (char) ((int[]) ca[c])[1] + " " + ((int) tval) + "%";
+                    + (char) ((int[]) ca[c])[1] + " " + fmt.form(tval) + "%";
             p++;
 
           }
@@ -440,7 +453,7 @@ public class StructureFrequency
       }
       else
       {
-        mouseOver += ((int) value + "%");
+        mouseOver += (fmt.form(value) + "%");
       }
       consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
               value);
index 65dc13f..5fcd2bf 100755 (executable)
@@ -493,7 +493,7 @@ public class SequenceGroup implements AnnotatedCollectionI
               endRes + 1, showSequenceLogo);
       if (consensus != null)
       {
-        _updateConsensusRow(cnsns);
+        _updateConsensusRow(cnsns, sequences.size());
       }
       if (cs != null)
       {
@@ -552,7 +552,7 @@ public class SequenceGroup implements AnnotatedCollectionI
 
   public Hashtable[] consensusData = null;
 
-  private void _updateConsensusRow(Hashtable[] cnsns)
+  private void _updateConsensusRow(Hashtable[] cnsns, long nseq)
   {
     if (consensus == null)
     {
@@ -569,7 +569,7 @@ public class SequenceGroup implements AnnotatedCollectionI
     consensus.annotations = new Annotation[aWidth]; // should be alignment width
 
     AAFrequency.completeConsensus(consensus, cnsns, startRes, endRes + 1,
-            ignoreGapsInConsensus, showSequenceLogo); // TODO: setting container
+            ignoreGapsInConsensus, showSequenceLogo, nseq); // TODO: setting container
                                                       // for
                                                       // ignoreGapsInConsensusCalculation);
   }
index ed899b1..b978a05 100755 (executable)
@@ -663,7 +663,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
               && aa[row].annotations[res].description != null
               && aa[row].annotations[res].description.length() > 0)
       {
-        this.setToolTipText(aa[row].annotations[res].description);
+        this.setToolTipText("<html>"+JvSwingUtils.wrapTooltip(aa[row].annotations[res].description)+"</html>");
       }
       else
       {
index 343e64d..c2b4d66 100644 (file)
@@ -24,6 +24,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceI;
 import jalview.schemes.ColourSchemeI;
 
 import java.util.Hashtable;
@@ -31,6 +32,8 @@ import java.util.Hashtable;
 public class ConsensusThread extends AlignCalcWorker implements
         AlignCalcWorkerI
 {
+  private long nseq=-1;
+
   public ConsensusThread(AlignViewportI alignViewport,
           AlignmentViewPanel alignPanel)
   {
@@ -94,7 +97,9 @@ public class ConsensusThread extends AlignCalcWorker implements
       hconsensus = new Hashtable[aWidth];
       try
       {
-        AAFrequency.calculate(alignment.getSequencesArray(), 0,
+        SequenceI aseqs[] = alignment.getSequencesArray();
+        nseq = aseqs.length;
+        AAFrequency.calculate(aseqs, 0,
                 alignment.getWidth(), hconsensus, true);
       } catch (ArrayIndexOutOfBoundsException x)
       {
@@ -150,7 +155,7 @@ public class ConsensusThread extends AlignCalcWorker implements
     {
       AAFrequency.completeConsensus(consensus, hconsensus, 0,
               hconsensus.length, alignViewport.getIgnoreGapsConsensus(),
-              alignViewport.isShowSequenceLogo());
+              alignViewport.isShowSequenceLogo(), nseq);
     }
   }
 }
index 86c3336..25e5cde 100644 (file)
@@ -26,6 +26,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.SequenceI;
 
 public class StrucConsensusThread extends AlignCalcWorker implements
         AlignCalcWorkerI
@@ -40,6 +41,8 @@ public class StrucConsensusThread extends AlignCalcWorker implements
 
   Hashtable[] hStrucConsensus;
 
+  private long nseq=-1;
+
   @Override
   public void run()
   {
@@ -107,8 +110,10 @@ public class StrucConsensusThread extends AlignCalcWorker implements
 
       try
       {
-        jalview.analysis.StructureFrequency.calculate(
-                alignment.getSequencesArray(), 0, alignment.getWidth(),
+        final SequenceI[] arr=
+                alignment.getSequencesArray();
+        nseq = arr.length;
+        jalview.analysis.StructureFrequency.calculate(arr, 0, alignment.getWidth(),
                 hStrucConsensus, true, rnaStruc);
       } catch (ArrayIndexOutOfBoundsException x)
       {
@@ -159,7 +164,7 @@ public class StrucConsensusThread extends AlignCalcWorker implements
       StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus,
               0, hStrucConsensus.length,
               alignViewport.getIgnoreGapsConsensus(),
-              alignViewport.isShowSequenceLogo());
+              alignViewport.isShowSequenceLogo(), nseq);
     }
   }