*/
package jalview.ext.jmol;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
{
showConsole(false);
}
+
+ @Override
+ public void showStructures(AlignViewportI av)
+ {
+ // TODO show Jmol structure optionally restricted to visible alignment
+ }
}
*/
public class ChimeraCommands
{
-
public static final String NAMESPACE_PREFIX = "jv_";
+ private static final String COLOR_GRAY_HEX = "color "
+ + ColorUtils.toTkCode(Color.GRAY);
+
/**
* Constructs Chimera commands to colour residues as per the Jalview alignment
*
* delimited). If length limit issues arise, refactor to return one color
* command per colour.
*/
- List<String> commands = new ArrayList<String>();
+ List<String> commands = new ArrayList<>();
StringBuilder sb = new StringBuilder(256);
- boolean firstColour = true;
+ sb.append(COLOR_GRAY_HEX);
+
for (Object key : colourMap.keySet())
{
Color colour = (Color) key;
String colourCode = ColorUtils.toTkCode(colour);
- if (!firstColour)
- {
- sb.append("; ");
- }
+ sb.append("; ");
sb.append("color ").append(colourCode).append(" ");
- firstColour = false;
final AtomSpecModel colourData = colourMap.get(colour);
sb.append(colourData.getAtomSpec());
}
AlignViewportI viewport = viewPanel.getAlignViewport();
HiddenColumns cs = viewport.getAlignment().getHiddenColumns();
AlignmentI al = viewport.getAlignment();
- Map<Object, AtomSpecModel> colourMap = new LinkedHashMap<Object, AtomSpecModel>();
+ Map<Object, AtomSpecModel> colourMap = new LinkedHashMap<>();
Color lastColour = null;
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
Color colour = sr.getResidueColour(seq, r, finder);
/*
- * darker colour for hidden regions
+ * hidden regions are shown gray
+ * todo: iterate over visible columns only
*/
if (!cs.isVisible(r))
{
- colour = Color.GRAY;
+ continue; // colour = Color.GRAY;
}
final String chain = mapping[m].getChain();
StructureSelectionManager ssm, String[] files, SequenceI[][] seqs,
AlignmentViewPanel viewPanel)
{
- Map<String, Map<Object, AtomSpecModel>> theMap = new LinkedHashMap<String, Map<Object, AtomSpecModel>>();
+ Map<String, Map<Object, AtomSpecModel>> theMap = new LinkedHashMap<>();
FeatureRenderer fr = viewPanel.getFeatureRenderer();
if (fr == null)
Map<Object, AtomSpecModel> featureValues = theMap.get(type);
if (featureValues == null)
{
- featureValues = new HashMap<Object, AtomSpecModel>();
+ featureValues = new HashMap<>();
theMap.put(type, featureValues);
}
for (int[] range : mappedRanges)
protected static List<String> buildSetAttributeCommands(
Map<String, Map<Object, AtomSpecModel>> featureMap)
{
- List<String> commands = new ArrayList<String>();
+ List<String> commands = new ArrayList<>();
for (String featureType : featureMap.keySet())
{
String attributeName = makeAttributeName(featureType);
*/
package jalview.ext.rbvi.chimera;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.SequenceRenderer;
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.VisibleContigsIterator;
import jalview.httpserver.AbstractRequestHandler;
import jalview.io.DataSourceType;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.structure.AtomSpec;
+import jalview.structure.StructureMapping;
import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel;
private static final String ALPHACARBON = "CA";
- private List<String> chainNames = new ArrayList<String>();
+ private List<String> chainNames = new ArrayList<>();
- private Hashtable<String, String> chainFile = new Hashtable<String, String>();
+ private Hashtable<String, String> chainFile = new Hashtable<>();
/*
* Object through which we talk to Chimera
/*
* Map of ChimeraModel objects keyed by PDB full local file name
*/
- private Map<String, List<ChimeraModel>> chimeraMaps = new LinkedHashMap<String, List<ChimeraModel>>();
+ private Map<String, List<ChimeraModel>> chimeraMaps = new LinkedHashMap<>();
String lastHighlightCommand;
String file = pe.getFile();
try
{
- List<ChimeraModel> modelsToMap = new ArrayList<ChimeraModel>();
+ List<ChimeraModel> modelsToMap = new ArrayList<>();
List<ChimeraModel> oldList = viewer.getModelList();
boolean alreadyOpen = false;
System.out.println(
"Superimpose command(s):\n" + command.toString());
}
- allComs.append("~display all; chain @CA|P; ribbon ")
- .append(selectioncom.toString())
+ allComs/*.append("~display all; chain @CA|P; ribbon ")
+ .append(selectioncom.toString())*/
.append(";" + command.toString());
}
}
{
System.out.println("Select regions:\n" + selectioncom.toString());
}
- allComs.append("; ~display all; chain @CA|P; ribbon ")
- .append(selectioncom.toString()).append("; focus");
+ allComs.append("; ~display "); // all");
+ if (!isShowAlignmentOnly())
+ {
+ allComs.append("; ribbon; chain @CA|P");
+ }
+ else
+ {
+ allComs.append("; ~ribbon");
+ }
+ allComs.append("; ribbon ").append(selectioncom.toString())
+ .append("; focus");
List<String> chimeraReplies = sendChimeraCommand(allComs.toString(),
true);
for (String reply : chimeraReplies)
{
- if (reply.toLowerCase().contains("unequal numbers of atoms"))
+ String lowerCase = reply.toLowerCase();
+ if (lowerCase.contains("unequal numbers of atoms")
+ || lowerCase.contains("at least"))
{
error = reply;
}
protected List<AtomSpec> convertStructureResiduesToAlignment(
List<String> structureSelection)
{
- List<AtomSpec> atomSpecs = new ArrayList<AtomSpec>();
+ List<AtomSpec> atomSpecs = new ArrayList<>();
for (String atomSpec : structureSelection)
{
try
}
return -1;
}
+
+ @Override
+ public void showStructures(AlignViewportI av)
+ {
+ StringBuilder cmd = new StringBuilder(128);
+ cmd.append("~display; ~ribbon;");
+ if (isShowAlignmentOnly())
+ {
+ String atomSpec = getMappedResidues(av);
+ cmd.append("ribbon ").append(atomSpec);
+ }
+ else
+ {
+ cmd.append("chain @CA|P; ribbon");
+ }
+ cmd.append("; focus");
+ sendChimeraCommand(cmd.toString(), false);
+ }
+
+ /**
+ * Builds a Chimera atomSpec of residues mapped from sequences, of the format
+ * (#model:residues.chain)
+ *
+ * <pre>
+ * #0:2-94.A | #1:1-93.C | #2:1-93.A
+ * </pre>
+ *
+ * Only residues visible in the alignment are included, that is, hidden columns
+ * and sequences are excluded.
+ *
+ * @param av
+ * @return
+ */
+ private String getMappedResidues(AlignViewportI av)
+ {
+ AlignmentI alignment = av.getAlignment();
+ final int width = alignment.getWidth();
+
+ String[] files = getStructureFiles();
+
+ StringBuilder atomSpec = new StringBuilder(256);
+
+ for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
+ {
+ StructureMapping[] mappings = getSsm().getMapping(files[pdbfnum]);
+
+ /*
+ * Find the first mapped sequence (if any) for this PDB entry which is in
+ * the alignment
+ */
+ final int seqCountForPdbFile = getSequence()[pdbfnum].length;
+ for (int s = 0; s < seqCountForPdbFile; s++)
+ {
+ for (StructureMapping mapping : mappings)
+ {
+ final SequenceI theSequence = getSequence()[pdbfnum][s];
+ if (mapping.getSequence() == theSequence
+ && alignment.findIndex(theSequence) > -1)
+ {
+ String chainCd = mapping.getChain();
+
+ // TODO only process sequence ranges within visible columns
+ VisibleContigsIterator visible = alignment.getHiddenColumns()
+ .getVisContigsIterator(0, width, true);
+ while (visible.hasNext())
+ {
+ int[] visibleRegion = visible.next();
+ int seqStartPos = theSequence.findPosition(visibleRegion[0]);
+ int seqEndPos = theSequence.findPosition(visibleRegion[1]);
+ List<int[]> residueRanges = mapping
+ .getPDBResNumRanges(seqStartPos, seqEndPos);
+ if (!residueRanges.isEmpty())
+ {
+ if (atomSpec.length() > 0)
+ {
+ atomSpec.append("| ");
+ }
+ atomSpec.append(getModelSpec(pdbfnum)).append(":");
+ boolean first = true;
+ for (int[] range : residueRanges)
+ {
+ if (!first)
+ {
+ atomSpec.append(",");
+ }
+ first = false;
+ atomSpec.append(range[0]).append("-").append(range[1]);
+ atomSpec.append(".").append(chainCd);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return atomSpec.toString();
+ }
}
protected String alignStructs_withAllAlignPanels()
{
String reply = super.alignStructs_withAllAlignPanels();
- if (reply != null)
- {
- statusBar.setText("Superposition failed: " + reply);
- }
+ statusBar.setText(
+ reply == null ? " " : "Superposition failed: " + reply);
return reply;
}
});
viewMenu.add(seqColourBy);
+ showAlignmentOnly = new JCheckBoxMenuItem("Visible alignment only");
+ showAlignmentOnly.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ getBinding().setShowAlignmentOnly(showAlignmentOnly.isSelected());
+ getBinding().showStructures(getAlignmentPanel().getAlignViewport());
+ }
+ });
+ viewMenu.add(showAlignmentOnly);
+
final ItemListener handler = new ItemListener()
{
@Override
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import javax.swing.JCheckBoxMenuItem;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
protected JMenuItem alignStructs;
+ protected JCheckBoxMenuItem showAlignmentOnly;
+
protected JMenuItem fitToWindow;
protected JRadioButtonMenuItem seqColour;
*/
package jalview.structures.models;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.SequenceRenderer;
import jalview.api.StructureSelectionManagerProvider;
public String fileLoadingError;
+ private boolean showAlignmentOnly;
+
/**
* Data bean class to simplify parameterisation in superposeStructures
*/
{ Integer.valueOf(pe).toString() }));
}
final String nullChain = "TheNullChain";
- List<SequenceI> s = new ArrayList<SequenceI>();
- List<String> c = new ArrayList<String>();
+ List<SequenceI> s = new ArrayList<>();
+ List<String> c = new ArrayList<>();
if (getChains() == null)
{
setChains(new String[getPdbCount()][]);
public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe,
SequenceI[][] seq, String[][] chns)
{
- List<PDBEntry> v = new ArrayList<PDBEntry>();
- List<int[]> rtn = new ArrayList<int[]>();
+ List<PDBEntry> v = new ArrayList<>();
+ List<int[]> rtn = new ArrayList<>();
for (int i = 0; i < getPdbCount(); i++)
{
v.add(getPdbEntry(i));
public abstract jalview.api.FeatureRenderer getFeatureRenderer(
AlignmentViewPanel alignment);
+
+ /**
+ * Sets the flag for whether only mapped visible residues in the alignment
+ * should be visible in the structure viewer
+ *
+ * @param b
+ */
+ public void setShowAlignmentOnly(boolean b)
+ {
+ showAlignmentOnly = b;
+ }
+
+ /**
+ * Answers true if only mapped visible residues in the alignment should be
+ * visible in the structure viewer, else false
+ *
+ * @return
+ */
+ public boolean isShowAlignmentOnly()
+ {
+ return showAlignmentOnly;
+ }
+
+ /**
+ * Shows the structures in the viewer, without changing their colouring. This is
+ * to support toggling of whether the whole structure is shown, or only residues
+ * mapped to visible regions of the alignment.
+ *
+ * @param alignViewportI
+ */
+ public abstract void showStructures(AlignViewportI alignViewportI);
}