Merge remote-tracking branch 'origin/releases/Release_2_10_2_Branch' into features...
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index aa3a22d..0ec07c0 100644 (file)
@@ -36,7 +36,6 @@ import jalview.datamodel.Annotation;
 import jalview.datamodel.CigarArray;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
-import jalview.datamodel.HiddenMarkovModel;
 import jalview.datamodel.HiddenSequences;
 import jalview.datamodel.ProfileI;
 import jalview.datamodel.Profiles;
@@ -100,7 +99,6 @@ public abstract class AlignmentViewport
 
   protected Deque<CommandI> redoList = new ArrayDeque<>();
 
-  HiddenMarkovModel selectedHMM;
 
   /**
    * alignment displayed in the viewport. Please use get/setter
@@ -411,6 +409,7 @@ public abstract class AlignmentViewport
   public void setWrapAlignment(boolean state)
   {
     viewStyle.setWrapAlignment(state);
+    ranges.setWrappedMode(state);
   }
 
   /**
@@ -650,6 +649,11 @@ public abstract class AlignmentViewport
       {
         residueShading.setConservation(hconservation);
       }
+      /*
+       * reset conservation flag in case just set to false if
+       * Conservation was null (calculation still in progress)
+       */
+      residueShading.setConservationApplied(getConservationSelected());
       residueShading.alignmentChanged(alignment, hiddenRepSequences);
     }
 
@@ -712,6 +716,9 @@ public abstract class AlignmentViewport
    */
   protected ProfilesI hconsensus = null;
 
+  /**
+   * results of information annotation analysis for the visible portion of view
+   */
   protected List<ProfilesI> hinformation = new ArrayList<>();
 
   /**
@@ -1278,7 +1285,7 @@ public abstract class AlignmentViewport
   @Override
   public boolean hasHiddenColumns()
   {
-    return colSel != null
+    return alignment.getHiddenColumns() != null
             && alignment.getHiddenColumns().hasHiddenColumns();
   }
 
@@ -1525,6 +1532,9 @@ public abstract class AlignmentViewport
   // common hide/show seq stuff
   public void showAllHiddenSeqs()
   {
+    int startSeq = ranges.getStartSeq();
+    int endSeq = ranges.getEndSeq();
+
     if (alignment.getHiddenSequences().getSize() > 0)
     {
       if (selectionGroup == null)
@@ -1542,6 +1552,8 @@ public abstract class AlignmentViewport
 
       hiddenRepSequences = null;
 
+      ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
+
       firePropertyChange("alignment", null, alignment.getSequences());
       // used to set hasHiddenRows/hiddenRepSequences here, after the property
       // changed event
@@ -1551,6 +1563,9 @@ public abstract class AlignmentViewport
 
   public void showSequence(int index)
   {
+    int startSeq = ranges.getStartSeq();
+    int endSeq = ranges.getEndSeq();
+
     List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
             hiddenRepSequences);
     if (tmp.size() > 0)
@@ -1566,6 +1581,9 @@ public abstract class AlignmentViewport
         selectionGroup.addSequence(seq, false);
         setSequenceAnnotationsVisible(seq, true);
       }
+
+      ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
+
       firePropertyChange("alignment", null, alignment.getSequences());
       sendSelection();
     }
@@ -1587,6 +1605,11 @@ public abstract class AlignmentViewport
 
   public void hideSequence(SequenceI[] seq)
   {
+    /*
+     * cache offset to first visible sequence
+     */
+    int startSeq = ranges.getStartSeq();
+
     if (seq != null)
     {
       for (int i = 0; i < seq.length; i++)
@@ -1594,6 +1617,7 @@ public abstract class AlignmentViewport
         alignment.getHiddenSequences().hideSequence(seq[i]);
         setSequenceAnnotationsVisible(seq[i], false);
       }
+      ranges.setStartSeq(startSeq);
       firePropertyChange("alignment", null, alignment.getSequences());
     }
   }
@@ -1804,7 +1828,8 @@ public abstract class AlignmentViewport
           boolean selectedOnly, boolean markGroups)
   {
     return new AlignmentView(alignment, alignment.getHiddenColumns(),
-            selectionGroup, alignment.getHiddenColumns() != null
+            selectionGroup,
+            alignment.getHiddenColumns() != null
                     && alignment.getHiddenColumns().hasHiddenColumns(),
             selectedOnly, markGroups);
   }
@@ -3053,23 +3078,43 @@ public abstract class AlignmentViewport
   }
 
   /**
-   * Gets the selected hidden Markov model
+   * get the consensus sequence as displayed under the PID consensus annotation
+   * row.
    * 
-   * @return
+   * @return consensus sequence as a new sequence object
    */
-  public HiddenMarkovModel getSelectedHMM()
+  public SequenceI getConsensusSeq()
   {
-    return selectedHMM;
-  }
+    if (consensus == null)
+    {
+      updateConsensus(null);
+    }
+    if (consensus == null)
+    {
+      return null;
+    }
+    StringBuffer seqs = new StringBuffer();
+    for (int i = 0; i < consensus.annotations.length; i++)
+    {
+      Annotation annotation = consensus.annotations[i];
+      if (annotation != null)
+      {
+        String description = annotation.description;
+        if (description != null && description.startsWith("["))
+        {
+          // consensus is a tie - just pick the first one
+          seqs.append(description.charAt(1));
+        }
+        else
+        {
+          seqs.append(annotation.displayCharacter);
+        }
+      }
+    }
 
-  /**
-   * Sets the selected hidden Markov model
-   * 
-   * @param selectedHMM
-   */
-  public void setSelectedHMM(HiddenMarkovModel selectedHMM)
-  {
-    this.selectedHMM = selectedHMM;
+    SequenceI sq = new Sequence("Consensus", seqs.toString());
+    sq.setDescription("Percentage Identity Consensus "
+            + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
+    return sq;
   }
-
 }