JAL-2629 revising hmmer annotation updating (wip)
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 9b4e1fe..ecca699 100644 (file)
@@ -22,6 +22,7 @@ package jalview.viewmodel;
 
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.analysis.Conservation;
+import jalview.analysis.TreeModel;
 import jalview.api.AlignCalcManagerI;
 import jalview.api.AlignViewportI;
 import jalview.api.AlignmentViewPanel;
@@ -33,7 +34,6 @@ import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.Annotation;
-import jalview.datamodel.CigarArray;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.HiddenSequences;
@@ -83,7 +83,7 @@ import java.util.Map;
 public abstract class AlignmentViewport
         implements AlignViewportI, CommandListener, VamsasSource
 {
-  final protected ViewportRanges ranges;
+  protected ViewportRanges ranges;
 
   protected ViewStyleI viewStyle = new ViewStyle();
 
@@ -99,11 +99,73 @@ public abstract class AlignmentViewport
 
   protected Deque<CommandI> redoList = new ArrayDeque<>();
 
+  protected String sequenceSetID;
+
+  /*
+   * 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;
+
+  public boolean autoCalculateInformation = 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;
+
+  protected List<AlignmentAnnotation> information = new ArrayList<>();
+
+  /**
+   * alignment displayed in the viewport
+   */
+  private AlignmentI alignment;
+
+  /**
+   * results of alignment consensus analysis for visible portion of view
+   */
+  protected ProfilesI hconsensus = null;
+
+  /**
+   * results of information annotation analysis for the visible portion of view
+   */
+  protected List<ProfilesI> hinformation = new ArrayList<>();
+
+  /**
+   * results of cDNA complement consensus visible portion of view
+   */
+  protected Hashtable[] hcomplementConsensus = null;
 
   /**
-   * alignment displayed in the viewport. Please use get/setter
+   * results of secondary structure base pair consensus for visible portion of
+   * view
    */
-  protected AlignmentI alignment;
+  protected Hashtable[] hStrucConsensus = null;
+
+  protected Conservation hconservation = null;
 
   public AlignmentViewport(AlignmentI al)
   {
@@ -584,14 +646,6 @@ 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;
@@ -602,24 +656,6 @@ public abstract class AlignmentViewport
     return isDataset;
   }
 
-  private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
-
-  protected ColumnSelection colSel = new ColumnSelection();
-
-  public boolean autoCalculateConsensus = true;
-
-  public boolean autoCalculateInformation = true;
-
-  protected boolean autoCalculateStrucConsensus = true;
-
-  protected boolean ignoreGapsInConsensusCalculation = false;
-
-  protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
-
-  protected boolean infoLetterHeight = false;
-
-  protected ResidueShaderI residueShading = new ResidueShader();
-
   @Override
   public void setGlobalColourScheme(ColourSchemeI cs)
   {
@@ -692,50 +728,6 @@ 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;
-
-  protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
-
-  protected List<AlignmentAnnotation> information = new ArrayList<>();
-
-  /**
-   * results of alignment consensus analysis for visible portion of view
-   */
-  protected ProfilesI hconsensus = null;
-
-  /**
-   * results of information annotation analysis for the visible portion of view
-   */
-  protected List<ProfilesI> hinformation = new ArrayList<>();
-
-  /**
-   * 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)
   {
@@ -844,15 +836,9 @@ public abstract class AlignmentViewport
   }
 
   @Override
-  public AlignmentAnnotation getInformationAnnotation(int index)
-  {
-    return information.get(index);
-  }
-
-  @Override
   public AlignmentAnnotation getAlignmentGapAnnotation()
   {
-    return gapcounts;
+    return occupancy;
   }
 
   @Override
@@ -1018,14 +1004,16 @@ public abstract class AlignmentViewport
     strucConsensus = null;
     conservation = null;
     quality = null;
-    groupConsensus = null;
-    groupConservation = null;
     hconsensus = null;
+    hconservation = null;
     hcomplementConsensus = null;
-    // colour scheme may hold reference to consensus
-    residueShading = null;
-    // TODO remove listeners from changeSupport?
+    occupancy = null;
+    calculator = null;
+    residueShading = null; // may hold a reference to Consensus
     changeSupport = null;
+    ranges = null;
+    currentTree = null;
+    selectionGroup = null;
     setAlignment(null);
   }
 
@@ -1493,7 +1481,10 @@ public abstract class AlignmentViewport
   public void removePropertyChangeListener(
           java.beans.PropertyChangeListener listener)
   {
-    changeSupport.removePropertyChangeListener(listener);
+    if (changeSupport != null)
+    {
+      changeSupport.removePropertyChangeListener(listener);
+    }
   }
 
   /**
@@ -1832,13 +1823,6 @@ public abstract class AlignmentViewport
   }
 
   @Override
-  public CigarArray getViewAsCigars(boolean selectedRegionOnly)
-  {
-    return new CigarArray(alignment, alignment.getHiddenColumns(),
-            (selectedRegionOnly ? selectionGroup : null));
-  }
-
-  @Override
   public jalview.datamodel.AlignmentView getAlignmentView(
           boolean selectedOnly)
   {
@@ -2023,7 +2007,7 @@ public abstract class AlignmentViewport
     updateInformation(ap);
 
     List<SequenceI> hmmSequences;
-    hmmSequences = alignment.getHMMConsensusSequences(false);
+    hmmSequences = alignment.getHMMConsensusSequences();
 
     for (SequenceI seq : hmmSequences)
     {
@@ -2105,7 +2089,7 @@ public abstract class AlignmentViewport
               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
       initConsensus(consensus);
 
-      initGapCounts();
+      initOccupancy();
 
       initComplementConsensus();
     }
@@ -2165,48 +2149,43 @@ public abstract class AlignmentViewport
   @Override
   public void initInformation()
   {
-    for (SequenceI seq : alignment.getHMMConsensusSequences(false))
+    for (SequenceI seq : alignment.getHMMConsensusSequences())
     {
       if (!seq.hasHMMAnnotation())
       {
-        AlignmentAnnotation information;
-        information = new AlignmentAnnotation(seq.getName(),
+        AlignmentAnnotation info = new AlignmentAnnotation(seq.getName(),
                 MessageManager.getString("label.information_description"),
                 new Annotation[1], 0f, 6.52f,
                 AlignmentAnnotation.BAR_GRAPH);
-        information.hasText = true;
-        information.autoCalculated = true;
-        information.hasText = true;
-        information.autoCalculated = false;
-        information.sequenceRef = seq;
-        information.setCalcId("HMM");
-        this.information.add(information);
+        info.hasText = true;
+        info.autoCalculated = false;
+        info.sequenceRef = seq;
+        info.setCalcId(InformationThread.HMM_CALC_ID);
+        this.information.add(info);
         hinformation.add(new Profiles(new ProfileI[1]));
-        alignment.addAnnotation(information);
+        alignment.addAnnotation(info);
         seq.updateHMMMapping();
-        seq.setHasInfo(true);
-        seq.addAlignmentAnnotation(information);
+        seq.addAlignmentAnnotation(info);
       }
     }
-
   }
 
   // these should be extracted from the view model - style and settings for
   // derived annotation
-  private void initGapCounts()
+  private void initOccupancy()
   {
     if (showOccupancy)
     {
-      gapcounts = new AlignmentAnnotation("Occupancy",
+      occupancy = new AlignmentAnnotation("Occupancy",
               MessageManager.getString("label.occupancy_descr"),
               new Annotation[1], 0f, alignment.getHeight(),
               AlignmentAnnotation.BAR_GRAPH);
-      gapcounts.hasText = true;
-      gapcounts.autoCalculated = true;
-      gapcounts.scaleColLabel = true;
-      gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
+      occupancy.hasText = true;
+      occupancy.autoCalculated = true;
+      occupancy.scaleColLabel = true;
+      occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
 
-      alignment.addAnnotation(gapcounts);
+      alignment.addAnnotation(occupancy);
     }
   }
 
@@ -3082,6 +3061,8 @@ public abstract class AlignmentViewport
    */
   private SearchResultsI searchResults = null;
 
+  protected TreeModel currentTree = null;
+
   @Override
   public boolean hasSearchResults()
   {
@@ -3154,4 +3135,15 @@ public abstract class AlignmentViewport
     return false;
   }
 
+  @Override
+  public void setCurrentTree(TreeModel tree)
+  {
+    currentTree = tree;
+  }
+
+  @Override
+  public TreeModel getCurrentTree()
+  {
+    return currentTree;
+  }
 }