import java.util.List;
import java.util.Map;
-import MCview.PDBChain;
-
/**
* Routines for generating Chimera commands for Jalview/Chimera binding
*
public class ChimeraCommands
{
+ public static final String NAMESPACE_PREFIX = "jv_";
+
/**
- * utility to construct the commands to colour chains by the given alignment
- * for passing to Chimera
- *
- * @returns Object[] { Object[] { <model being coloured>,
+ * Constructs Chimera commands to colour residues as per the Jalview alignment
*
+ * @param ssm
+ * @param files
+ * @param sequence
+ * @param sr
+ * @param fr
+ * @param alignment
+ * @return
*/
public static StructureMappingcommandSet getColourBySequenceCommand(
StructureSelectionManager ssm, String[] files,
}
/**
- * Constructs and returns a set of Chimera commands to set attributes on
- * residues corresponding to features in Jalview
+ * 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
for (SequenceFeature sf : sfs)
{
String type = sf.getType();
- if (!visibleFeatures.contains(type) || suppressFeature(type))
+
+ /*
+ * Only copy visible features, don't copy any which originated
+ * from Chimera, and suppress uninteresting ones (e.g. RESNUM)
+ */
+ boolean isFromViewer = JalviewChimeraBinding.CHIMERA_FEATURE_GROUP
+ .equals(sf.getFeatureGroup());
+ if (isFromViewer || !visibleFeatures.contains(type))
{
continue;
}
if (!mappedRanges.isEmpty())
{
String value = sf.getDescription();
- if (value == null)
+ if (value == null || value.length() == 0)
{
value = type;
}
float score = sf.getScore();
- if (score != 0f && score != Float.NaN)
+ if (score != 0f && !Float.isNaN(score))
{
value = Float.toString(score);
}
}
/**
- * Answers true if the feature type is one we don't wish to propagate to
- * Chimera - for now, RESNUM
- *
- * @param type
- * @return
- */
- static boolean suppressFeature(String type)
- {
- return PDBChain.RESNUM_FEATURE.equals(type);
- }
-
- /**
* Traverse the map of features/values/models/chains/positions to construct a
* list of 'setattr' commands (one per distinct feature type and value).
* <p>
List<String> commands = new ArrayList<String>();
for (String featureType : featureMap.keySet())
{
- String attributeName = "jv_"
- + featureType.replace(" ", "_").replace("-", "_");
+ String attributeName = makeAttributeName(featureType);
/*
* clear down existing attributes for this feature
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.
+ *
+ * @param featureType
+ * @return <pre>
+ * @see https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/setattr.html
+ * </pre>
+ */
+ protected static String makeAttributeName(String featureType)
+ {
+ StringBuilder sb = new StringBuilder();
+ if (featureType != null)
+ {
+ for (char c : featureType.toCharArray())
+ {
+ sb.append(Character.isLetterOrDigit(c) ? c : '_');
+ }
+ }
+ String attName = NAMESPACE_PREFIX + sb.toString();
+
+ /*
+ * Chimera treats an attribute name ending in 'color' as colour-valued;
+ * Jalview doesn't, so prevent this by appending an underscore
+ */
+ if (attName.toUpperCase().endsWith("COLOR"))
+ {
+ attName += "_";
+ }
+
+ return attName;
+ }
+
}