Merge branch 'develop' into developtomchmmer
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 58dba9d..39a1c18 100644 (file)
@@ -68,6 +68,7 @@ import java.util.BitSet;
 import java.util.Deque;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -701,7 +702,8 @@ public abstract class AlignmentViewport
          * retain any colour thresholds per group while
          * changing choice of colour scheme (JAL-2386)
          */
-        sg.setColourScheme(cs);
+        sg.setColourScheme(
+                cs == null ? null : cs.getInstance(this, sg));
         if (cs != null)
         {
           sg.getGroupColourScheme().alignmentChanged(sg,
@@ -899,18 +901,14 @@ public abstract class AlignmentViewport
     }
   }
 
-  /**
-   * trigger update of information annotation
-   */
   @Override
-  public void updateInformation(final AlignmentViewPanel ap)
+  public void initInformationWorker(final AlignmentViewPanel ap)
   {
     if (calculator
             .getRegisteredWorkersOfClass(InformationThread.class) == null)
     {
       calculator.registerWorker(new InformationThread(this, ap));
     }
-
   }
 
   // --------START Structure Conservation
@@ -1031,17 +1029,17 @@ public abstract class AlignmentViewport
   /**
    * should hmm profile be rendered by default
    */
-  protected boolean showHMMSequenceLogo = false;
+  protected boolean hmmShowSequenceLogo = false;
 
   /**
    * should hmm profile be rendered normalised to row height
    */
-  protected boolean normaliseHMMSequenceLogo = false;
+  protected boolean hmmNormaliseSequenceLogo = false;
 
   /**
    * should information histograms be rendered by default
    */
-  protected boolean showInformationHistogram = true;
+  protected boolean hmmShowHistogram = true;
 
   /**
    * @return the showConsensusProfile
@@ -1058,7 +1056,7 @@ public abstract class AlignmentViewport
   @Override
   public boolean isShowHMMSequenceLogo()
   {
-    return showHMMSequenceLogo;
+    return hmmShowSequenceLogo;
   }
 
   /**
@@ -1081,12 +1079,14 @@ public abstract class AlignmentViewport
 
   public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
   {
-    if (showHMMSequenceLogo != this.showHMMSequenceLogo)
+    if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
     {
-      this.showHMMSequenceLogo = showHMMSequenceLogo;
-      calculator.updateAnnotationFor(InformationThread.class);
+      this.hmmShowSequenceLogo = showHMMSequenceLogo;
+      // TODO: updateAnnotation if description (tooltip) will show
+      // profile in place of information content?
+      // calculator.updateAnnotationFor(InformationThread.class);
     }
-    this.showHMMSequenceLogo = showHMMSequenceLogo;
+    this.hmmShowSequenceLogo = showHMMSequenceLogo;
   }
 
   /**
@@ -1100,11 +1100,10 @@ public abstract class AlignmentViewport
 
   /**
    * @param showInformationHistogram
-   *          the showInformationHistogram to set
    */
   public void setShowInformationHistogram(boolean showInformationHistogram)
   {
-    this.showInformationHistogram = showInformationHistogram;
+    this.hmmShowHistogram = showInformationHistogram;
   }
 
   /**
@@ -1160,7 +1159,7 @@ public abstract class AlignmentViewport
   @Override
   public boolean isShowInformationHistogram()
   {
-    return this.showInformationHistogram;
+    return this.hmmShowHistogram;
   }
 
   /**
@@ -1312,7 +1311,6 @@ public abstract class AlignmentViewport
     ignoreGapsInConsensusCalculation = b;
     if (ap != null)
     {
-      updateConsensus(ap);
       if (residueShading != null)
       {
         residueShading.setThreshold(residueShading.getThreshold(),
@@ -1323,22 +1321,12 @@ public abstract class AlignmentViewport
 
   public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
   {
-    boolean was = ignoreBelowBackGroundFrequencyCalculation;
     ignoreBelowBackGroundFrequencyCalculation = b;
-    if (ap != null && was != b)
-    {
-      updateInformation(ap);
-    }
   }
 
   public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
   {
-    boolean was = infoLetterHeight;
     infoLetterHeight = b;
-    if (ap != null && was != b)
-    {
-      updateInformation(ap);
-    }
   }
 
   private long sgrouphash = -1, colselhash = -1;
@@ -1749,6 +1737,7 @@ public abstract class AlignmentViewport
   public void invertColumnSelection()
   {
     colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
+    isColSelChanged(true);
   }
 
   @Override
@@ -1772,7 +1761,8 @@ public abstract class AlignmentViewport
     }
     else
     {
-      sequences = selectionGroup.getSelectionAsNewSequences(alignment);
+      sequences = selectionGroup.getSelectionAsNewSequences(alignment,
+              true);
     }
 
     return sequences;
@@ -1854,8 +1844,12 @@ public abstract class AlignmentViewport
     if (alignment.getHiddenColumns() != null
             && alignment.getHiddenColumns().hasHiddenColumns())
     {
-      selection = alignment.getHiddenColumns()
-              .getVisibleSequenceStrings(start, end, seqs);
+      for (i = 0; i < iSize; i++)
+      {
+        Iterator<int[]> blocks = alignment.getHiddenColumns()
+                .getVisContigsIterator(start, end + 1, false);
+        selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
+      }
     }
     else
     {
@@ -1882,10 +1876,10 @@ public abstract class AlignmentViewport
       {
         if (start == 0)
         {
-          start = hidden.adjustForHiddenColumns(start);
+          start = hidden.visibleToAbsoluteColumn(start);
         }
 
-        end = hidden.getHiddenBoundaryRight(start);
+        end = hidden.getNextHiddenBoundary(false, start);
         if (start == end)
         {
           end = max;
@@ -1900,8 +1894,8 @@ public abstract class AlignmentViewport
 
       if (hidden != null && hidden.hasHiddenColumns())
       {
-        start = hidden.adjustForHiddenColumns(end);
-        start = hidden.getHiddenBoundaryLeft(start) + 1;
+        start = hidden.visibleToAbsoluteColumn(end);
+        start = hidden.getNextHiddenBoundary(true, start) + 1;
       }
     } while (end < max);
 
@@ -1923,13 +1917,13 @@ public abstract class AlignmentViewport
         AlignmentAnnotation clone = new AlignmentAnnotation(annot);
         if (selectedOnly && selectionGroup != null)
         {
-          alignment.getHiddenColumns().makeVisibleAnnotation(
+          clone.makeVisibleAnnotation(
                   selectionGroup.getStartRes(), selectionGroup.getEndRes(),
-                  clone);
+                  alignment.getHiddenColumns());
         }
         else
         {
-          alignment.getHiddenColumns().makeVisibleAnnotation(clone);
+          clone.makeVisibleAnnotation(alignment.getHiddenColumns());
         }
         ala.add(clone);
       }
@@ -1962,20 +1956,6 @@ public abstract class AlignmentViewport
     {
       alignment.padGaps();
     }
-    if (autoCalculateConsensus)
-    {
-      updateConsensus(ap);
-    }
-    if (consensusProfiles != null && autoCalculateConsensus)
-    {
-      updateConservation(ap);
-    }
-    if (autoCalculateStrucConsensus)
-    {
-      updateStrucConsensus(ap);
-    }
-    // initInformation();
-    updateInformation(ap);
 
     // Reset endRes of groups if beyond alignment width
     int alWidth = alignment.getWidth();
@@ -1998,7 +1978,6 @@ public abstract class AlignmentViewport
 
     updateAllColourSchemes();
     calculator.restartWorkers();
-    // alignment.adjustSequenceAnnotations();
   }
 
   /**
@@ -2298,7 +2277,7 @@ public abstract class AlignmentViewport
           sg.setshowSequenceLogo(showprf);
           sg.setShowConsensusHistogram(showConsHist);
           sg.setNormaliseSequenceLogo(normLogo);
-          sg.setshowHMMSequenceLogo(showHMMPrf);
+          sg.setShowHMMSequenceLogo(showHMMPrf);
           sg.setShowInformationHistogram(showInfoHist);
           sg.setNormaliseHMMSequenceLogo(normHMMLogo);
         }
@@ -2904,7 +2883,7 @@ public abstract class AlignmentViewport
     int lastSeq = alignment.getHeight() - 1;
     List<AlignedCodonFrame> seqMappings = null;
     for (int seqNo = ranges
-            .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
+            .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
     {
       sequence = getAlignment().getSequenceAt(seqNo);
       if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
@@ -3085,4 +3064,90 @@ public abstract class AlignmentViewport
   {
     return currentTree;
   }
+
+  @Override
+  public boolean isNormaliseSequenceLogo()
+  {
+    return normaliseSequenceLogo;
+  }
+
+  public void setNormaliseSequenceLogo(boolean state)
+  {
+    normaliseSequenceLogo = state;
+  }
+
+  @Override
+  public boolean isNormaliseHMMSequenceLogo()
+  {
+    return hmmNormaliseSequenceLogo;
+  }
+
+  public void setNormaliseHMMSequenceLogo(boolean state)
+  {
+    hmmNormaliseSequenceLogo = state;
+  }
+
+  /**
+   * flag set to indicate if structure views might be out of sync with sequences
+   * in the alignment
+   */
+
+  private boolean needToUpdateStructureViews = false;
+
+  @Override
+  public boolean isUpdateStructures()
+  {
+    return needToUpdateStructureViews;
+  }
+
+  @Override
+  public void setUpdateStructures(boolean update)
+  {
+    needToUpdateStructureViews = update;
+  }
+
+  @Override
+  public boolean needToUpdateStructureViews()
+  {
+    boolean update = needToUpdateStructureViews;
+    needToUpdateStructureViews = false;
+    return update;
+  }
+
+  @Override
+  public void addSequenceGroup(SequenceGroup sequenceGroup)
+  {
+    alignment.addGroup(sequenceGroup);
+
+    Color col = sequenceGroup.idColour;
+    if (col != null)
+    {
+      col = col.brighter();
+
+      for (SequenceI sq : sequenceGroup.getSequences())
+      {
+        setSequenceColour(sq, col);
+      }
+    }
+
+    if (codingComplement != null)
+    {
+      SequenceGroup mappedGroup = MappingUtils
+              .mapSequenceGroup(sequenceGroup, this, codingComplement);
+      if (mappedGroup.getSequences().size() > 0)
+      {
+        codingComplement.getAlignment().addGroup(mappedGroup);
+
+        if (col != null)
+        {
+          for (SequenceI seq : mappedGroup.getSequences())
+          {
+            codingComplement.setSequenceColour(seq, col);
+          }
+        }
+      }
+      // propagate the structure view update flag according to our own setting
+      codingComplement.setUpdateStructures(needToUpdateStructureViews);
+    }
+  }
 }