}
}
}
- jmb.centerViewer(toshow);
+ jmb.setChainsToShow(toshow);
+ jmb.centerViewer();
}
void closeViewer()
/**
* prepare the view for a given set of models/chains. chainList contains
* strings of the form 'pdbfilename:Chaincode'
- *
- * @param chainList
- * list of chains to make visible
*/
- public void centerViewer(Vector<String> chainList)
+ public void centerViewer()
{
StringBuilder cmd = new StringBuilder(128);
int mlength, p;
- for (String lbl : chainList)
+ for (String lbl : chainsToShow)
{
mlength = 0;
do
{
cmd.setLength(cmd.length() - 4);
}
- evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd);
+ String command = "select *;restrict " + cmd + ";cartoon;center " + cmd;
+ evalStateCommand(command);
}
public void closeViewer()
}
@Override
- public void showStructures(AlignViewportI av)
+ public void showStructures(AlignViewportI av, boolean refocus)
{
// TODO show Jmol structure optionally restricted to visible alignment
+ // and/or selected chains
}
}
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 java.util.BitSet;
import java.util.Collections;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
}
/**
- * Tells Chimera to display only the specified chains
- *
- * @param toshow
- */
- public void showChains(List<String> toshow)
- {
- /*
- * Construct a chimera command like
- *
- * ~display #*;~ribbon #*;ribbon :.A,:.B
- */
- StringBuilder cmd = new StringBuilder(64);
- boolean first = true;
- for (String chain : toshow)
- {
- int modelNumber = getModelNoForChain(chain);
- String showChainCmd = modelNumber == -1 ? ""
- : modelNumber + ":." + chain.split(":")[1];
- if (!first)
- {
- cmd.append(",");
- }
- cmd.append(showChainCmd);
- first = false;
- }
-
- /*
- * could append ";focus" to this command to resize the display to fill the
- * window, but it looks more helpful not to (easier to relate chains to the
- * whole)
- */
- final String command = "~display #*; ~ribbon #*; ribbon :"
- + cmd.toString();
- sendChimeraCommand(command, false);
- }
-
- /**
* Close down the Jalview viewer and listener, and (optionally) the associated
* Chimera window.
*/
}
@Override
- public void showStructures(AlignViewportI av)
+ public void showStructures(AlignViewportI av, boolean refocus)
{
StringBuilder cmd = new StringBuilder(128);
cmd.append("~display; ~ribbon;");
- if (isShowAlignmentOnly())
+ String atomSpec = getMappedResidues(av);
+ cmd.append("ribbon ").append(atomSpec);
+ if (!isShowAlignmentOnly())
{
- String atomSpec = getMappedResidues(av);
- cmd.append("ribbon ").append(atomSpec);
+ cmd.append("chain @CA|P; ribbon");
}
- else
+ if (refocus)
{
- cmd.append("chain @CA|P; ribbon");
+ cmd.append("; focus");
}
- cmd.append("; focus");
sendChimeraCommand(cmd.toString(), false);
}
&& alignment.findIndex(theSequence) > -1)
{
String chainCd = mapping.getChain();
-
- // TODO only process sequence ranges within visible columns
- VisibleContigsIterator visible = alignment.getHiddenColumns()
+ if (!isShowChain(mapping.getPdbId(), chainCd))
+ {
+ continue;
+ }
+ Iterator<int[]> visible;
+ if (isShowAlignmentOnly())
+ {
+ visible = alignment.getHiddenColumns()
.getVisContigsIterator(0, width, true);
+ }
+ else
+ {
+ visible = Collections.singletonList(new int[] { 0, width })
+ .iterator();
+ }
while (visible.hasNext())
{
int[] visibleRegion = visible.next();
af.setMenusForViewport();
}
+ avp.setSelected(true);
AlignmentPanel ap = (AlignmentPanel) avp;
ap.updateLayout();
- ap.setSelected(true);
ap.alignFrame.setMenusForViewport();
}
}
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import java.util.Vector;
-import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
@Override
void showSelectedChains()
{
- Vector<String> toshow = new Vector<>();
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
- if (item.isSelected())
- {
- toshow.addElement(item.getText());
- }
- }
- }
- jmb.centerViewer(toshow);
+ setSelectedChains();
+ jmb.centerViewer();
}
@Override
import java.util.List;
import java.util.Random;
-import javax.swing.JCheckBoxMenuItem;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
@Override
void showSelectedChains()
{
- List<String> toshow = new ArrayList<>();
- for (int i = 0; i < chainMenu.getItemCount(); i++)
- {
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
- {
- JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
- if (item.isSelected())
- {
- toshow.add(item.getText());
- }
- }
- }
- jmb.showChains(toshow);
+ setSelectedChains();
+
+ /*
+ * refresh display without resizing - easier to see what changed
+ */
+ jmb.showStructures(getAlignmentPanel().getAlignViewport(), false);
}
/**
public void actionPerformed(ActionEvent e)
{
getBinding().setShowAlignmentOnly(showAlignmentOnly.isSelected());
- getBinding().showStructures(getAlignmentPanel().getAlignViewport());
+ getBinding().showStructures(getAlignmentPanel().getAlignViewport(),
+ true);
}
});
viewMenu.add(showAlignmentOnly);
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JInternalFrame;
{
}
+
+ /**
+ * Saves the selected entries in the 'View Chain' menu into a list. Entries are
+ * formatted as "pdbid:chainid". Only the selected chains should be drawn in the
+ * structure display.
+ */
+ protected void setSelectedChains()
+ {
+ List<String> chains = new ArrayList<>();
+ for (int i = 0; i < chainMenu.getItemCount(); i++)
+ {
+ JMenuItem menuItem = chainMenu.getItem(i);
+ if (menuItem instanceof JCheckBoxMenuItem)
+ {
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem) menuItem;
+ if (item.isSelected())
+ {
+ chains.add(item.getText());
+ }
+ }
+ }
+ getBinding().setChainsToShow(chains);
+ }
}
private boolean showAlignmentOnly;
+ /*
+ * a list of chains "pdbid:chainid" to show in the viewer;
+ * empty means show all
+ */
+ // TODO make private once showStructures() deals with this
+ protected List<String> chainsToShow;
+
/**
* Data bean class to simplify parameterisation in superposeStructures
*/
{
this.ssm = ssm;
this.sequence = seqs;
+ chainsToShow = new ArrayList<>();
}
/**
this.nucleotide = Comparison.isNucleotide(sequenceIs);
this.pdbEntry = pdbentry;
this.protocol = protocol;
+ chainsToShow = new ArrayList<>();
+
resolveChains();
}
* mapped to visible regions of the alignment.
*
* @param alignViewportI
+ * @param refocus
+ * if true, refit the display to the viewer
*/
- public void showStructures(AlignViewportI alignViewportI)
+ public void showStructures(AlignViewportI alignViewportI, boolean refocus)
{
// override with implementation
}
colourBySequence(ap);
}
}
+
+ /**
+ * Sets the list of chains to display (as "pdbid:chain"), where an empty list
+ * means show all
+ *
+ * @param chains
+ */
+ public void setChainsToShow(List<String> chains)
+ {
+ chainsToShow = chains;
+ }
+
+ /**
+ * Answers true if the specified structure and chain are selected to be shown in
+ * the viewer, else false
+ *
+ * @param pdbId
+ * @param chainId
+ * @return
+ */
+ protected boolean isShowChain(String pdbId, String chainId)
+ {
+ if (chainsToShow.isEmpty())
+ {
+ return true;
+ }
+ return chainsToShow.contains(pdbId + ":" + chainId);
+ }
}