import jalview.appletgui.FeatureSettings;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AlignmentOrder;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.Sequence;
// The following public methods maybe called
// externally, eg via javascript in HTML page
/**
- * @return String list of selected sequence IDs, each terminated by the 'boolean not' character (""+0x00AC) or
- * (¬)
+ * @return String list of selected sequence IDs, each terminated by the
+ * 'boolean not' character (""+0x00AC) or (¬)
*/
public String getSelectedSequences()
{
/**
* @param sep
* separator string or null for default
- * @return String list of selected sequence IDs, each terminated by given separator string
+ * @return String list of selected sequence IDs, each terminated by given
+ * separator string
*/
public String getSelectedSequences(String sep)
{
/**
* @param alf
* alignframe containing selection
- * @return String list of selected sequence IDs, each terminated by current default separator sequence
+ * @return String list of selected sequence IDs, each terminated by current
+ * default separator sequence
*
*/
public String getSelectedSequencesFrom(AlignFrame alf)
{
- return getSelectedSequencesFrom(alf,separator); // ""+0x00AC);
+ return getSelectedSequencesFrom(alf, separator); // ""+0x00AC);
}
/**
public void highlight(String sequenceId, String position,
String alignedPosition)
{
- highlightIn(getDefaultTargetFrame(), sequenceId, position, alignedPosition);
+ highlightIn(getDefaultTargetFrame(), sequenceId, position,
+ alignedPosition);
}
/**
* false, blank or something else - indicate if position is an
* alignment column or unaligned sequence position
*/
- public void highlightIn(AlignFrame alf, String sequenceId, String position,
- String alignedPosition)
+ public void highlightIn(AlignFrame alf, String sequenceId,
+ String position, String alignedPosition)
{
// TODO: could try to highlight in all alignments if alf==null
- SequenceI sq = alf.getAlignViewport().getAlignment()
- .findName(sequenceId);
+ jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+ alf.viewport.getAlignment().getSequencesArray());
+ SequenceI sq = matcher.findIdMatch(sequenceId);
if (sq != null)
{
int pos, apos = -1;
if (sep == null || sep.length() == 0)
{
sep = separator;
- } else {
+ }
+ else
+ {
if (debug)
{
- System.err.println("Selecting region using separator string '"+separator+"'");
+ System.err.println("Selecting region using separator string '"
+ + separator + "'");
}
}
// deparse fields
SequenceGroup sel = new SequenceGroup();
ColumnSelection csel = new ColumnSelection();
AlignmentI al = alf.viewport.getAlignment();
+ jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+ alf.viewport.getAlignment().getSequencesArray());
int start = 0, end = al.getWidth(), alw = al.getWidth();
+ boolean seqsfound = true;
if (ids != null && ids.length > 0)
{
+ seqsfound = false;
for (int i = 0; i < ids.length; i++)
{
if (ids[i].trim().length() == 0)
{
continue;
}
- SequenceI sq = al.findName(ids[i]);
+ SequenceI sq = matcher.findIdMatch(ids[i]);
if (sq != null)
{
+ seqsfound = true;
sel.addSequence(sq, false);
}
}
}
+ boolean inseqpos = false;
if (cols != null && cols.length > 0)
{
boolean seset = false;
r--;
} catch (NumberFormatException ex)
{
- System.err
- .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
- + cl + "'");
- return;
+ if (cl.toLowerCase().equals("sequence"))
+ {
+ // we are in the dataset sequence's coordinate frame.
+ inseqpos = true;
+ }
+ else
+ {
+ System.err
+ .println("ERROR: Couldn't parse integer from point selection element of column selection string '"
+ + cl + "'");
+ return;
+ }
}
if (r >= 0 && r <= alw)
{
}
}
}
- sel.setStartRes(start);
- sel.setEndRes(end);
- alf.select(sel, csel);
-
+ if (seqsfound)
+ {
+ // we only propagate the selection when it was the null selection, or the
+ // given sequences were found in the alignment.
+ if (inseqpos && sel.getSize() > 0)
+ {
+ // assume first sequence provides reference frame ?
+ SequenceI rs = sel.getSequenceAt(0);
+ start = rs.findIndex(start);
+ end = rs.findIndex(end);
+ if (csel != null)
+ {
+ Vector cs = csel.getSelected();
+ csel.clear();
+ for (int csi = 0, csiS = cs.size(); csi < csiS; csi++)
+ {
+ csel.addElement(rs.findIndex(((Integer) cs.elementAt(csi))
+ .intValue()));
+ }
+ }
+ }
+ sel.setStartRes(start);
+ sel.setEndRes(end);
+ alf.select(sel, csel);
+ }
}
/**
*/
public String getSelectedSequencesAsAlignment(String format, String suffix)
{
- return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(), format,
- suffix);
+ return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
+ format, suffix);
}
/**
return "";
}
+ public String getAlignmentOrder()
+ {
+ return getAlignmentOrderFrom(getDefaultTargetFrame());
+ }
+
+ public String getAlignmentOrderFrom(AlignFrame alf)
+ {
+ return getAlignmentOrderFrom(alf, separator);
+ }
+
+ public String getAlignmentOrderFrom(AlignFrame alf, String sep)
+ {
+ AlignmentI alorder = alf.getAlignViewport().getAlignment();
+ String[] order = new String[alorder.getHeight()];
+ for (int i = 0; i < order.length; i++)
+ {
+ order[i] = alorder.getSequenceAt(i).getName();
+ }
+ return arrayToSeparatorList(order);
+ }
+
+ public String orderBy(String order, String undoName)
+ {
+ return orderBy(order, undoName, separator);
+ }
+
+ public String orderBy(String order, String undoName, String sep)
+ {
+ return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
+ }
+
+ public String orderAlignmentBy(AlignFrame alf, String order,
+ String undoName, String sep)
+ {
+ String[] ids = separatorListToArray(order, sep);
+ SequenceI[] sqs = null;
+ if (ids != null && ids.length > 0)
+ {
+ jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+ alf.viewport.getAlignment().getSequencesArray());
+ int s = 0;
+ sqs = new SequenceI[ids.length];
+ for (int i = 0; i < ids.length; i++)
+ {
+ if (ids[i].trim().length() == 0)
+ {
+ continue;
+ }
+ SequenceI sq = matcher.findIdMatch(ids[i]);
+ if (sq != null)
+ {
+ sqs[s++] = sq;
+ }
+ }
+ if (s > 0)
+ {
+ SequenceI[] sqq = new SequenceI[s];
+ System.arraycopy(sqs, 0, sqq, 0, s);
+ sqs = sqq;
+ }
+ else
+ {
+ sqs = null;
+ }
+ }
+ if (sqs == null)
+ {
+ return "";
+ }
+ ;
+ AlignmentOrder aorder = new AlignmentOrder(sqs);
+
+ if (undoName != null && undoName.trim().length() == 0)
+ {
+ undoName = null;
+ }
+
+ return alf.sortBy(aorder, undoName) ? "true" : "";
+ }
+
public String getAlignment(String format)
{
return getAlignmentFrom(getDefaultTargetFrame(), format, "true");
{
if (debug)
{
- System.err.println("Applet context is '"+getAppletContext().getClass().toString()+"'");
+ System.err.println("Applet context is '"
+ + getAppletContext().getClass().toString() + "'");
}
JSObject scriptObject = JSObject.getWindow(this);
- if (debug && scriptObject!=null)
+ if (debug && scriptObject != null)
{
System.err.println("Applet has Javascript callback support.");
}
-
+
} catch (Exception ex)
{
System.err
- .println("Warning: No JalviewLite javascript callbacks available.");
+ .println("Warning: No JalviewLite javascript callbacks available.");
if (debug)
{
ex.printStackTrace();
}
setBackground(new Color(r, g, b));
-
+
file = getParameter("file");
if (file == null)
else if (file != null)
{
if (getParameter("showbutton") == null
- || !getParameter("showbutton").equalsIgnoreCase(
- "false"))
+ || !getParameter("showbutton").equalsIgnoreCase("false"))
{
// Add the JalviewLite 'Button' to the page
add(launcher);
initjscallback = initjscallback.trim();
if (initjscallback.length() > 0)
{
- JSObject scriptObject = null;
- try {
+ JSObject scriptObject = null;
+ try
+ {
scriptObject = JSObject.getWindow(this);
- } catch (Exception ex) {};
+ } catch (Exception ex)
+ {
+ }
+ ;
if (scriptObject != null)
{
try
{
// do onInit with the JS executor thread
new JSFunctionExec(this).executeJavascriptFunction(true,
- initjscallback, null, "Calling oninit callback '" + initjscallback
- + "'.");
+ initjscallback, null, "Calling oninit callback '"
+ + initjscallback + "'.");
} catch (Exception e)
{
System.err.println("Exception when executing _oninit callback '"
g.drawString("Loading Data...", 50, getSize().height / 2);
}
}
+
/**
* get all components associated with the applet of the given type
*
/**
* separator used for separatorList
*/
- protected String separator = ""+((char)0x00AC); // the default used to be '|' but many sequence IDS include pipes.
-
+ protected String separator = "" + ((char) 0x00AC); // the default used to be
+ // '|' but many sequence
+ // IDS include pipes.
+
/**
* parse the string into a list
*
*/
public void setSeparator(String separator)
{
- if (separator==null || separator.length()<1)
+ if (separator == null || separator.length() < 1)
{
// reset to default
- separator = ""+((char)0x00AC);
+ separator = "" + ((char) 0x00AC);
}
this.separator = separator;
if (debug)
{
- System.err.println("Default Separator now: '"+separator+"'");
+ System.err.println("Default Separator now: '" + separator + "'");
}
}