JAL-3390 new View menu option to hide hidden regions in structure
[jalview.git] / src / jalview / ext / rbvi / chimera / ChimeraCommands.java
index ec94e7d..dc53c2b 100644 (file)
@@ -32,6 +32,7 @@ import jalview.renderer.seqfeatures.FeatureColourFinder;
 import jalview.structure.StructureMapping;
 import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
+import jalview.structures.models.AAStructureBindingModel;
 import jalview.util.ColorUtils;
 import jalview.util.Comparison;
 
@@ -68,11 +69,24 @@ public class ChimeraCommands
    */
   public static StructureMappingcommandSet[] getColourBySequenceCommand(
           StructureSelectionManager ssm, String[] files,
+          AAStructureBindingModel binding, AlignmentViewPanel viewPanel)
+  {
+    SequenceRenderer sr = binding.getSequenceRenderer(viewPanel);
+    SequenceI[][] sequence = binding.getSequence();
+    boolean hideHiddenRegions = binding.isShowAlignmentOnly()
+            && binding.isHideHiddenRegions();
+
+    return getColourBySequenceCommand(ssm, files, sequence, sr,
+            hideHiddenRegions, viewPanel);
+  }
+
+  static StructureMappingcommandSet[] getColourBySequenceCommand(
+          StructureSelectionManager ssm, String[] files,
           SequenceI[][] sequence, SequenceRenderer sr,
-          AlignmentViewPanel viewPanel)
+          boolean hideHiddenRegions, AlignmentViewPanel viewPanel)
   {
     Map<Object, AtomSpecModel> colourMap = buildColoursMap(ssm, files,
-            sequence, sr, viewPanel);
+            sequence, sr, hideHiddenRegions, viewPanel);
 
     List<String> colourCommands = buildColourCommands(colourMap);
 
@@ -175,20 +189,31 @@ public class ChimeraCommands
   }
 
   /**
-   * <pre>
-   * Build a data structure which records contiguous subsequences for each colour. 
+   * Build a data structure which records contiguous subsequences for each colour.
    * From this we can easily generate the Chimera command for colour by sequence.
+   * 
+   * <pre>
    * Color
    *     Model number
    *         Chain
    *             list of start/end ranges
-   * Ordering is by order of addition (for colours and positions), natural ordering (for models and chains)
    * </pre>
+   * 
+   * Ordering is by order of addition (for colours and positions), natural
+   * ordering (for models and chains)
+   * 
+   * @param ssm
+   * @param files
+   * @param sequence
+   * @param sr
+   * @param hideHiddenRegions
+   * @param viewPanel
+   * @return
    */
   protected static Map<Object, AtomSpecModel> buildColoursMap(
           StructureSelectionManager ssm, String[] files,
           SequenceI[][] sequence, SequenceRenderer sr,
-          AlignmentViewPanel viewPanel)
+          boolean hideHiddenRegions, AlignmentViewPanel viewPanel)
   {
     FeatureRenderer fr = viewPanel.getFeatureRenderer();
     FeatureColourFinder finder = new FeatureColourFinder(fr);
@@ -235,12 +260,18 @@ public class ChimeraCommands
               Color colour = sr.getResidueColour(seq, r, finder);
 
               /*
-               * hidden regions are shown gray
-               * todo: iterate over visible columns only
+               * hidden regions are shown gray or, optionally, ignored
                */
               if (!cs.isVisible(r))
               {
-                continue; // colour = Color.GRAY;
+                if (hideHiddenRegions)
+                {
+                  continue;
+                }
+                else
+                {
+                  colour = Color.GRAY;
+                }
               }
 
               final String chain = mapping[m].getChain();