label.standard_databases = Standard Databases
label.fetch_embl_uniprot = Fetch from EMBL/EMBLCDS or Uniprot/PDB and any selected DAS sources
label.reset_min_max_colours_to_defaults = Reset min and max colours to defaults from user preferences.
-label.align_structures_using_linked_alignment_views = Superpose structures using selected alignment view
+label.align_structures_using_linked_alignment_views = Superpose structures using {0} selected alignment view(s)
label.connect_to_session = Connect to session {0}
label.threshold_feature_display_by_score = Threshold the feature display by score.
label.threshold_feature_no_threshold = No Threshold
label.colour_with_jmol = Colour with Jmol
label.colour_with_chimera = Colour with Chimera
label.superpose_structures = Superpose Structures
+error.superposition_failed = Superposition failed: {0}
+label.insufficient_residues = Not enough aligned residues ({0}) to perform superposition
label.jmol = Jmol
label.chimera = Chimera
label.create_chimera_attributes = Write Jalview features
label.create_chimera_attributes_tip = Set Chimera residue attributes for visible features
+label.attributes_set = {0} attribute values set on Chimera
label.sort_alignment_by_tree = Sort Alignment By Tree
label.mark_unlinked_leaves = Mark Unlinked Leaves
label.associate_leaves_with = Associate Leaves With
label.standard_databases = Bases de datos estándar
label.fetch_embl_uniprot = Recuperar de EMBL/EMBLCDS o Uniprot/PDB y de cualquier fuente DAS seleccionada
label.reset_min_max_colours_to_defaults = Reiniciar los colores min y max colours a los valores por defecto establecidos en las preferencias de usuario
-label.align_structures_using_linked_alignment_views = Alinear las estructuras utlizando las {0} vistas de alineamiento enlazadas
+label.align_structures_using_linked_alignment_views = Alinear las estructuras utilizando las {0} vista(s) de alineamiento enlazada(s)
label.connect_to_session = Conectar a la sesión {0}
label.threshold_feature_display_by_score = Filtrar la característica mostrada por puntuación.
label.threshold_feature_no_threshold = Sin umbral
import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.MessageManager;
import java.awt.Color;
import java.awt.Container;
import java.net.URL;
import java.security.AccessControlException;
import java.util.ArrayList;
+import java.util.BitSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
}
/**
- * Construct and send a command to align structures against a reference
- * structure, based on one or more sequence alignments
- *
- * @param _alignment
- * an array of alignments to process
- * @param _refStructure
- * an array of corresponding reference structures (index into pdb
- * file array); if a negative value is passed, the first PDB file
- * mapped to an alignment sequence is used as the reference for
- * superposition
- * @param _hiddenCols
- * an array of corresponding hidden columns for each alignment
+ * {@inheritDoc}
*/
@Override
- public void superposeStructures(AlignmentI[] _alignment,
+ public String superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
while (viewer.isScriptExecuting())
String[] files = getPdbFile();
if (!waitForFileLoad(files))
{
- return;
+ return null;
}
StringBuilder selectioncom = new StringBuilder(256);
nSeconds = " " + (2.0 / files.length) + " ";
// if (nSeconds).substring(0,5)+" ";
}
+
// see JAL-1345 - should really automatically turn off the animation for
// large numbers of structures, but Jmol doesn't seem to allow that.
// nSeconds = " ";
}
/*
- * 'matched' array will hold 'true' for visible alignment columns where
+ * 'matched' bit j will be set for visible alignment columns j where
* all sequences have a residue with a mapping to the PDB structure
*/
- // TODO could use a BitSet for matched
- boolean matched[] = new boolean[alignment.getWidth()];
- for (int m = 0; m < matched.length; m++)
+ BitSet matched = new BitSet();
+ for (int m = 0; m < alignment.getWidth(); m++)
{
- matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
+ if (hiddenCols == null || hiddenCols.isVisible(m))
+ {
+ matched.set(m);
+ }
}
SuperposeData[] structures = new SuperposeData[files.length];
}
String[] selcom = new String[files.length];
- int nmatched = 0;
- for (boolean b : matched)
- {
- if (b)
- {
- nmatched++;
- }
- }
+ int nmatched = matched.cardinality();
if (nmatched < 4)
{
- // TODO: bail out here because superposition illdefined?
+ return (MessageManager.formatMessage(
+"label.insufficient_residues",
+ nmatched));
}
/*
boolean run = false;
StringBuilder molsel = new StringBuilder();
molsel.append("{");
- for (int r = 0; r < matched.length; r++)
+
+ int nextColumnMatch = matched.nextSetBit(0);
+ while (nextColumnMatch != -1)
{
- if (matched[r])
+ int pdbResNo = structures[pdbfnum].pdbResNo[nextColumnMatch];
+ if (lpos != pdbResNo - 1)
{
- int pdbResNo = structures[pdbfnum].pdbResNo[r];
- if (lpos != pdbResNo - 1)
+ // discontinuity
+ if (lpos != -1)
{
- // discontinuity
- if (lpos != -1)
- {
- molsel.append(lpos);
- molsel.append(chainCd);
- molsel.append("|");
- }
- run = false;
+ molsel.append(lpos);
+ molsel.append(chainCd);
+ molsel.append("|");
}
- else
+ run = false;
+ }
+ else
+ {
+ // continuous run - and lpos >-1
+ if (!run)
{
- // continuous run - and lpos >-1
- if (!run)
- {
- // at the beginning, so add dash
- molsel.append(lpos);
- molsel.append("-");
- }
- run = true;
+ // at the beginning, so add dash
+ molsel.append(lpos);
+ molsel.append("-");
}
- lpos = pdbResNo;
+ run = true;
}
+ lpos = pdbResNo;
+ nextColumnMatch = matched.nextSetBit(nextColumnMatch + 1);
}
/*
* add final selection phrase
+ selectioncom.toString() + "); cartoons; ");
// evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
}
+
+ return null;
}
public void evalStateCommand(String command)
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SearchResultMatchI;
-import jalview.datamodel.SearchResults;
+import jalview.datamodel.SearchResultsI;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.httpserver.AbstractRequestHandler;
import java.io.PrintWriter;
import java.net.BindException;
import java.util.ArrayList;
+import java.util.BitSet;
import java.util.Collections;
import java.util.Hashtable;
import java.util.LinkedHashMap;
}
/**
- * Construct and send a command to align structures against a reference
- * structure, based on one or more sequence alignments
- *
- * @param _alignment
- * an array of alignments to process
- * @param _refStructure
- * an array of corresponding reference structures (index into pdb
- * file array); if a negative value is passed, the first PDB file
- * mapped to an alignment sequence is used as the reference for
- * superposition
- * @param _hiddenCols
- * an array of corresponding hidden columns for each alignment
+ * {@inheritDoc}
*/
@Override
- public void superposeStructures(AlignmentI[] _alignment,
+ public String superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
StringBuilder allComs = new StringBuilder(128);
if (!waitForFileLoad(files))
{
- return;
+ return null;
}
refreshPdbEntries();
}
/*
- * 'matched' array will hold 'true' for visible alignment columns where
+ * 'matched' bit i will be set for visible alignment columns i where
* all sequences have a residue with a mapping to the PDB structure
*/
- boolean matched[] = new boolean[alignment.getWidth()];
- for (int m = 0; m < matched.length; m++)
+ BitSet matched = new BitSet();
+ for (int m = 0; m < alignment.getWidth(); m++)
{
- matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
+ if (hiddenCols == null || hiddenCols.isVisible(m))
+ {
+ matched.set(m);
+ }
}
SuperposeData[] structures = new SuperposeData[files.length];
refStructure = candidateRefStructure;
}
- int nmatched = 0;
- for (boolean b : matched)
- {
- if (b)
- {
- nmatched++;
- }
- }
+ int nmatched = matched.cardinality();
if (nmatched < 4)
{
- // TODO: bail out here because superposition illdefined?
+ return MessageManager.formatMessage("label.insufficient_residues",
+ nmatched);
}
/*
int lpos = -1;
boolean run = false;
StringBuilder molsel = new StringBuilder();
- for (int r = 0; r < matched.length; r++)
+
+ int nextColumnMatch = matched.nextSetBit(0);
+ while (nextColumnMatch != -1)
{
- if (matched[r])
+ int pdbResNum = structures[pdbfnum].pdbResNo[nextColumnMatch];
+ if (lpos != pdbResNum - 1)
{
- int pdbResNum = structures[pdbfnum].pdbResNo[r];
- if (lpos != pdbResNum - 1)
+ /*
+ * discontiguous - append last residue now
+ */
+ if (lpos != -1)
{
- /*
- * discontiguous - append last residue now
- */
- if (lpos != -1)
- {
- molsel.append(String.valueOf(lpos));
- molsel.append(chainCd);
- molsel.append(",");
- }
- run = false;
+ molsel.append(String.valueOf(lpos));
+ molsel.append(chainCd);
+ molsel.append(",");
}
- else
+ run = false;
+ }
+ else
+ {
+ /*
+ * extending a contiguous run
+ */
+ if (!run)
{
/*
- * extending a contiguous run
+ * start the range selection
*/
- if (!run)
- {
- /*
- * start the range selection
- */
- molsel.append(String.valueOf(lpos));
- molsel.append("-");
- }
- run = true;
+ molsel.append(String.valueOf(lpos));
+ molsel.append("-");
}
- lpos = pdbResNum;
+ run = true;
}
+ lpos = pdbResNum;
+ nextColumnMatch = matched.nextSetBit(nextColumnMatch + 1);
}
/*
.append(";" + command.toString());
}
}
+
+ String error = null;
if (selectioncom.length() > 0)
{
// TODO: visually distinguish regions that were superposed
}
allComs.append("; ~display all; chain @CA|P; ribbon ")
.append(selectioncom.toString()).append("; focus");
- sendChimeraCommand(allComs.toString(), false);
+ List<String> chimeraReplies = sendChimeraCommand(allComs.toString(),
+ true);
+ for (String reply : chimeraReplies)
+ {
+ if (reply.toLowerCase().contains("unequal numbers of atoms"))
+ {
+ error = reply;
+ }
+ }
}
-
+ return error;
}
/**
* features visible in Jalview
*
* @param avp
+ * @return
*/
- public void sendFeaturesToViewer(AlignmentViewPanel avp)
+ public int sendFeaturesToViewer(AlignmentViewPanel avp)
{
// TODO refactor as required to pull up to an interface
AlignmentI alignment = avp.getAlignment();
*/
if (fr == null)
{
- return;
+ return 0;
}
String[] files = getPdbFile();
if (files == null)
{
- return;
+ return 0;
}
StructureMappingcommandSet commandSet = ChimeraCommands
sendAsynchronousCommand(command, null);
}
}
+ return commands.length;
}
/**
/*
* locate the mapped position in the alignment (if any)
*/
- SearchResults sr = getSsm()
+ SearchResultsI sr = getSsm()
.findAlignmentPositionsForStructurePositions(atoms);
/*
private Random random = new Random();
+ private int myWidth = 500;
+
+ private int myHeight = 150;
+
/**
* Initialise menu options.
*/
*/
protected void sendFeaturesToChimera()
{
- jmb.sendFeaturesToViewer(getAlignmentPanel());
+ int count = jmb.sendFeaturesToViewer(getAlignmentPanel());
+ statusBar.setText(MessageManager.formatMessage("label.attributes_set",
+ count));
}
/**
useAlignmentPanelForSuperposition(ap);
}
jmb.setColourBySequence(true);
- setSize(400, 400); // probably should be a configurable/dynamic default here
+ setSize(myWidth, myHeight);
initMenus();
addingStructures = false;
}
/**
- * Override superclass method to make the 'Chimera' menu always visible, but
- * 'Superpose with...' only enabled if there is more than one structure shown
+ * Sends commands to align structures according to associated alignment(s).
+ *
+ * @return
*/
@Override
- public void updateTitleAndMenus()
+ protected String alignStructs_withAllAlignPanels()
{
- super.updateTitleAndMenus();
- viewerActionMenu.setVisible(true);
- viewSelectionMenu.setEnabled(false);
- if (getBinding().getPdbFile().length > 1
- && getBinding().getSequence().length > 1)
+ String reply = super.alignStructs_withAllAlignPanels();
+ if (reply != null)
{
- viewSelectionMenu.setEnabled(true);
+ statusBar.setText("Superposition failed: " + reply);
}
+ return reply;
}
}
public void itemStateChanged(ItemEvent e)
{
alignStructs.setEnabled(!_alignwith.isEmpty());
- alignStructs
- .setToolTipText(MessageManager
- .getString("label.align_structures_using_linked_alignment_views"));
+ alignStructs.setToolTipText(MessageManager.formatMessage(
+ "label.align_structures_using_linked_alignment_views",
+ _alignwith.size()));
}
};
viewSelectionMenu = new ViewSelectionMenu(
public void setJalviewColourScheme(ColourSchemeI cs) {
getBinding().setJalviewColourScheme(cs);
}
+
+ /**
+ * Sends commands to the structure viewer to superimpose structures based on
+ * currently associated alignments. May optionally return an error message for
+ * the operation.
+ */
@Override
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
+ protected String alignStructs_actionPerformed(
+ ActionEvent actionEvent)
{
- alignStructs_withAllAlignPanels();
+ return alignStructs_withAllAlignPanels();
}
- protected void alignStructs_withAllAlignPanels()
+
+ protected String alignStructs_withAllAlignPanels()
{
if (getAlignmentPanel() == null)
{
- return;
+ return null;
}
if (_alignwith.size() == 0)
_alignwith.add(getAlignmentPanel());
}
+ String reply = null;
try
{
AlignmentI[] als = new Alignment[_alignwith.size()];
alm[a] = -1;
alc[a++] = ap.av.getColumnSelection();
}
- getBinding().superposeStructures(als, alm, alc);
+ reply = getBinding().superposeStructures(als, alm, alc);
+ if (reply != null)
+ {
+ String text = MessageManager.formatMessage(
+ "error.superposition_failed", reply);
+ statusBar.setText(text);
+ }
} catch (Exception e)
{
StringBuffer sp = new StringBuffer();
Cache.log.info("Couldn't align structures with the " + sp.toString()
+ "associated alignment panels.", e);
}
+ return reply;
}
+
@Override
public void background_actionPerformed(ActionEvent actionEvent)
{
}
protected abstract String getViewerName();
+
+ /**
+ * Configures the title and menu items of the viewer panel.
+ */
public void updateTitleAndMenus()
{
AAStructureBindingModel binding = getBinding();
setChainMenuItems(binding.getChainNames());
this.setTitle(binding.getViewerTitle(getViewerName(), true));
- if (binding.getPdbFile().length > 1 && binding.getSequence().length > 1)
+
+ /*
+ * enable 'Superpose with' if more than one mapped structure
+ */
+ viewSelectionMenu.setEnabled(false);
+ if (getBinding().getPdbFile().length > 1
+ && getBinding().getSequence().length > 1)
{
- viewerActionMenu.setVisible(true);
+ viewSelectionMenu.setEnabled(true);
}
+
+ /*
+ * Show action menu if it has any enabled items
+ */
+ viewerActionMenu.setVisible(false);
+ for (int i = 0; i < viewerActionMenu.getItemCount(); i++)
+ {
+ if (viewerActionMenu.getItem(i).isEnabled())
+ {
+ viewerActionMenu.setVisible(true);
+ break;
+ }
+ }
+
if (!binding.isLoadingFromArchive())
{
seqColour_actionPerformed(null);
{
}
- protected void alignStructs_actionPerformed(ActionEvent actionEvent)
- {
- }
+ protected abstract String alignStructs_actionPerformed(
+ ActionEvent actionEvent);
public void pdbFile_actionPerformed(ActionEvent actionEvent)
{
* @param atoms
* @return
*/
- public SearchResults findAlignmentPositionsForStructurePositions(
+ public SearchResultsI findAlignmentPositionsForStructurePositions(
List<AtomSpec> atoms)
{
- SearchResults results = new SearchResults();
+ SearchResultsI results = new SearchResults();
for (AtomSpec atom : atoms)
{
SequenceI lastseq = null;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.BitSet;
import java.util.List;
/**
* the sequence alignment which is the basis of structure
* superposition
* @param matched
- * an array of booleans, indexed by alignment column, where true
- * indicates that every structure has a mapped residue present in the
- * column (so the column can participate in structure alignment)
+ * a BitSet, where bit j is set to indicate that every structure has
+ * a mapped residue present in column j (so the column can
+ * participate in structure alignment)
* @param structures
* an array of data beans corresponding to pdb file index
* @return
*/
protected int findSuperposableResidues(AlignmentI alignment,
- boolean[] matched, SuperposeData[] structures)
+ BitSet matched, SuperposeData[] structures)
{
int refStructure = -1;
String[] files = getPdbFile();
{
refStructure = pdbfnum;
}
- for (int r = 0; r < matched.length; r++)
+ for (int r = 0; r < alignment.getWidth(); r++)
{
- if (!matched[r])
+ if (!matched.get(r))
{
continue;
}
int pos = getMappedPosition(theSequence, r, mapping);
if (pos < 1 || pos == lastPos)
{
- matched[r] = false;
+ matched.clear(r);
continue;
}
lastPos = pos;
public abstract void setJalviewColourScheme(ColourSchemeI cs);
- public abstract void superposeStructures(AlignmentI[] als, int[] alm,
- ColumnSelection[] alc);
+ /**
+ * Constructs and sends a command to align structures against a reference
+ * structure, based on one or more sequence alignments. May optionally return
+ * an error or warning message for the alignment command.
+ *
+ * @param alignments
+ * an array of alignments to process
+ * @param structureIndices
+ * an array of corresponding reference structures (index into pdb
+ * file array); if a negative value is passed, the first PDB file
+ * mapped to an alignment sequence is used as the reference for
+ * superposition
+ * @param hiddenCols
+ * an array of corresponding hidden columns for each alignment
+ * @return
+ */
+ public abstract String superposeStructures(AlignmentI[] alignments, int[] structureIndices,
+ ColumnSelection[] hiddenCols);
public abstract void setBackgroundColour(Color col);
import java.awt.Color;
import java.util.Arrays;
+import java.util.BitSet;
import java.util.List;
import org.testng.annotations.BeforeClass;
}
@Override
- public void superposeStructures(AlignmentI[] als, int[] alm,
+ public String superposeStructures(AlignmentI[] als, int[] alm,
ColumnSelection[] alc)
{
+ return null;
}
@Override
structs[i] = testee.new SuperposeData(al.getWidth());
}
/*
- * initialise array of 'superposable columns' to true (would be false for
+ * initialise BitSet of 'superposable columns' to true (would be false for
* hidden columns)
*/
- boolean[] matched = new boolean[al.getWidth()];
- Arrays.fill(matched, true);
+ BitSet matched = new BitSet();
+ for (int i = 0; i < al.getWidth(); i++)
+ {
+ matched.set(i);
+ }
int refStructure = testee
.findSuperposableResidues(al, matched, structs);
/*
* only ungapped, structure-mapped columns are superposable
*/
- assertFalse(matched[0]); // gap in first sequence
- assertTrue(matched[1]);
- assertFalse(matched[2]); // gap in third sequence
- assertFalse(matched[3]); // gap in fourth sequence
- assertTrue(matched[4]);
- assertTrue(matched[5]); // gap in second sequence
+ assertFalse(matched.get(0)); // gap in first sequence
+ assertTrue(matched.get(1));
+ assertFalse(matched.get(2)); // gap in third sequence
+ assertFalse(matched.get(3)); // gap in fourth sequence
+ assertTrue(matched.get(4));
+ assertTrue(matched.get(5)); // gap in second sequence
assertEquals("1YCS", structs[0].pdbId);
assertEquals("3A6S", structs[1].pdbId);
structs[i] = testee.new SuperposeData(al.getWidth());
}
/*
- * initialise array of 'superposable columns' to true (would be false for
+ * initialise BitSet of 'superposable columns' to true (would be false for
* hidden columns)
*/
- boolean[] matched = new boolean[al.getWidth()];
- Arrays.fill(matched, true);
+ BitSet matched = new BitSet();
+ for (int i = 0; i < al.getWidth(); i++)
+ {
+ matched.set(i);
+ }
+
// treat column 5 of the alignment as hidden
- matched[4] = false;
+ matched.clear(4);
int refStructure = testee
.findSuperposableResidues(al, matched, structs);
assertEquals(0, refStructure);
// only ungapped, structure-mapped columns are not superposable
- assertFalse(matched[0]);
- assertTrue(matched[1]);
- assertFalse(matched[2]);
- assertFalse(matched[3]);
- assertFalse(matched[4]); // superposable, but hidden, column
- assertTrue(matched[5]);
+ assertFalse(matched.get(0));
+ assertTrue(matched.get(1));
+ assertFalse(matched.get(2));
+ assertFalse(matched.get(3));
+ assertFalse(matched.get(4)); // superposable, but hidden, column
+ assertTrue(matched.get(5));
}
public FeatureRenderer getFeatureRenderer(AlignmentViewPanel alignment)