Merge branch 'JAL-1373_precision' into RNAalifold
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Tue, 3 Sep 2013 13:27:54 +0000 (14:27 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Tue, 3 Sep 2013 13:27:54 +0000 (14:27 +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
src/jalview/ws/jws2/Jws2Discoverer.java

index 50b1b4b..df5ca8d 100755 (executable)
@@ -19,6 +19,7 @@ package jalview.analysis;
 
 import java.util.*;
 
+import jalview.util.Format;
 import jalview.datamodel.*;
 
 /**
@@ -90,7 +91,7 @@ public class AAFrequency
     Hashtable residueHash;
     int maxCount, nongap, i, j, v, jSize = sequences.length;
     String maxResidue;
-    char c;
+    char c='-';
     float percentage;
 
     int[] values = new int[255];
@@ -104,7 +105,7 @@ public class AAFrequency
       maxResidue = "";
       nongap = 0;
       values = new int[255];
-
+      
       for (j = 0; j < jSize; j++)
       {
         if (sequences[j] == null)
@@ -142,8 +143,11 @@ public class AAFrequency
           values['-']++;
         }
       }
-
-      for (v = 'A'; v < 'Z'; v++)
+      if (jSize==1)
+      {
+        maxResidue = String.valueOf(c);
+        maxCount=1;
+      } else {for (v = 'A'; v < 'Z'; v++)
       {
         if (values[v] < 2 || values[v] < maxCount)
         {
@@ -160,7 +164,7 @@ public class AAFrequency
         }
         maxCount = values[v];
       }
-
+      }
       if (maxResidue.length() == 0)
       {
         maxResidue = "-";
@@ -194,14 +198,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 +214,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 +224,23 @@ public class AAFrequency
       // initialised properly
       return;
     }
+    String fmtstr="%3.1f";
+    int precision=0;
+    while (nseq>=10) {
+      precision++;
+      nseq/=10;
+    }
+    final Format fmt;
+    if (precision>1)
+    {
+      //if (precision>2)
+      {
+        fmtstr = "%"+(2+precision)+"."+(precision)+"f";
+      }
+      fmt = new Format(fmtstr);
+    } else {
+      fmt = null;
+    }
     for (int i = iStart; i < width; i++)
     {
       Hashtable hci;
@@ -229,7 +251,6 @@ public class AAFrequency
         consensus.annotations[i] = null;
         continue;
       }
-
       value = 0;
       Float fv;
       if (ignoreGapsInConsensusCalculation)
@@ -265,7 +286,7 @@ public class AAFrequency
             tval = profile[0][alphabet[c]] * 100f
                     / profile[1][ignoreGapsInConsensusCalculation ? 1 : 0];
             mouseOver += ((c == 0) ? "" : "; ") + alphabet[c] + " "
-                    + ((int) tval) + "%";
+                    + ((fmt!=null) ? fmt.form(tval) : ((int) tval)) + "%";
           }
         }
         else
@@ -288,7 +309,7 @@ public class AAFrequency
                       * 100f
                       / profile[1][ignoreGapsInConsensusCalculation ? 1 : 0];
               mouseOver += ((p == 0) ? "" : "; ") + ((char[]) ca[c])[0]
-                      + " " + ((int) tval) + "%";
+                      + " " + ((fmt!=null) ? fmt.form(tval) : ((int) tval)) + "%";
               p++;
 
             }
@@ -298,7 +319,7 @@ public class AAFrequency
       }
       else
       {
-        mouseOver += ((int) value + "%");
+        mouseOver += ((fmt!=null) ? fmt.form(value) : ((int) value)) + "%";
       }
       consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
               value);
index 08bb3fd..948bdc1 100644 (file)
@@ -21,6 +21,7 @@ package jalview.analysis;
 
 import java.util.*;
 
+import jalview.util.Format;
 import jalview.datamodel.*;
 
 /**
@@ -299,7 +300,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
@@ -309,6 +310,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;
@@ -385,7 +398,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++;
 
           }
@@ -395,7 +408,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);
     }
   }
 
index cb700bc..32e9ad5 100644 (file)
@@ -191,7 +191,9 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
       ;
       for (JabaWsServerQuery squery : qrys)
       {
-        finished = finished && !squery.isRunning();
+        if (squery.isRunning()){
+          finished=false;
+        }
       }
       if (aborted)
       {