JAL-969 refactor columnselection operation (during JAL-2001)
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 3d807e2..b70e92b 100644 (file)
@@ -49,6 +49,7 @@ import jalview.structure.CommandListener;
 import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.util.Comparison;
+import jalview.util.MapList;
 import jalview.util.MappingUtils;
 import jalview.viewmodel.styles.ViewStyle;
 import jalview.workers.AlignCalcManager;
@@ -848,7 +849,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
        */
       AlignedCodonFrame mapping = al.getCodonFrames().iterator().next();
       // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
-      if (mapping.getdnaToProt()[0].getFromRatio() == 3)
+      MapList[] mapLists = mapping.getdnaToProt();
+      // mapLists can be empty if project load has not finished resolving seqs
+      if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
       {
         if (calculator
                 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
@@ -1203,7 +1206,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
    */
   public boolean isColSelChanged(boolean b)
   {
-    int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
+    int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel
             .hashCode();
     if (hc != -1 && hc != colselhash)
     {
@@ -1298,7 +1301,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
 
   public void hideSelectedColumns()
   {
-    if (colSel.size() < 1)
+    if (colSel.isEmpty())
     {
       return;
     }
@@ -1567,9 +1570,20 @@ public abstract class AlignmentViewport implements AlignViewportI,
     }
     else
     {
-      iSize = alignment.getHeight();
-      seqs = alignment.getSequencesArray();
-      end = alignment.getWidth();
+      if (hasHiddenRows())
+      {
+        iSize = alignment.getHiddenSequences().getFullAlignment()
+                .getHeight();
+        seqs = alignment.getHiddenSequences().getFullAlignment()
+                .getSequencesArray();
+        end = alignment.getHiddenSequences().getFullAlignment().getWidth();
+      }
+      else
+      {
+        iSize = alignment.getHeight();
+        seqs = alignment.getSequencesArray();
+        end = alignment.getWidth();
+      }
     }
 
     selection = new String[iSize];
@@ -1786,7 +1800,9 @@ public abstract class AlignmentViewport implements AlignViewportI,
         // fudge: check mappings are not protein-to-protein
         // TODO: nicer
         AlignedCodonFrame mapping = codonMappings.iterator().next();
-        if (mapping.getdnaToProt()[0].getFromRatio() == 3)
+        MapList[] mapLists = mapping.getdnaToProt();
+        // mapLists can be empty if project load has not finished resolving seqs
+        if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
         {
           complementConsensus = new AlignmentAnnotation("cDNA Consensus",
                   "PID for cDNA", new Annotation[1], 0f, 100f,
@@ -2104,7 +2120,7 @@ public abstract class AlignmentViewport implements AlignViewportI,
   public boolean areFeaturesDisplayed()
   {
     return featuresDisplayed != null
-            && featuresDisplayed.getRegisterdFeaturesCount() > 0;
+            && featuresDisplayed.getRegisteredFeaturesCount() > 0;
   }
 
   /**
@@ -2639,4 +2655,37 @@ public abstract class AlignmentViewport implements AlignViewportI,
             sequence.findPosition(middleColumn), mappings);
     return seqOffset;
   }
+
+  /**
+   * synthesize a column selection if none exists so it covers the given
+   * selection group. if wholewidth is false, no column selection is made if the
+   * selection group covers the whole alignment width.
+   * 
+   * @param sg
+   * @param wholewidth
+   */
+  public void expandColSelection(SequenceGroup sg, boolean wholewidth)
+  {
+    int sgs, sge;
+    if (sg != null
+            && (sgs = sg.getStartRes()) >= 0
+            && sg.getStartRes() <= (sge = sg.getEndRes())
+            && (colSel == null || colSel.getSelected() == null || colSel
+                    .getSelected().size() == 0))
+    {
+      if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
+      {
+        // do nothing
+        return;
+      }
+      if (colSel == null)
+      {
+        colSel = new ColumnSelection();
+      }
+      for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
+      {
+        colSel.addElement(cspos);
+      }
+    }
+  }
 }