JAL-3285 delete duplicate variables in AlignmentViewport from merge
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 0f46d5a..23c1d00 100644 (file)
@@ -98,47 +98,22 @@ public abstract class AlignmentViewport
 
   protected Deque<CommandI> redoList = new ArrayDeque<>();
 
-  protected String sequenceSetID;
-
+  /**
+   * alignment displayed in the viewport. Please use get/setter
+   */
+  protected AlignmentI alignment;
+  
   /*
    * probably unused indicator that view is of a dataset rather than an
    * alignment
    */
-  protected boolean isDataset = false;
-
-  private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
-
-  protected ColumnSelection colSel = new ColumnSelection();
-
-  public boolean autoCalculateConsensus = true;
-
-  protected boolean autoCalculateStrucConsensus = true;
-
-  protected boolean ignoreGapsInConsensusCalculation = false;
 
   protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
 
   protected boolean infoLetterHeight = false;
 
-  protected ResidueShaderI residueShading = new ResidueShader();
-
-  protected AlignmentAnnotation consensus;
-
-  protected AlignmentAnnotation complementConsensus;
-
   protected AlignmentAnnotation occupancy;
-
-  protected AlignmentAnnotation strucConsensus;
-
-  protected AlignmentAnnotation conservation;
-
-  protected AlignmentAnnotation quality;
-
-  /**
-   * alignment displayed in the viewport
-   */
-  private AlignmentI alignment;
-
+  
   /**
    * results of alignment consensus analysis for visible portion of view
    */
@@ -149,19 +124,6 @@ public abstract class AlignmentViewport
    */
   protected ProfilesI hmmProfiles;
 
-  /**
-   * results of cDNA complement consensus visible portion of view
-   */
-  protected Hashtable[] hcomplementConsensus;
-
-  /**
-   * results of secondary structure base pair consensus for visible portion of
-   * view
-   */
-  protected Hashtable[] hStrucConsensus;
-
-  protected Conservation hconservation;
-
   public AlignmentViewport(AlignmentI al)
   {
     setAlignment(al);
@@ -641,6 +603,14 @@ public abstract class AlignmentViewport
     return alignment.getGapCharacter();
   }
 
+  protected String sequenceSetID;
+
+  /**
+   * probably unused indicator that view is of a dataset rather than an
+   * alignment
+   */
+  protected boolean isDataset = false;
+  
   public void setDataset(boolean b)
   {
     isDataset = b;
@@ -651,6 +621,18 @@ public abstract class AlignmentViewport
     return isDataset;
   }
 
+  private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
+
+  protected ColumnSelection colSel = new ColumnSelection();
+
+  public boolean autoCalculateConsensus = true;
+
+  protected boolean autoCalculateStrucConsensus = true;
+
+  protected boolean ignoreGapsInConsensusCalculation = false;
+
+  protected ResidueShaderI residueShading = new ResidueShader();
+  
   @Override
   public void setGlobalColourScheme(ColourSchemeI cs)
   {
@@ -702,7 +684,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,
@@ -723,6 +706,41 @@ public abstract class AlignmentViewport
   {
     return residueShading;
   }
+  
+  protected AlignmentAnnotation consensus;
+
+  protected AlignmentAnnotation complementConsensus;
+
+  protected AlignmentAnnotation gapcounts;
+
+  protected AlignmentAnnotation strucConsensus;
+
+  protected AlignmentAnnotation conservation;
+
+  protected AlignmentAnnotation quality;
+
+  protected AlignmentAnnotation[] groupConsensus;
+
+  protected AlignmentAnnotation[] groupConservation;
+
+  /**
+   * results of alignment consensus analysis for visible portion of view
+   */
+  protected ProfilesI hconsensus = null;
+
+  /**
+   * results of cDNA complement consensus visible portion of view
+   */
+  protected Hashtable[] hcomplementConsensus = null;
+
+  /**
+   * results of secondary structure base pair consensus for visible portion of
+   * view
+   */
+  protected Hashtable[] hStrucConsensus = null;
+
+  protected Conservation hconservation = null;
+  
   @Override
   public void setConservation(Conservation cons)
   {
@@ -742,9 +760,9 @@ public abstract class AlignmentViewport
   }
 
   @Override
-  public void setConsensusProfiles(ProfilesI hconsensus)
+  public void setSequenceConsensusHash(ProfilesI hconsensus)
   {
-    this.consensusProfiles = hconsensus;
+    this.hconsensus = hconsensus;
   }
 
   @Override
@@ -754,9 +772,9 @@ public abstract class AlignmentViewport
   }
 
   @Override
-  public ProfilesI getConsensusProfiles()
+  public ProfilesI getSequenceConsensusHash()
   {
-    return consensusProfiles;
+    return hconsensus;
   }
 
   @Override
@@ -809,9 +827,9 @@ public abstract class AlignmentViewport
   }
 
   @Override
-  public AlignmentAnnotation getOccupancyAnnotation()
+  public AlignmentAnnotation getAlignmentGapAnnotation()
   {
-    return occupancy;
+    return gapcounts;
   }
 
   @Override
@@ -974,9 +992,12 @@ public abstract class AlignmentViewport
     conservation = null;
     quality = null;
     consensusProfiles = null;
+    groupConsensus = null;
+    groupConservation = null;
+    hconsensus = null;
     hconservation = null;
     hcomplementConsensus = null;
-    occupancy = null;
+    gapcounts = null;
     calculator = null;
     residueShading = null; // may hold a reference to Consensus
     changeSupport = null;
@@ -1028,17 +1049,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
@@ -1055,7 +1076,7 @@ public abstract class AlignmentViewport
   @Override
   public boolean isShowHMMSequenceLogo()
   {
-    return showHMMSequenceLogo;
+    return hmmShowSequenceLogo;
   }
 
   /**
@@ -1078,14 +1099,14 @@ public abstract class AlignmentViewport
 
   public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
   {
-    if (showHMMSequenceLogo != this.showHMMSequenceLogo)
+    if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
     {
-      this.showHMMSequenceLogo = showHMMSequenceLogo;
+      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;
   }
 
   /**
@@ -1099,11 +1120,10 @@ public abstract class AlignmentViewport
 
   /**
    * @param showInformationHistogram
-   *          the showInformationHistogram to set
    */
   public void setShowInformationHistogram(boolean showInformationHistogram)
   {
-    this.showInformationHistogram = showInformationHistogram;
+    this.hmmShowHistogram = showInformationHistogram;
   }
 
   /**
@@ -1159,7 +1179,7 @@ public abstract class AlignmentViewport
   @Override
   public boolean isShowInformationHistogram()
   {
-    return this.showInformationHistogram;
+    return this.hmmShowHistogram;
   }
 
   /**
@@ -1311,6 +1331,7 @@ public abstract class AlignmentViewport
     ignoreGapsInConsensusCalculation = b;
     if (ap != null)
     {
+      updateConsensus(ap);
       if (residueShading != null)
       {
         residueShading.setThreshold(residueShading.getThreshold(),
@@ -1737,6 +1758,7 @@ public abstract class AlignmentViewport
   public void invertColumnSelection()
   {
     colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
+    isColSelChanged(true);
   }
 
   @Override
@@ -1954,20 +1976,18 @@ public abstract class AlignmentViewport
     {
       alignment.padGaps();
     }
-    // if (autoCalculateConsensus)
-    // {
-    // updateConsensus(ap);
-    // }
-    // if (consensusProfiles != null && autoCalculateConsensus)
-    // {
-    // updateConservation(ap);
-    // }
-    // if (autoCalculateStrucConsensus)
-    // {
-    // updateStrucConsensus(ap);
-    // }
-    //
-    // updateInformation(ap);
+    if (autoCalculateConsensus)
+    {
+      updateConsensus(ap);
+    }
+    if (hconsensus != null && autoCalculateConsensus)
+    {
+      updateConservation(ap);
+    }
+    if (autoCalculateStrucConsensus)
+    {
+      updateStrucConsensus(ap);
+    }
 
     // Reset endRes of groups if beyond alignment width
     int alWidth = alignment.getWidth();
@@ -2002,7 +2022,7 @@ public abstract class AlignmentViewport
     {
       rs.alignmentChanged(alignment, hiddenRepSequences);
 
-      rs.setConsensus(consensusProfiles);
+      rs.setConsensus(hconsensus);
       if (rs.conservationApplied())
       {
         rs.setConservation(Conservation.calculateConservation("All",
@@ -2027,7 +2047,7 @@ public abstract class AlignmentViewport
     // depending on if the user wants to see the annotation or not in a
     // specific alignment
 
-    if (consensusProfiles == null && !isDataset)
+    if (hconsensus == null && !isDataset)
     {
       if (!alignment.isNucleotide())
       {
@@ -2043,7 +2063,7 @@ public abstract class AlignmentViewport
               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
       initConsensus(consensus);
 
-      initOccupancy();
+      initGapCounts();
 
       initComplementConsensus();
     }
@@ -2102,20 +2122,20 @@ public abstract class AlignmentViewport
 
   // these should be extracted from the view model - style and settings for
   // derived annotation
-  private void initOccupancy()
+  private void initGapCounts()
   {
     if (showOccupancy)
     {
-      occupancy = new AlignmentAnnotation("Occupancy",
+      gapcounts = new AlignmentAnnotation("Occupancy",
               MessageManager.getString("label.occupancy_descr"),
               new Annotation[1], 0f, alignment.getHeight(),
               AlignmentAnnotation.BAR_GRAPH);
-      occupancy.hasText = true;
-      occupancy.autoCalculated = true;
-      occupancy.scaleColLabel = true;
-      occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
+      gapcounts.hasText = true;
+      gapcounts.autoCalculated = true;
+      gapcounts.scaleColLabel = true;
+      gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
 
-      alignment.addAnnotation(occupancy);
+      alignment.addAnnotation(gapcounts);
     }
   }
 
@@ -2289,7 +2309,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);
         }
@@ -3091,11 +3111,75 @@ public abstract class AlignmentViewport
   @Override
   public boolean isNormaliseHMMSequenceLogo()
   {
-    return normaliseHMMSequenceLogo;
+    return hmmNormaliseSequenceLogo;
   }
 
   public void setNormaliseHMMSequenceLogo(boolean state)
   {
-    normaliseHMMSequenceLogo = 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);
+    }
   }
 }