+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#highlight(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public void highlight(String sequenceId, String position,
+ String alignedPosition)
+ {
+ highlightIn(getDefaultTargetFrame(), sequenceId, position,
+ alignedPosition);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#highlightIn(jalview.appletgui.AlignFrame,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void highlightIn(final AlignFrame alf, final String sequenceId,
+ final String position, final String alignedPosition)
+ {
+ // TODO: could try to highlight in all alignments if alf==null
+ jalview.analysis.SequenceIdMatcher matcher = new jalview.analysis.SequenceIdMatcher(
+ alf.viewport.getAlignment().getSequencesArray());
+ final SequenceI sq = matcher.findIdMatch(sequenceId);
+ if (sq != null)
+ {
+ int apos = -1;
+ try
+ {
+ apos = new Integer(position).intValue();
+ apos--;
+ } catch (NumberFormatException ex)
+ {
+ return;
+ }
+ final StructureSelectionManagerProvider me = this;
+ final int pos = apos;
+ // use vamsas listener to broadcast to all listeners in scope
+ if (alignedPosition != null
+ && (alignedPosition.trim().length() == 0 || alignedPosition
+ .toLowerCase().indexOf("false") > -1))
+ {
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ StructureSelectionManager.getStructureSelectionManager(me)
+ .mouseOverVamsasSequence(sq, sq.findIndex(pos), null);
+ }
+ });
+ }
+ else
+ {
+ java.awt.EventQueue.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ StructureSelectionManager.getStructureSelectionManager(me)
+ .mouseOverVamsasSequence(sq, pos, null);
+ }
+ });
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
+ * java.lang.String)
+ */
+ public void select(String sequenceIds, String columns)
+ {
+ selectIn(getDefaultTargetFrame(), sequenceIds, columns, separator);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#select(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public void select(String sequenceIds, String columns, String sep)
+ {
+ selectIn(getDefaultTargetFrame(), sequenceIds, columns, sep);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
+ * java.lang.String, java.lang.String)
+ */
+ public void selectIn(AlignFrame alf, String sequenceIds, String columns)
+ {
+ selectIn(alf, sequenceIds, columns, separator);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#selectIn(jalview.appletgui.AlignFrame,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void selectIn(final AlignFrame alf, String sequenceIds,
+ String columns, String sep)
+ {
+ if (sep == null || sep.length() == 0)
+ {
+ sep = separator;
+ }
+ else
+ {
+ if (debug)
+ {
+ System.err.println("Selecting region using separator string '"
+ + separator + "'");
+ }
+ }
+ // deparse fields
+ String[] ids = separatorListToArray(sequenceIds, sep);
+ String[] cols = separatorListToArray(columns, sep);
+ final SequenceGroup sel = new SequenceGroup();
+ final 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 = 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;
+ for (int i = 0; i < cols.length; i++)
+ {
+ String cl = cols[i].trim();
+ if (cl.length() == 0)
+ {
+ continue;
+ }
+ int p;
+ if ((p = cl.indexOf("-")) > -1)
+ {
+ int from = -1, to = -1;
+ try
+ {
+ from = new Integer(cl.substring(0, p)).intValue();
+ from--;
+ } catch (NumberFormatException ex)
+ {
+ System.err
+ .println("ERROR: Couldn't parse first integer in range element column selection string '"
+ + cl + "' - format is 'from-to'");
+ return;
+ }
+ try
+ {
+ to = new Integer(cl.substring(p + 1)).intValue();
+ to--;
+ } catch (NumberFormatException ex)
+ {
+ System.err
+ .println("ERROR: Couldn't parse second integer in range element column selection string '"
+ + cl + "' - format is 'from-to'");
+ return;
+ }
+ if (from >= 0 && to >= 0)
+ {
+ // valid range
+ if (from < to)
+ {
+ int t = to;
+ to = from;
+ to = t;
+ }
+ if (!seset)
+ {
+ start = from;
+ end = to;
+ seset = true;
+ }
+ else
+ {
+ // comment to prevent range extension
+ if (start > from)
+ {
+ start = from;
+ }
+ if (end < to)
+ {
+ end = to;
+ }
+ }
+ for (int r = from; r <= to; r++)
+ {
+ if (r >= 0 && r < alw)
+ {
+ csel.addElement(r);
+ }
+ }
+ if (debug)
+ {
+ System.err.println("Range '" + cl + "' deparsed as [" + from
+ + "," + to + "]");
+ }
+ }
+ else
+ {
+ System.err.println("ERROR: Invalid Range '" + cl
+ + "' deparsed as [" + from + "," + to + "]");
+ }
+ }
+ else
+ {
+ int r = -1;
+ try
+ {
+ r = new Integer(cl).intValue();
+ r--;
+ } catch (NumberFormatException ex)
+ {
+ 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)
+ {
+ if (!seset)
+ {
+ start = r;
+ end = r;
+ seset = true;
+ }
+ else
+ {
+ // comment to prevent range extension
+ if (start > r)
+ {
+ start = r;
+ }
+ if (end < r)
+ {
+ end = r;
+ }
+ }
+ csel.addElement(r);
+ if (debug)
+ {
+ System.err.println("Point selection '" + cl
+ + "' deparsed as [" + r + "]");
+ }
+ }
+ else
+ {
+ System.err.println("ERROR: Invalid Point selection '" + cl
+ + "' deparsed as [" + r + "]");
+ }
+ }
+ }
+ }
+ 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);
+ EventQueue.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ alf.select(sel, csel);
+ }
+ });
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignment(java.lang.
+ * String, java.lang.String)
+ */
+ public String getSelectedSequencesAsAlignment(String format, String suffix)
+ {
+ return getSelectedSequencesAsAlignmentFrom(getDefaultTargetFrame(),
+ format, suffix);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#getSelectedSequencesAsAlignmentFrom(jalview
+ * .appletgui.AlignFrame, java.lang.String, java.lang.String)
+ */
+ public String getSelectedSequencesAsAlignmentFrom(AlignFrame alf,
+ String format, String suffix)
+ {
+ try
+ {
+ boolean seqlimits = suffix.equalsIgnoreCase("true");
+ if (alf.viewport.getSelectionGroup() != null)
+ {
+ // JBPNote: getSelectionAsNewSequence behaviour has changed - this
+ // method now returns a full copy of sequence data
+ // TODO consider using getSequenceSelection instead here
+ String reply = new AppletFormatAdapter().formatSequences(format,
+ new Alignment(alf.viewport.getSelectionAsNewSequence()),
+ seqlimits);
+ return reply;
+ }
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ return "Error retrieving alignment in " + format + " format. ";
+ }
+ return "";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#getAlignmentOrder()
+ */
+ public String getAlignmentOrder()
+ {
+ return getAlignmentOrderFrom(getDefaultTargetFrame());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
+ * )
+ */
+ public String getAlignmentOrderFrom(AlignFrame alf)
+ {
+ return getAlignmentOrderFrom(alf, separator);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#getAlignmentOrderFrom(jalview.appletgui.AlignFrame
+ * , java.lang.String)
+ */
+ 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
+ * java.lang.String)
+ */
+ public String orderBy(String order, String undoName)
+ {
+ return orderBy(order, undoName, separator);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#orderBy(java.lang.String,
+ * java.lang.String, java.lang.String)
+ */
+ public String orderBy(String order, String undoName, String sep)
+ {
+ return orderAlignmentBy(getDefaultTargetFrame(), order, undoName, sep);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * jalview.bin.JalviewLiteJsApi#orderAlignmentBy(jalview.appletgui.AlignFrame,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ 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 "";
+ }
+ ;
+ final AlignmentOrder aorder = new AlignmentOrder(sqs);
+
+ if (undoName != null && undoName.trim().length() == 0)
+ {
+ undoName = null;
+ }
+ final String _undoName = undoName;
+ // TODO: deal with synchronization here: cannot raise any events until after
+ // this has returned.
+ return alf.sortBy(aorder, _undoName) ? "true" : "";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see jalview.bin.JalviewLiteJsApi#getAlignment(java.lang.String)
+ */