--- /dev/null
+package jalview.rest;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceGroup;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+
+public class SelectSequencesEndpoint extends AbstractEndpoint
+{
+ public SelectSequencesEndpoint(API api)
+ {
+ super(api, path, name, parameters, description);
+ }
+
+ protected static final String path = "selectsequences";
+
+ private static final String name = "Select sequence(s) positions";
+
+ private static final String parameters = "<sequence names>/<range>";
+
+ private static final String description = "Select the specified sequence(s) with the specified range";
+
+ public void processEndpoint(HttpServletRequest request,
+ HttpServletResponse response)
+ {
+ if (!checkParameters(request, response, 2))
+ {
+ return;
+ }
+ String[] parameters = getEndpointPathParameters(request);
+
+ String rangesString = parameters[1];
+ int[][] ranges = parseIntRanges(rangesString);
+ if (ranges == null || ranges.length < 2 || ranges[0].length < 1)
+ {
+ returnError(request, response,
+ "couldn't parse range '" + rangesString + "'");
+ return;
+ }
+ if (ranges[0].length > 1)
+ {
+ returnError(request, response,
+ "only provide 1 range '" + rangesString + "'");
+ return;
+ }
+ int start = ranges[0][0];
+ int end = ranges[1][0];
+
+ String sequenceNamesString = parameters[0];
+ List<String> sequenceNames = Arrays
+ .asList(sequenceNamesString.split(","));
+
+ AlignFrame[] alignFrames = getAlignFrames(request, true);
+ if (alignFrames == null)
+ {
+ returnError(request, response, "could not find results");
+ return;
+ }
+ for (int i = 0; i < alignFrames.length; i++)
+ {
+ AlignFrame af = alignFrames[i];
+ List<AlignmentViewPanel> aps = (List<AlignmentViewPanel>) af
+ .getAlignPanels();
+ for (AlignmentViewPanel ap : aps)
+ {
+ AlignViewportI avp = ap.getAlignViewport();
+ AlignmentI al = ap.getAlignment();
+ List<SequenceI> seqs = (List<SequenceI>) al.getSequences();
+ SequenceGroup stretchGroup = new SequenceGroup();
+ for (SequenceI seq : seqs)
+ {
+ if (sequenceNames.contains(seq.getName())
+ || (sequenceNamesString.equals("*")
+ && alignFrames.length == 1))
+ {
+ stretchGroup.addSequence(seq, false);
+ }
+ }
+ if (start == -1 && end == -1) // "*" as range
+ {
+ stretchGroup.setStartRes(al.getStartRes());
+ stretchGroup.setEndRes(al.getEndRes());
+ }
+ else
+ {
+ stretchGroup.setStartRes(start);
+ stretchGroup.setEndRes(end);
+ }
+ avp.setSelectionGroup(stretchGroup);
+ ap.paintAlignment(false, false);
+ avp.sendSelection();
+ }
+ }
+ }
+}
\ No newline at end of file