1 package jalview.ws.rest.params;
3 import jalview.datamodel.AlignmentI;
4 import jalview.datamodel.SequenceGroup;
5 import jalview.datamodel.SequenceI;
6 import jalview.ws.rest.AlignmentProcessor;
7 import jalview.ws.rest.InputType;
8 import jalview.ws.rest.NoValidInputDataException;
9 import jalview.ws.rest.RestJob;
10 import jalview.ws.rest.InputType.molType;
12 import java.io.UnsupportedEncodingException;
13 import java.util.ArrayList;
14 import java.util.Vector;
16 import org.apache.http.entity.mime.content.ContentBody;
17 import org.apache.http.entity.mime.content.StringBody;
20 * Represents the partitions defined on the alignment as indices
21 * e.g. for a partition (A,B,C),(D,E),(F)
22 * The indices would be 3,2,1. Note, the alignment must be ordered so groups are contiguous before this input type can be used.
26 public class SeqGroupIndexVector extends InputType implements AlignmentProcessor{
27 public SeqGroupIndexVector()
29 super(new Class[] { AlignmentI.class} );
32 * separator for list of sequence Indices - default is ','
34 public String sep=",";
37 * prepare the context alignment for this input
38 * @param al - alignment to be processed
39 * @return al or a new alignment with appropriate attributes/order for input
41 public AlignmentI prepareAlignment(AlignmentI al)
43 jalview.analysis.AlignmentSorter.sortByGroup(al);
47 public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException
49 StringBuffer idvector = new StringBuffer();
51 AlignmentI al = rj.getAlignmentForInput(token, type);
52 // assume that alignment is properly ordered so groups form consecutive blocks
53 ArrayList<int[]> gl = new ArrayList<int[]>();
54 for (SequenceGroup sg : (Vector<SequenceGroup>)al.getGroups())
56 // TODO: refactor to sequenceGroup for efficiency - getAlignmentRowInterval(AlignmentI al)
58 for (SequenceI sq: sg.getSequencesInOrder(al))
60 int p = al.findIndex(sq);
77 int[][] vals = gl.toArray(new int[gl.size()][]);
78 int[] srt = new int[gl.size()];
79 for (int i=0;i<vals.length;i++)
81 jalview.util.QuickSort.sort(srt, vals);
83 int last=vals[0][0]-1;
84 for (int[] range:vals)
91 idvector.append(range[1]-last);
96 return new StringBody(idvector.toString());