Merge branch 'develop' into features/JAL-2295setChimeraAttributes
[jalview.git] / src / jalview / ext / rbvi / chimera / JalviewChimeraBinding.java
index 72b33cc..cc1de6a 100644 (file)
@@ -27,8 +27,8 @@ import jalview.bin.Cache;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SearchResultMatchI;
 import jalview.datamodel.SearchResults;
-import jalview.datamodel.SearchResults.Match;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.httpserver.AbstractRequestHandler;
@@ -1175,19 +1175,32 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
 
     String cmd = "list residues attr '" + attName + "'";
     List<String> residues = sendChimeraCommand(cmd, true);
-    /*
-     * Expect 0, 1 or more reply lines of the format (chi2 is attName):
-     * residue id #0:5.A chi2 -155.000836316 index 5
-     * or
-     * residue id #0:6.A chi3 None
-     * 
-     * We assume here that attributes on structure do not naturally convert
-     * to ranges on sequence, i.e. we just set one feature per mapped position.
-     * 
-     * To conflate positions, would need to first build a map 
-     * Map<String value, Map<Sequence seq, List<Integer position>>>
-     * and then traverse it to find feature ranges.
-     */
+
+    boolean featureAdded = createFeaturesForAttributes(attName, residues);
+    if (featureAdded)
+    {
+      alignmentPanel.getFeatureRenderer().featuresAdded();
+    }
+  }
+
+  /**
+   * Create features in Jalview for the given attribute name and structure
+   * residues.
+   * 
+   * <pre>
+   * The residue list should be 0, 1 or more reply lines of the format: 
+   *     residue id #0:5.A isHelix -155.000836316 index 5 
+   * or 
+   *     residue id #0:6.A isHelix None
+   * </pre>
+   * 
+   * @param attName
+   * @param residues
+   * @return
+   */
+  protected boolean createFeaturesForAttributes(String attName,
+          List<String> residues)
+  {
     boolean featureAdded = false;
     String featureGroup = getViewerFeatureGroup();
 
@@ -1236,6 +1249,10 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
       spec.setPdbFile(pdbFile);
 
       List<AtomSpec> atoms = Collections.singletonList(spec);
+
+      /*
+       * locate the mapped position in the alignment (if any)
+       */
       SearchResults sr = getSsm()
               .findAlignmentPositionsForStructurePositions(atoms);
 
@@ -1243,7 +1260,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
        * expect one matched alignment position, or none 
        * (if the structure position is not mapped)
        */
-      for (Match m : sr.getResults())
+      for (SearchResultMatchI m : sr.getResults())
       {
         SequenceI seq = m.getSequence();
         int start = m.getStart();
@@ -1255,10 +1272,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel
         featureAdded |= seq.addSequenceFeature(sf);
       }
     }
-    if (featureAdded)
-    {
-      alignmentPanel.getFeatureRenderer().featuresAdded();
-    }
+    return featureAdded;
   }
 
   /**