Merge branch 'features/JAL-1933_occupancy' into develop
authorJim Procter <jprocter@issues.jalview.org>
Thu, 27 Apr 2017 14:05:42 +0000 (15:05 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 27 Apr 2017 14:05:42 +0000 (15:05 +0100)
resources/lang/Messages.properties
src/jalview/analysis/AAFrequency.java
src/jalview/appletgui/AnnotationColumnChooser.java
src/jalview/appletgui/AnnotationRowFilter.java
src/jalview/gui/AnnotationColumnChooser.java
src/jalview/gui/AnnotationRowFilter.java
src/jalview/viewmodel/AlignmentViewport.java

index 4ebca62..cc52620 100644 (file)
@@ -908,6 +908,7 @@ label.webservice_job_title_on = {0} using {1} on {2}
 label.updating_vamsas_session = Updating vamsas session
 label.loading_file = Loading File: {0}
 label.edit_params = Edit {0}
+label.as_percentage = As Percentage
 error.not_implemented = Not implemented
 error.no_such_method_as_clone1_for = No such method as clone1 for {0}
 error.null_from_clone1 = Null from clone1!
index ee16f94..3636b5e 100755 (executable)
  */
 package jalview.analysis;
 
-import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.List;
-
 import jalview.datamodel.AlignedCodonFrame;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -41,6 +37,11 @@ import jalview.util.Format;
 import jalview.util.MappingUtils;
 import jalview.util.QuickSort;
 
+import java.awt.Color;
+import java.util.Arrays;
+import java.util.Hashtable;
+import java.util.List;
+
 /**
  * Takes in a vector or array of sequences and column start and column end and
  * returns a new Hashtable[] of size maxSeqLength, if Hashtable not supplied.
@@ -315,6 +316,7 @@ public class AAFrequency
     // always set ranges again
     gaprow.graphMax = nseq;
     gaprow.graphMin = 0;
+    double scale = 0.8/nseq;
     for (int i = startCol; i < endCol; i++)
     {
       ProfileI profile = profiles.get(i);
@@ -330,11 +332,11 @@ public class AAFrequency
 
       final int gapped = profile.getNonGapped();
 
-      String description = String.valueOf(gapped);
+      String description = "";
 
       gaprow.annotations[i] = new Annotation(description, description,
-              '\0',
-              gapped);
+              '\0', gapped, jalview.util.ColorUtils.bleachColour(
+                      Color.DARK_GRAY, (float) scale * gapped));
     }
   }
 
index a8dff62..bbd01f6 100644 (file)
@@ -204,6 +204,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
 
     thresholdValue.setEnabled(false);
     thresholdValue.setColumns(7);
+    thresholdValue.setCaretPosition(0);
 
     ok.addActionListener(this);
     cancel.addActionListener(this);
@@ -219,6 +220,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     // thresholdPanel.setFont(JvSwingUtils.getLabelFont());
     // thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
 
+    percentThreshold.setLabel("As percentage");
+    percentThreshold.addItemListener(this);
+
     actionPanel.setBackground(Color.white);
     // actionPanel.setFont(JvSwingUtils.getLabelFont());
 
@@ -239,6 +243,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     ngStructureFilterPanel = new StructureFilterPanel(this);
 
     thresholdPanel.setTitle("Threshold Filter");
+    thresholdPanel.add(percentThreshold);
     thresholdPanel.add(getThreshold());
     thresholdPanel.add(slider);
     thresholdPanel.add(thresholdValue);
@@ -425,7 +430,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
       slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
-      thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
+      setThresholdValueText();
       // slider.setMajorTickSpacing((int) (range / 10f));
       slider.setEnabled(true);
       thresholdValue.setEnabled(true);
@@ -574,6 +579,14 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     {
       threshold_actionPerformed(null);
     }
+    else if (e.getSource() == percentThreshold)
+    {
+      if (!adjusting)
+      {
+        percentageValue_actionPerformed();
+      }
+
+    }
   }
 
   public void selectedAnnotationChanged()
index 8d67d71..6ea0fed 100644 (file)
@@ -31,7 +31,6 @@ import java.awt.Panel;
 import java.awt.Scrollbar;
 import java.awt.TextField;
 import java.awt.event.ActionEvent;
-import java.util.Vector;
 
 @SuppressWarnings("serial")
 public abstract class AnnotationRowFilter extends Panel
@@ -60,6 +59,8 @@ public abstract class AnnotationRowFilter extends Panel
 
   protected Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
 
+  protected Checkbox percentThreshold = new Checkbox();
+
   protected TextField thresholdValue = new TextField(20);
 
   protected Frame frame;
@@ -132,18 +133,49 @@ public abstract class AnnotationRowFilter extends Panel
     updateView();
   }
 
+  protected void setThresholdValueText()
+  {
+    adjusting = true;
+    if (percentThreshold.getState())
+    {
+      double scl = slider.getMaximum() - slider.getMinimum();
+      scl = (slider.getValue() - slider.getMinimum()) / scl;
+      thresholdValue.setText(100 * scl + "");
+    }
+    else
+    {
+      thresholdValue.setText((slider.getValue() / 1000f) + "");
+    }
+    thresholdValue.setCaretPosition(0);
+    adjusting = false;
+  }
+  
   public void thresholdValue_actionPerformed(ActionEvent e)
   {
     try
     {
       float f = Float.parseFloat(thresholdValue.getText());
-      slider.setValue((int) (f * 1000));
+      if (percentThreshold.getState())
+      {
+        slider.setValue(slider.getMinimum()
+                + ((int) ((f / 100f) * (slider.getMaximum() - slider
+                        .getMinimum()))));
+      }
+      else
+      {
+        slider.setValue((int) (f * 1000));
+      }
       updateView();
     } catch (NumberFormatException ex)
     {
     }
   }
 
+  protected void percentageValue_actionPerformed()
+  {
+    setThresholdValueText();
+  }
+
   protected void populateThresholdComboBox(Choice threshold)
   {
     threshold.addItem(MessageManager
index 637eb30..c321e59 100644 (file)
@@ -151,6 +151,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     thresholdPanel.setFont(JvSwingUtils.getLabelFont());
     thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]"));
 
+    percentThreshold.setBackground(Color.white);
+    percentThreshold.setFont(JvSwingUtils.getLabelFont());
+
     JPanel actionPanel = new JPanel();
     actionPanel.setBackground(Color.white);
     actionPanel.setFont(JvSwingUtils.getLabelFont());
@@ -174,8 +177,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     ngStructureFilterPanel = new StructureFilterPanel(this);
 
     thresholdPanel.add(getThreshold());
-    thresholdPanel.add(thresholdValue, "wrap");
-    thresholdPanel.add(slider, "grow, span, wrap");
+    thresholdPanel.add(percentThreshold, "wrap");
+    thresholdPanel.add(slider, "grow");
+    thresholdPanel.add(thresholdValue, "span, wrap");
 
     actionPanel.add(ok);
     actionPanel.add(cancel);
@@ -282,12 +286,14 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
 
     slider.setEnabled(true);
     thresholdValue.setEnabled(true);
+    percentThreshold.setEnabled(true);
 
     if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
     {
       slider.setEnabled(false);
       thresholdValue.setEnabled(false);
       thresholdValue.setText("");
+      percentThreshold.setEnabled(false);
       // build filter params
     }
     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
@@ -308,7 +314,18 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
       slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
-      thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
+      
+      if (percentThreshold.isSelected())
+      {
+        thresholdValue
+                .setText(""
+                        + ((getCurrentAnnotation().threshold.value - getCurrentAnnotation().graphMin) * 100f / (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin)));
+      }
+      else
+      {
+        thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
+      }
+
       slider.setMajorTickSpacing((int) (range / 10f));
       slider.setEnabled(true);
       thresholdValue.setEnabled(true);
@@ -392,6 +409,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     ap.paintAlignment(true);
   }
 
+
   public ColumnSelection getOldColumnSelection()
   {
     return oldColumnSelection;
index c2bf41b..1035a6c 100644 (file)
@@ -62,6 +62,8 @@ public abstract class AnnotationRowFilter extends JPanel
 
   protected JCheckBox seqAssociated = new JCheckBox();
 
+  protected JCheckBox percentThreshold = new JCheckBox();
+
   protected JSlider slider = new JSlider();
 
   protected JTextField thresholdValue = new JTextField(20);
@@ -120,13 +122,27 @@ public abstract class AnnotationRowFilter extends JPanel
       {
         if (!adjusting)
         {
-          thresholdValue.setText((slider.getValue() / 1000f) + "");
+          setThresholdValueText();
           valueChanged(!sliderDragging);
         }
       }
     });
   }
 
+  protected void setThresholdValueText()
+  {
+    adjusting = true;
+    if (percentThreshold.isSelected())
+    {
+      thresholdValue.setText("" + (slider.getValue() - slider.getMinimum())
+              * 100f / (slider.getMaximum() - slider.getMinimum()));
+    }
+    else
+    {
+      thresholdValue.setText((slider.getValue() / 1000f) + "");
+    }
+    adjusting = false;
+  }
   protected void addSliderMouseListeners()
   {
 
@@ -275,13 +291,27 @@ public abstract class AnnotationRowFilter extends JPanel
     try
     {
       float f = Float.parseFloat(thresholdValue.getText());
-      slider.setValue((int) (f * 1000));
+      if (percentThreshold.isEnabled())
+      {
+        slider.setValue(slider.getMinimum()
+                + ((int) ((f / 100f) * (slider.getMaximum() - slider
+                        .getMinimum()))));
+      }
+      else
+      {
+        slider.setValue((int) (f * 1000));
+      }
       updateView();
     } catch (NumberFormatException ex)
     {
     }
   }
 
+  protected void percentageValue_actionPerformed()
+  {
+    setThresholdValueText();
+  }
+
   protected void thresholdIsMin_actionPerformed()
   {
     updateView();
@@ -439,6 +469,18 @@ public abstract class AnnotationRowFilter extends JPanel
       }
     });
 
+    percentThreshold.setText(MessageManager.getString("label.as_percentage"));
+    percentThreshold.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        if (!adjusting)
+        {
+          percentageValue_actionPerformed();
+        }
+      }
+    });
     slider.setPaintLabels(false);
     slider.setPaintTicks(true);
     slider.setBackground(Color.white);
index 47dceec..8d2580b 100644 (file)
@@ -1956,8 +1956,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
   // derived annotation
   private void initGapCounts(AlignmentAnnotation counts)
   {
-    counts.hasText = false;
+    counts.hasText = true;
     counts.autoCalculated = true;
+    counts.scaleColLabel = true;
     counts.graph = AlignmentAnnotation.BAR_GRAPH;
 
     if (showConsensus)