import javax.swing.JPanel;
+import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
import jalview.api.SequenceStructureBinding;
public void superposeStructures(AlignmentI alignment, int refStructure,
ColumnSelection hiddenCols)
{
+ superposeStructures(new AlignmentI[]
+ { alignment }, new int[]
+ { refStructure }, new ColumnSelection[]
+ { hiddenCols });
+ }
+
+ public void superposeStructures(AlignmentI[] _alignment,
+ int[] _refStructure, ColumnSelection[] _hiddenCols)
+ {
String[] files = getPdbFile();
- if (refStructure >= files.length)
+ StringBuffer selectioncom = new StringBuffer();
+ assert (_alignment.length == _refStructure.length && _alignment.length != _hiddenCols.length);
+ // union of all aligned positions are collected together.
+ for (int a = 0; a < _alignment.length; a++)
{
- System.err.println("Invalid reference structure value "
- + refStructure);
- refStructure = -1;
- }
- if (refStructure < -1)
- {
- refStructure = -1;
- }
- StringBuffer command = new StringBuffer(), selectioncom = new StringBuffer();
+ int refStructure = _refStructure[a];
+ AlignmentI alignment = _alignment[a];
+ ColumnSelection hiddenCols = _hiddenCols[a];
+ if (a > 0
+ && selectioncom.length() > 0
+ && !selectioncom.substring(selectioncom.length() - 1).equals(
+ "|"))
+ {
+ selectioncom.append("|");
+ }
+ // process this alignment
+ if (refStructure >= files.length)
+ {
+ System.err.println("Invalid reference structure value "
+ + refStructure);
+ refStructure = -1;
+ }
+ if (refStructure < -1)
+ {
+ refStructure = -1;
+ }
+ StringBuffer command = new StringBuffer();
- boolean matched[] = new boolean[alignment.getWidth()];
- for (int m = 0; m < matched.length; m++)
- {
+ boolean matched[] = new boolean[alignment.getWidth()];
+ for (int m = 0; m < matched.length; m++)
+ {
- matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
- }
+ matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
+ }
- int commonrpositions[][] = new int[files.length][alignment.getWidth()];
- String isel[] = new String[files.length];
- // reference structure - all others are superposed in it
- String[] targetC = new String[files.length];
- String[] chainNames = new String[files.length];
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
+ int commonrpositions[][] = new int[files.length][alignment.getWidth()];
+ String isel[] = new String[files.length];
+ // reference structure - all others are superposed in it
+ String[] targetC = new String[files.length];
+ String[] chainNames = new String[files.length];
+ for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
+ {
+ StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
- if (mapping == null || mapping.length < 1)
- continue;
+ if (mapping == null || mapping.length < 1)
+ continue;
- int lastPos = -1;
- for (int s = 0; s < sequence[pdbfnum].length; s++)
- {
- for (int sp, m = 0; m < mapping.length; m++)
+ int lastPos = -1;
+ for (int s = 0; s < sequence[pdbfnum].length; s++)
{
- if (mapping[m].getSequence() == sequence[pdbfnum][s]
- && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
+ for (int sp, m = 0; m < mapping.length; m++)
{
- if (refStructure == -1)
- {
- refStructure = pdbfnum;
- }
- SequenceI asp = alignment.getSequenceAt(sp);
- for (int r = 0; r < matched.length; r++)
+ if (mapping[m].getSequence() == sequence[pdbfnum][s]
+ && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
{
- if (!matched[r])
+ if (refStructure == -1)
{
- continue;
+ refStructure = pdbfnum;
}
- matched[r] = false; // assume this is not a good site
- if (r >= asp.getLength())
+ SequenceI asp = alignment.getSequenceAt(sp);
+ for (int r = 0; r < matched.length; r++)
{
- continue;
- }
+ if (!matched[r])
+ {
+ continue;
+ }
+ matched[r] = false; // assume this is not a good site
+ if (r >= asp.getLength())
+ {
+ continue;
+ }
- if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
+ if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
+ {
+ // no mapping to gaps in sequence
+ continue;
+ }
+ int t = asp.findPosition(r); // sequence position
+ int apos = mapping[m].getAtomNum(t);
+ int pos = mapping[m].getPDBResNum(t);
+
+ if (pos < 1 || pos == lastPos)
+ {
+ // can't align unmapped sequence
+ continue;
+ }
+ matched[r] = true; // this is a good ite
+ lastPos = pos;
+ // just record this residue position
+ commonrpositions[pdbfnum][r] = pos;
+ }
+ // create model selection suffix
+ isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1";
+ if (mapping[m].getChain() == null
+ || mapping[m].getChain().trim().length() == 0)
{
- // no mapping to gaps in sequence
- continue;
+ targetC[pdbfnum] = "";
}
- int t = asp.findPosition(r); // sequence position
- int apos = mapping[m].getAtomNum(t);
- int pos = mapping[m].getPDBResNum(t);
-
- if (pos < 1 || pos == lastPos)
+ else
{
- // can't align unmapped sequence
- continue;
+ targetC[pdbfnum] = ":" + mapping[m].getChain();
}
- matched[r] = true; // this is a good ite
- lastPos = pos;
- // just record this residue position
- commonrpositions[pdbfnum][r] = pos;
- }
- // create model selection suffix
- isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1";
- if (mapping[m].getChain() == null
- || mapping[m].getChain().trim().length() == 0)
- {
- targetC[pdbfnum] = "";
+ chainNames[pdbfnum] = mapping[m].getPdbId()
+ + targetC[pdbfnum];
+ // move on to next pdb file
+ s = sequence[pdbfnum].length;
+ break;
}
- else
- {
- targetC[pdbfnum] = ":" + mapping[m].getChain();
- }
- chainNames[pdbfnum] = mapping[m].getPdbId()+targetC[pdbfnum];
- // move on to next pdb file
- s = sequence[pdbfnum].length;
- break;
}
}
}
- }
- String[] selcom = new String[files.length];
- int nmatched = 0;
- // generate select statements to select regions to superimpose structures
- {
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
+ String[] selcom = new String[files.length];
+ int nmatched = 0;
+ // generate select statements to select regions to superimpose structures
{
- String chainCd = targetC[pdbfnum];
- int lpos = -1;
- boolean run = false;
- StringBuffer molsel = new StringBuffer();
- molsel.append("{");
- for (int r = 0; r < matched.length; r++)
+ for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
- if (matched[r])
+ String chainCd = targetC[pdbfnum];
+ int lpos = -1;
+ boolean run = false;
+ StringBuffer molsel = new StringBuffer();
+ molsel.append("{");
+ for (int r = 0; r < matched.length; r++)
{
- if (pdbfnum == 0)
+ if (matched[r])
{
- nmatched++;
- }
- if (lpos != commonrpositions[pdbfnum][r] - 1)
- {
- // discontinuity
- if (lpos != -1)
+ if (pdbfnum == 0)
{
- molsel.append(lpos);
- molsel.append(chainCd);
- // molsel.append("} {");
- molsel.append("|");
+ nmatched++;
}
- }
- else
- {
- // continuous run - and lpos >-1
- if (!run)
+ if (lpos != commonrpositions[pdbfnum][r] - 1)
+ {
+ // discontinuity
+ if (lpos != -1)
+ {
+ molsel.append(lpos);
+ molsel.append(chainCd);
+ // molsel.append("} {");
+ molsel.append("|");
+ }
+ }
+ else
{
- // at the beginning, so add dash
- molsel.append(lpos);
- molsel.append("-");
+ // continuous run - and lpos >-1
+ if (!run)
+ {
+ // at the beginning, so add dash
+ molsel.append(lpos);
+ molsel.append("-");
+ }
+ run = true;
}
- run = true;
+ lpos = commonrpositions[pdbfnum][r];
+ // molsel.append(lpos);
}
- lpos = commonrpositions[pdbfnum][r];
- // molsel.append(lpos);
+ }
+ // add final selection phrase
+ if (lpos != -1)
+ {
+ molsel.append(lpos);
+ molsel.append(chainCd);
+ molsel.append("}");
+ }
+ selcom[pdbfnum] = molsel.toString();
+ selectioncom.append("((");
+ selectioncom.append(selcom[pdbfnum].substring(1,
+ selcom[pdbfnum].length() - 1));
+ selectioncom.append(" )& ");
+ selectioncom.append(pdbfnum + 1);
+ selectioncom.append(".1)");
+ if (pdbfnum < files.length - 1)
+ {
+ selectioncom.append("|");
}
}
- // add final selection phrase
- if (lpos != -1)
+ }
+ // TODO: consider bailing if nmatched less than 4 because superposition
+ // not
+ // well defined.
+ // TODO: refactor superposable position search (above) from jmol selection
+ // construction (below)
+ for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
+ {
+ if (pdbfnum == refStructure)
{
- molsel.append(lpos);
- molsel.append(chainCd);
- molsel.append("}");
+ continue;
}
- selcom[pdbfnum] = molsel.toString();
- selectioncom.append("((");
- selectioncom.append(selcom[pdbfnum].substring(1,
- selcom[pdbfnum].length() - 1));
- selectioncom.append(" )& ");
- selectioncom.append(pdbfnum + 1);
- selectioncom.append(".1)");
- if (pdbfnum < files.length - 1)
+ command.append("echo ");
+ command.append("\"Superposing (");
+ command.append(chainNames[pdbfnum]);
+ command.append(") against reference (");
+ command.append(chainNames[refStructure]);
+ command.append(")\";\ncompare ");
+ command.append("{");
+ command.append(1 + pdbfnum);
+ command.append(".1} {");
+ command.append(1 + refStructure);
+ command.append(".1} SUBSET {*.CA | *.P} ATOMS ");
+
+ // form the matched pair strings
+ String sep = "";
+ for (int s = 0; s < 2; s++)
{
- selectioncom.append("|");
+ command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
}
+ command.append(" ROTATE TRANSLATE;\n");
}
+ System.out.println("Select regions:\n" + selectioncom.toString());
+ evalStateCommand("select *; cartoons off; backbone; select ("
+ + selectioncom.toString() + "); cartoons; ");
+ // selcom.append("; ribbons; ");
+ System.out.println("Superimpose command(s):\n" + command.toString());
+
+ evalStateCommand(command.toString());
}
- // TODO: consider bailing if nmatched less than 4 because superposition not
- // well defined.
- // TODO: refactor superposable position search (above) from jmol selection
- // construction (below)
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- if (pdbfnum == refStructure)
- {
- continue;
- }
- command.append("echo ");
- command.append("\"Superposing (");
- command.append(chainNames[pdbfnum]);
- command.append(") against reference (");
- command.append(chainNames[refStructure]);
- command.append(")\";\ncompare ");
- command.append("{");
- command.append(1 + pdbfnum);
- command.append(".1} {");
- command.append(1 + refStructure);
- command.append(".1} SUBSET {*.CA | *.P} ATOMS ");
-
- // form the matched pair strings
- String sep = "";
- for (int s = 0; s < 2; s++)
+ if (selectioncom.length() > 0)
+ {// finally, mark all regions that were superposed.
+ if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
{
- command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
+ selectioncom.setLength(selectioncom.length() - 1);
}
- command.append(" ROTATE TRANSLATE;\n");
+ System.out.println("Select regions:\n" + selectioncom.toString());
+ evalStateCommand("select *; cartoons off; backbone; select ("
+ + selectioncom.toString() + "); cartoons; ");
+ // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
}
- System.out.println("Select regions:\n" + selectioncom.toString());
- evalStateCommand("select *; cartoons off; backbone; select ("
- + selectioncom.toString() + "); cartoons; ");
- // selcom.append("; ribbons; ");
- System.out.println("Superimpose command(s):\n" + command.toString());
-
- evalStateCommand(command.toString());
-
- // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
}
public void evalStateCommand(String command)
* using the getFeatureRenderer() and getSequenceRenderer() renderers but only
* if colourBySequence is enabled.
*/
- public void colourBySequence(boolean showFeatures, AlignmentI alignment)
+ public void colourBySequence(boolean showFeatures,
+ jalview.api.AlignmentViewPanel alignmentv)
{
if (!colourBySequence)
return;
return;
}
String[] files = getPdbFile();
- SequenceRenderer sr = getSequenceRenderer();
+
+ SequenceRenderer sr = getSequenceRenderer(alignmentv);
FeatureRenderer fr = null;
if (showFeatures)
{
- fr = getFeatureRenderer();
+ fr = getFeatureRenderer(alignmentv);
}
-
+ AlignmentI alignment = alignmentv.getAlignment();
StringBuffer command = new StringBuffer();
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
* returns the current featureRenderer that should be used to colour the
* structures
*
+ * @param alignment
+ *
* @return
*/
- public abstract FeatureRenderer getFeatureRenderer();
+ public abstract FeatureRenderer getFeatureRenderer(
+ AlignmentViewPanel alignment);
/**
* instruct the Jalview binding to update the pdbentries vector if necessary
* returns the current sequenceRenderer that should be used to colour the
* structures
*
+ * @param alignment
+ *
* @return
*/
- public abstract SequenceRenderer getSequenceRenderer();
+ public abstract SequenceRenderer getSequenceRenderer(
+ AlignmentViewPanel alignment);
// ///////////////////////////////
// JmolStatusListener
public void mouseOverStructure(int atomIndex, String strInfo)
{
int pdbResNum;
+ int alocsep = strInfo.indexOf("^");
int mdlSep = strInfo.indexOf("/");
int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1;
chainSeparator = mdlSep;
}
}
- pdbResNum = Integer.parseInt(strInfo.substring(
- strInfo.indexOf("]") + 1, chainSeparator));
+ // handle insertion codes
+ if (alocsep != -1)
+ {
+ pdbResNum = Integer.parseInt(strInfo.substring(
+ strInfo.indexOf("]") + 1, alocsep));
+ }
+ else
+ {
+ pdbResNum = Integer.parseInt(strInfo.substring(
+ strInfo.indexOf("]") + 1, chainSeparator));
+ }
String chainId;
if (strInfo.indexOf(":") > -1)
ssm.addStructureViewerListener(this);
if (notifyLoaded)
{
- FeatureRenderer fr = getFeatureRenderer();
+ FeatureRenderer fr = getFeatureRenderer(null);
if (fr != null)
{
fr.featuresAdded();