JAL-3518 more extraction of ChimeraX commands as overrides
[jalview.git] / src / jalview / ext / rbvi / chimera / ChimeraXCommands.java
index 3947bb0..7693802 100644 (file)
@@ -32,7 +32,6 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.Desktop;
 import jalview.renderer.seqfeatures.FeatureColourFinder;
 import jalview.structure.StructureMapping;
-import jalview.structure.StructureMappingcommandSet;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.ColorUtils;
 import jalview.util.Comparison;
@@ -50,13 +49,11 @@ import java.util.Map.Entry;
  */
 public class ChimeraXCommands extends ChimeraCommands
 {
-  public static final String NAMESPACE_PREFIX = "jv_";
-
   private static final String CMD_COLOUR_BY_CHARGE = "color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow";
 
   /**
    * Traverses a map of { modelNumber, {chain, {list of from-to ranges} } } and
-   * builds a Chimera format atom spec
+   * builds a ChimeraX format atom spec
    * 
    * @param modelAndChainRanges
    */
@@ -211,65 +208,6 @@ public class ChimeraXCommands extends ChimeraCommands
   }
 
   /**
-   * Helper method to add one contiguous range to the AtomSpec model for the given
-   * value (creating the model if necessary). As used by Jalview, {@code value} is
-   * <ul>
-   * <li>a colour, when building a 'colour structure by sequence' command</li>
-   * <li>a feature value, when building a 'set Chimera attributes from features'
-   * command</li>
-   * </ul>
-   * 
-   * @param map
-   * @param value
-   * @param model
-   * @param startPos
-   * @param endPos
-   * @param chain
-   */
-  protected static void addAtomSpecRange(Map<Object, AtomSpecModel> map,
-          Object value, int model, int startPos, int endPos, String chain)
-  {
-    /*
-     * Get/initialize map of data for the colour
-     */
-    AtomSpecModel atomSpec = map.get(value);
-    if (atomSpec == null)
-    {
-      atomSpec = new AtomSpecModel();
-      map.put(value, atomSpec);
-    }
-
-    atomSpec.addRange(model, startPos, endPos, chain);
-  }
-
-  /**
-   * Constructs and returns Chimera commands to set attributes on residues
-   * corresponding to features in Jalview. Attribute names are the Jalview
-   * feature type, with a "jv_" prefix.
-   * 
-   * @param ssm
-   * @param files
-   * @param seqs
-   * @param viewPanel
-   * @return
-   */
-  public static StructureMappingcommandSet getSetAttributeCommandsForFeatures(
-          StructureSelectionManager ssm, String[] files, SequenceI[][] seqs,
-          AlignmentViewPanel viewPanel)
-  {
-    Map<String, Map<Object, AtomSpecModel>> featureMap = buildFeaturesMap(
-            ssm, files, seqs, viewPanel);
-
-    List<String> commands = buildSetAttributeCommands(featureMap);
-
-    StructureMappingcommandSet cs = new StructureMappingcommandSet(
-            ChimeraXCommands.class, null,
-            commands.toArray(new String[commands.size()]));
-
-    return cs;
-  }
-
-  /**
    * <pre>
    * Helper method to build a map of 
    *   { featureType, { feature value, AtomSpecModel } }
@@ -495,56 +433,6 @@ public class ChimeraXCommands extends ChimeraCommands
   }
 
   /**
-   * Traverse the map of features/values/models/chains/positions to construct a
-   * list of 'setattr' commands (one per distinct feature type and value).
-   * <p>
-   * The format of each command is
-   * 
-   * <pre>
-   * <blockquote> setattr r <featureName> " " #modelnumber:range.chain 
-   * e.g. setattr r jv:chain <value> #0:2.B,4.B,9-12.B|#1:1.A,2-6.A,...
-   * </blockquote>
-   * </pre>
-   * 
-   * @param featureMap
-   * @return
-   */
-  protected static List<String> buildSetAttributeCommands(
-          Map<String, Map<Object, AtomSpecModel>> featureMap)
-  {
-    List<String> commands = new ArrayList<>();
-    for (String featureType : featureMap.keySet())
-    {
-      String attributeName = makeAttributeName(featureType);
-
-      /*
-       * clear down existing attributes for this feature
-       */
-      // 'problem' - sets attribute to None on all residues - overkill?
-      // commands.add("~setattr r " + attributeName + " :*");
-
-      Map<Object, AtomSpecModel> values = featureMap.get(featureType);
-      for (Object value : values.keySet())
-      {
-        /*
-         * for each distinct value recorded for this feature type,
-         * add a command to set the attribute on the mapped residues
-         * Put values in single quotes, encoding any embedded single quotes
-         */
-        StringBuilder sb = new StringBuilder(128);
-        String featureValue = value.toString();
-        featureValue = featureValue.replaceAll("\\'", "&#39;");
-        sb.append("setattr r ").append(attributeName).append(" '")
-                .append(featureValue).append("' ");
-        sb.append(values.get(value).getAtomSpec());
-        commands.add(sb.toString());
-      }
-    }
-
-    return commands;
-  }
-
-  /**
    * Makes a prefixed and valid Chimera attribute name. A jv_ prefix is applied
    * for a 'Jalview' namespace, and any non-alphanumeric character is converted
    * to an underscore.
@@ -624,4 +512,39 @@ public class ChimeraXCommands extends ChimeraCommands
     return "view";
   }
 
+  /**
+   * {@inheritDoc}
+   * 
+   * @return
+   */
+  protected static int getModelStartNo()
+  {
+    return 1;
+  }
+
+  /**
+   * Returns a viewer command to set the given residue attribute value on
+   * residues specified by the AtomSpecModel, for example
+   * 
+   * <pre>
+   * setattr #0/A:3-9,14-20,39-43 res jv_strand 'strand' create true
+   * </pre>
+   * 
+   * @param attributeName
+   * @param attributeValue
+   * @param atomSpecModel
+   * @return
+   */
+  @Override
+  protected String getSetAttributeCommand(String attributeName,
+          String attributeValue, AtomSpecModel atomSpecModel)
+  {
+    StringBuilder sb = new StringBuilder(128);
+    sb.append("setattr ").append(atomSpecModel.getAtomSpecX());
+    sb.append(" res ").append(attributeName).append(" '")
+            .append(attributeValue).append("'");
+    sb.append(" create true");
+    return sb.toString();
+  }
+
 }