+ /*
+ * (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)