Merge branch 'develop' into bug/JAL-98consensusMemory
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 6 Oct 2016 12:55:50 +0000 (13:55 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 6 Oct 2016 12:55:50 +0000 (13:55 +0100)
1  2 
src/jalview/analysis/Conservation.java
src/jalview/api/AlignViewportI.java
src/jalview/renderer/AnnotationRenderer.java
src/jalview/viewmodel/AlignmentViewport.java

@@@ -24,13 -24,12 +24,13 @@@ import jalview.datamodel.AlignmentAnnot
  import jalview.datamodel.Annotation;
  import jalview.datamodel.Sequence;
  import jalview.datamodel.SequenceI;
 +import jalview.ext.android.SparseIntArray;
  import jalview.schemes.ResidueProperties;
  
  import java.awt.Color;
 -import java.util.Hashtable;
  import java.util.List;
  import java.util.Map;
 +import java.util.TreeMap;
  import java.util.Vector;
  
  /**
@@@ -189,22 -188,21 +189,22 @@@ public class Conservatio
     */
    public void calculate()
    {
 -    int thresh, j, jSize = sequences.length;
 -    int[] values; // Replaces residueHash
 -    char c;
 +    int jSize = sequences.length;
 +    // int[] values; // Replaces residueHash
 +    SparseIntArray values = new SparseIntArray();
  
 -    total = new Hashtable[maxLength];
 +    total = new Map[maxLength];
  
      for (int i = start; i <= end; i++)
      {
 -      values = new int[255];
 +      // values = new int[255];
 +      values.clear();
  
 -      for (j = 0; j < jSize; j++)
 +      for (int j = 0; j < jSize; j++)
        {
          if (sequences[j].getLength() > i)
          {
 -          c = sequences[j].getCharAt(i);
 +          char c = sequences[j].getCharAt(i);
  
            if (canonicaliseAa)
            { // lookup the base aa code symbol
  
              c = toUpperCase(c);
            }
 -          values[c]++;
 +          // values[c]++;
 +          values.add(c, 1);
          }
          else
          {
 -          values['-']++;
 +          // values['-']++;
 +          values.add('-', 1);
          }
        }
  
        // What is the count threshold to count the residues in residueHash()
 -      thresh = (threshold * (jSize)) / 100;
 +      int thresh = (threshold * jSize) / 100;
  
        // loop over all the found residues
 -      Hashtable<String, Integer> resultHash = new Hashtable<String, Integer>();
 -      for (char v = '-'; v < 'Z'; v++)
 +      // Hashtable<String, Integer> resultHash = new Hashtable<String,
 +      // Integer>();
 +      Map<String, Integer> resultHash = new TreeMap<String, Integer>();
 +      // for (char v = '-'; v < 'Z'; v++)
 +      for (int key = 0; key < values.size(); key++)
        {
 -
 -        if (values[v] > thresh)
 +        char v = (char) values.keyAt(key);
 +        // if (values[v] > thresh)
 +        if (values.valueAt(key) > thresh)
          {
            String res = String.valueOf(v);
  
     */
    public void verdict(boolean consflag, float percentageGaps)
    {
 -    StringBuffer consString = new StringBuffer();
 +    StringBuilder consString = new StringBuilder(end);
  
      // NOTE THIS SHOULD CHECK IF THE CONSEQUENCE ALREADY
      // EXISTS AND NOT OVERWRITE WITH '-', BUT THIS CASE
        int[] gapcons = countConsNGaps(i);
        int totGaps = gapcons[1];
        float pgaps = ((float) totGaps * 100) / sequences.length;
 -      consSymbs[i - start] = new String();
 +      StringBuilder positives = new StringBuilder(64);
 +      StringBuilder negatives = new StringBuilder(32);
 +      // consSymbs[i - start] = "";
  
        if (percentageGaps > pgaps)
        {
            {
              if (result == 1)
              {
 -              consSymbs[i - start] = type + " " + consSymbs[i - start];
 +              // consSymbs[i - start] = type + " " + consSymbs[i - start];
 +              positives.append(positives.length() == 0 ? "" : " ");
 +              positives.append(type);
                count++;
              }
            }
              {
                if (result == 0)
                {
 -                consSymbs[i - start] = consSymbs[i - start] + " !" + type;
 +                /*
 +                 * add negatively conserved properties on the end
 +                 */
 +                // consSymbs[i - start] = consSymbs[i - start] + " !" + type;
 +                negatives.append(negatives.length() == 0 ? "" : " ");
 +                negatives.append("!").append(type);
                }
                else
                {
 -                consSymbs[i - start] = type + " " + consSymbs[i - start];
 +                /*
 +                 * put positively conserved properties on the front
 +                 */
 +                // consSymbs[i - start] = type + " " + consSymbs[i - start];
 +                positives.append(positives.length() == 0 ? "" : " ");
 +                positives.append(type);
                }
                count++;
              }
            }
          }
 +        if (negatives.length() > 0)
 +        {
 +          positives.append(" ").append(negatives);
 +        }
 +        consSymbs[i - start] = positives.toString();
  
          if (count < 10)
          {
        {
          tot = 0;
          xx = new double[24];
-         seqNum = (j < lengths[k]) ? seqNums.elementAt(k)[j + 1]
-                 : 23; // Sequence, or gap at the end
+         seqNum = (j < lengths[k]) ? seqNums.elementAt(k)[j + 1] : 23; // Sequence,
+                                                                       // or gap
+                                                                       // at the
+                                                                       // end
  
          // This is a loop over r
          for (i = 0; i < 23; i++)
      Conservation cons = new Conservation(name, threshold, seqs, start, end);
      cons.calculate();
      cons.verdict(posOrNeg, consPercGaps);
-     
      if (calcQuality)
      {
        cons.findQuality();
      }
-     
      return cons;
    }
  }
@@@ -21,7 -21,6 +21,7 @@@
  package jalview.api;
  
  import jalview.analysis.Conservation;
 +import jalview.analysis.Profile;
  import jalview.datamodel.AlignmentAnnotation;
  import jalview.datamodel.AlignmentI;
  import jalview.datamodel.AlignmentView;
@@@ -82,7 -81,7 +82,7 @@@ public interface AlignViewportI extend
  
    ColumnSelection getColumnSelection();
  
 -  Hashtable[] getSequenceConsensusHash();
 +  Profile[] getSequenceConsensusHash();
  
    /**
     * Get consensus data table for the cDNA complement of this alignment (if any)
     * 
     * @param hconsensus
     */
 -  void setSequenceConsensusHash(Hashtable[] hconsensus);
 +  void setSequenceConsensusHash(Profile[] hconsensus);
  
    /**
     * Set the cDNA complement consensus for the viewport
     * @return String[]
     */
    String[] getViewAsString(boolean selectedRegionOnly);
-   
    /**
     * This method returns the visible alignment as text, as seen on the GUI, ie
     * if columns are hidden they will not be returned in the result. Use this for
     * 
     * @return String[]
     */
-   String[] getViewAsString(boolean selectedRegionOnly, boolean isExportHiddenSeqs);
+   String[] getViewAsString(boolean selectedRegionOnly,
+           boolean isExportHiddenSeqs);
  
    void setSelectionGroup(SequenceGroup sg);
  
     */
    void setFollowHighlight(boolean b);
  
    public void applyFeaturesStyle(FeatureSettingsModelI featureSettings);
  
    /**
@@@ -22,7 -22,6 +22,7 @@@ package jalview.renderer
  
  import jalview.analysis.AAFrequency;
  import jalview.analysis.CodingUtils;
 +import jalview.analysis.Profile;
  import jalview.analysis.Rna;
  import jalview.analysis.StructureFrequency;
  import jalview.api.AlignViewportI;
@@@ -74,7 -73,7 +74,7 @@@ public class AnnotationRendere
  
    private ColumnSelection columnSelection;
  
 -  private Hashtable[] hconsensus;
 +  private Profile[] hconsensus;
  
    private Hashtable[] complementConsensus;
  
      annotationPanel = null;
    }
  
-   void drawStemAnnot(Graphics g, Annotation[] row_annotations,
-           int lastSSX, int x, int y, int iconOffset, int startRes,
-           int column, boolean validRes, boolean validEnd)
+   void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
+           int x, int y, int iconOffset, int startRes, int column,
+           boolean validRes, boolean validEnd)
    {
      g.setColor(STEM_COLOUR);
      int sCol = (lastSSX / charWidth) + startRes;
  
    private Color sdNOTCANONICAL_COLOUR;
  
-   void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX,
-           int x, int y, int iconOffset, int startRes, int column,
+   void drawGlyphLine(Graphics g, Annotation[] row, int lastSSX, int x,
+           int y, int iconOffset, int startRes, int column,
            boolean validRes, boolean validEnd)
    {
      g.setColor(GLYPHLINE_COLOR);
  
    }
  
-   void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX,
-           int x, int y, int iconOffset, int startRes, int column,
+   void drawHelixAnnot(Graphics g, Annotation[] row, int lastSSX, int x,
+           int y, int iconOffset, int startRes, int column,
            boolean validRes, boolean validEnd)
    {
      g.setColor(HELIX_COLOUR);
@@@ -22,7 -22,6 +22,7 @@@ package jalview.viewmodel
  
  import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
  import jalview.analysis.Conservation;
 +import jalview.analysis.Profile;
  import jalview.api.AlignCalcManagerI;
  import jalview.api.AlignViewportI;
  import jalview.api.AlignmentViewPanel;
@@@ -700,7 -699,7 +700,7 @@@ public abstract class AlignmentViewpor
    /**
     * results of alignment consensus analysis for visible portion of view
     */
 -  protected Hashtable[] hconsensus = null;
 +  protected Profile[] hconsensus = null;
  
    /**
     * results of cDNA complement consensus visible portion of view
    }
  
    @Override
 -  public void setSequenceConsensusHash(Hashtable[] hconsensus)
 +  public void setSequenceConsensusHash(Profile[] hconsensus)
    {
      this.hconsensus = hconsensus;
    }
    }
  
    @Override
 -  public Hashtable[] getSequenceConsensusHash()
 +  public Profile[] getSequenceConsensusHash()
    {
      return hconsensus;
    }
    public boolean isHiddenRepSequence(SequenceI seq)
    {
      return (hiddenRepSequences != null && hiddenRepSequences
-                     .containsKey(seq));
+             .containsKey(seq));
    }
  
    /**
    public void expandColSelection(SequenceGroup sg, boolean wholewidth)
    {
      int sgs, sge;
-     if (sg != null
-             && (sgs = sg.getStartRes()) >= 0
+     if (sg != null && (sgs = sg.getStartRes()) >= 0
              && sg.getStartRes() <= (sge = sg.getEndRes())
              && !this.hasSelectedColumns())
      {