*/
package jalview.ext.jmol;
+import jalview.api.AlignViewportI;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
import jalview.datamodel.AlignmentI;
* @param files
* @param sr
* @param fr
- * @param alignment
+ * @param viewport
* @return
*/
@Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ AlignViewportI viewport)
{
return JmolCommands.getColourBySequenceCommand(getSsm(), files,
- getSequence(), sr, fr, alignment);
+ getSequence(), sr, fr, viewport);
}
/**
*/
package jalview.ext.jmol;
+import jalview.api.AlignViewportI;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SequenceI;
import jalview.structure.StructureMapping;
import jalview.structure.StructureMappingcommandSet;
import java.awt.Color;
import java.util.ArrayList;
+import java.util.List;
/**
* Routines for generating Jmol commands for Jalview/Jmol binding another
public static StructureMappingcommandSet[] getColourBySequenceCommand(
StructureSelectionManager ssm, String[] files,
SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ AlignViewportI viewport)
{
-
- ArrayList<StructureMappingcommandSet> cset = new ArrayList<StructureMappingcommandSet>();
+ ColumnSelection cs = viewport.getColumnSelection();
+ AlignmentI al = viewport.getAlignment();
+ List<StructureMappingcommandSet> cset = new ArrayList<StructureMappingcommandSet>();
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
for (int sp, m = 0; m < mapping.length; m++)
{
if (mapping[m].getSequence() == sequence[pdbfnum][s]
- && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
+ && (sp = al.findIndex(sequence[pdbfnum][s])) > -1)
{
- SequenceI asp = alignment.getSequenceAt(sp);
+ SequenceI asp = al.getSequenceAt(sp);
for (int r = 0; r < asp.getLength(); r++)
{
// no mapping to gaps in sequence
{
col = fr.findFeatureColour(col, sequence[pdbfnum][s], r);
}
+
+ /*
+ * shade hidden regions darker
+ */
+ if (!cs.isVisible(r))
+ {
+ // col = ColorUtils.darkerThan(col);
+ col = Color.GRAY;
+ }
+
String newSelcom = (mapping[m].getChain() != " " ? ":"
+ mapping[m].getChain() : "")
+ "/"
*/
package jalview.ext.rbvi.chimera;
+import jalview.api.AlignViewportI;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.structure.StructureMapping;
* @param sequence
* @param sr
* @param fr
- * @param alignment
+ * @param viewport
* @return
*/
public static StructureMappingcommandSet[] getColourBySequenceCommand(
StructureSelectionManager ssm, String[] files,
SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ AlignViewportI viewport)
{
Map<Object, AtomSpecModel> colourMap = buildColoursMap(ssm, files,
- sequence, sr, fr, alignment);
+ sequence, sr, fr, viewport);
List<String> colourCommands = buildColourCommands(colourMap);
/**
* <pre>
- * Build a data structure which maps contiguous subsequences for each colour.
- * This generates a data structure from which we can easily generate the
- * Chimera command for colour by sequence.
+ * Build a data structure which records contiguous subsequences for each colour.
+ * From this we can easily generate the Chimera command for colour by sequence.
* Color
* Model number
* Chain
protected static Map<Object, AtomSpecModel> buildColoursMap(
StructureSelectionManager ssm, String[] files,
SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ AlignViewportI viewport)
{
+ ColumnSelection cs = viewport.getColumnSelection();
+ AlignmentI al = viewport.getAlignment();
Map<Object, AtomSpecModel> colourMap = new LinkedHashMap<Object, AtomSpecModel>();
Color lastColour = null;
+
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
{
final SequenceI seq = sequence[pdbfnum][s];
if (mapping[m].getSequence() == seq
- && (sp = alignment.findIndex(seq)) > -1)
+ && (sp = al.findIndex(seq)) > -1)
{
- SequenceI asp = alignment.getSequenceAt(sp);
+ SequenceI asp = al.getSequenceAt(sp);
for (int r = 0; r < asp.getLength(); r++)
{
// no mapping to gaps in sequence
}
Color colour = sr.getResidueColour(seq, r, fr);
+
+ /*
+ * darker colour for hidden regions
+ */
+ if (!cs.isVisible(r))
+ {
+ // colour = ColorUtils.darkerThan(colour);
+ colour = Color.GRAY;
+ }
+
final String chain = mapping[m].getChain();
/*
*/
StringBuilder sb = new StringBuilder(128);
String featureValue = value.toString();
- featureValue.replaceAll("'", "'");
+ featureValue = featureValue.replaceAll("\\'", "'");
sb.append("setattr r ").append(attributeName).append(" '")
.append(featureValue).append("' ");
sb.append(values.get(value).getAtomSpec());
*/
package jalview.ext.rbvi.chimera;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
* @param files
* @param sr
* @param fr
- * @param alignment
+ * @param viewport
* @return
*/
@Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ AlignViewportI viewport)
{
return ChimeraCommands.getColourBySequenceCommand(getSsm(), files,
- getSequence(), sr, fr, alignment);
+ getSequence(), sr, fr, viewport);
}
/**
ArrayList<String> pdbfn = new ArrayList<String>();
StructureMappingcommandSet[] colcommands = JmolCommands
.getColourBySequenceCommand(ssm, modelSet, sequence, sr, fr,
- ((AlignmentViewPanel) source).getAlignment());
+ ((AlignmentViewPanel) source).getAlignViewport());
if (colcommands == null)
{
return;
return _listenerfn;
}
+ @Override
public void finalize() throws Throwable
{
jvlite = null;
return pdb;
}
- private boolean isCIFFile(String filename)
+ public void addStructureMapping(StructureMapping sm)
{
- String fileExt = filename.substring(filename.lastIndexOf(".") + 1,
- filename.length());
- return "cif".equalsIgnoreCase(fileExt);
+ mappings.add(sm);
}
/**
*/
package jalview.structures.models;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
protected abstract StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment);
+ AlignViewportI alignViewportI);
/**
* returns the current featureRenderer that should be used to colour the
*/
public void colourBySequence(AlignmentViewPanel alignmentv)
{
- boolean showFeatures = alignmentv.getAlignViewport()
- .isShowSequenceFeatures();
if (!colourBySequence || !isLoadingFinished())
{
return;
SequenceRenderer sr = getSequenceRenderer(alignmentv);
FeatureRenderer fr = null;
+ boolean showFeatures = alignmentv.getAlignViewport()
+ .isShowSequenceFeatures();
if (showFeatures)
{
fr = getFeatureRenderer(alignmentv);
}
- AlignmentI alignment = alignmentv.getAlignment();
StructureMappingcommandSet[] colourBySequenceCommands = getColourBySequenceCommands(
- files, sr, fr, alignment);
+ files, sr, fr, alignmentv.getAlignViewport());
colourBySequence(colourBySequenceCommands);
}
// need some mappings!
StructureMappingcommandSet[] commands = JmolCommands
- .getColourBySequenceCommand(ssm, files, seqs, sr, null, al);
+ .getColourBySequenceCommand(ssm, files, seqs, sr, null,
+ af.getViewport());
}
}
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.ColumnSelection;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
import jalview.gui.JvOptionPane;
+import jalview.gui.SequenceRenderer;
+import jalview.schemes.JalviewColourScheme;
+import jalview.structure.StructureMapping;
+import jalview.structure.StructureMappingcommandSet;
+import jalview.structure.StructureSelectionManager;
import java.awt.Color;
import java.util.HashMap;
* feature name gets a jv_ namespace prefix
* feature value is quoted in case it contains spaces
*/
- assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:8-20.A");
+ assertEquals(commands.get(0), "setattr r jv_chain 'X' #0:8-20.A");
// add same feature value, overlapping range
ChimeraCommands.addColourRange(featureValues, "X", 0, 3, 9, "A");
ChimeraCommands.addColourRange(featureValues, "X", 0, 21, 25, "A");
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertEquals(1, commands.size());
- assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:3-25.A");
+ assertEquals(commands.get(0), "setattr r jv_chain 'X' #0:3-25.A");
// same feature value and model, different chain
ChimeraCommands.addColourRange(featureValues, "X", 0, 21, 25, "B");
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertEquals(1, commands.size());
assertEquals(commands.get(0),
- "setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A");
+ "setattr r jv_chain 'X' #0:3-25.A,21-25.B|#1:26-30.A");
// same feature, different value
ChimeraCommands.addColourRange(featureValues, "Y", 0, 40, 50, "A");
// commands are ordered by feature type but not by value
// so use contains to test for the expected command:
assertTrue(commands
- .contains("setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A"));
- assertTrue(commands.contains("setattr r jv_chain \"Y\" #0:40-50.A"));
+ .contains("setattr r jv_chain 'X' #0:3-25.A,21-25.B|#1:26-30.A"));
+ assertTrue(commands.contains("setattr r jv_chain 'Y' #0:40-50.A"));
featuresMap.clear();
featureValues.clear();
featuresMap.put("side-chain binding!", featureValues);
- ChimeraCommands.addColourRange(featureValues, "metal ion!", 0, 7, 15,
+ ChimeraCommands.addColourRange(featureValues,
+ "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", 0, 7, 15,
"A");
- // feature names are sanitised to change space or hyphen to underscore
+ // feature names are sanitised to change non-alphanumeric to underscore
+ // feature values are sanitised to encode single quote characters
commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
assertTrue(commands
- .contains("setattr r jv_side_chain_binding_ \"metal ion!\" #0:7-15.A"));
+ .contains("setattr r jv_side_chain_binding_ '<html>metal <a href=\"http:a.b.c/x\"> 'ion!' #0:7-15.A"));
}
/**
assertEquals(ChimeraCommands.makeAttributeName("helixColor"),
"jv_helixColor_");
}
+
+ @Test(groups = { "Functional" })
+ public void testGetColourBySequenceCommands_hiddenColumns()
+ {
+ /*
+ * load these sequences, coloured by Strand propensity,
+ * with columns 2-4 hidden
+ */
+ SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG");
+ SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS");
+ AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 });
+ AlignFrame af = new AlignFrame(al, 800, 500);
+ af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString());
+ ColumnSelection cs = new ColumnSelection();
+ cs.addElement(2);
+ cs.addElement(3);
+ cs.addElement(4);
+ af.getViewport().setColumnSelection(cs);
+ af.hideSelColumns_actionPerformed(null);
+ SequenceRenderer sr = new SequenceRenderer(af.getViewport());
+ SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
+ String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
+ StructureSelectionManager ssm = new StructureSelectionManager();
+
+ /*
+ * map residues 1-10 to residues 21-30 (atoms 105-150) in structures
+ */
+ HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
+ for (int pos = 1; pos <= seq1.getLength(); pos++)
+ {
+ map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
+ }
+ StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1",
+ "A", map, null);
+ ssm.addStructureMapping(sm1);
+ StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2",
+ "B", map, null);
+ ssm.addStructureMapping(sm2);
+
+ StructureMappingcommandSet[] commands = ChimeraCommands
+ .getColourBySequenceCommand(ssm, files, seqs, sr, null,
+ af.getViewport());
+ assertEquals(1, commands.length);
+ assertEquals(1, commands[0].commands.length);
+ String theCommand = commands[0].commands[0];
+ // M colour is #82827d (see strand.html help page)
+ assertTrue(theCommand.contains("color #82827d #0:21.A|#1:21.B"));
+ // H colour is #60609f
+ assertTrue(theCommand.contains("color #60609f #0:22.A"));
+ // V colour is ##ffff00
+ assertTrue(theCommand.contains("color #ffff00 #1:22.B"));
+ // hidden columns are Gray (128, 128, 128)
+ assertTrue(theCommand.contains("color #808080 #0:23-25.A|#1:23-25.B"));
+ // S and G are both coloured #4949b6
+ assertTrue(theCommand.contains("color #4949b6 #0:26-30.A|#1:26-30.B"));
+ }
}
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
@Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
- AlignmentI alignment)
+ AlignViewportI viewport)
{
return null;
}
assertFalse(matched.get(4)); // superposable, but hidden, column
assertTrue(matched.get(5));
}
-
- public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)
- {
- return null;
- }
-
- public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
- {
- return null;
- }
}