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 e.g. for a
21 * partition (A,B,C),(D,E),(F) The indices would be 3,2,1. Note, the alignment
22 * must be ordered so groups are contiguous before this input type can be used.
27 public class SeqGroupIndexVector extends InputType implements
30 public SeqGroupIndexVector()
33 { AlignmentI.class });
37 * separator for list of sequence Indices - default is ','
39 public String sep = ",";
42 * min size of each partition
44 public int minsize = 1;
49 * prepare the context alignment for this input
52 * - alignment to be processed
53 * @return al or a new alignment with appropriate attributes/order for input
55 public AlignmentI prepareAlignment(AlignmentI al)
57 jalview.analysis.AlignmentSorter.sortByGroup(al);
62 public ContentBody formatForInput(RestJob rj)
63 throws UnsupportedEncodingException, NoValidInputDataException
65 StringBuffer idvector = new StringBuffer();
67 AlignmentI al = rj.getAlignmentForInput(token, type);
68 // assume that alignment is properly ordered so groups form consecutive
70 ArrayList<int[]> gl = new ArrayList<int[]>();
71 for (SequenceGroup sg : (Vector<SequenceGroup>) al.getGroups())
73 if (sg.getSize()<minsize)
75 throw new NoValidInputDataException("Group contains less than "+minsize+" sequences.");
77 // TODO: refactor to sequenceGroup for efficiency -
78 // getAlignmentRowInterval(AlignmentI al)
80 for (SequenceI sq : sg.getSequencesInOrder(al))
82 int p = al.findIndex(sq);
101 int[][] vals = gl.toArray(new int[gl.size()][]);
102 int[] srt = new int[gl.size()];
103 for (int i = 0; i < vals.length; i++)
105 jalview.util.QuickSort.sort(srt, vals);
107 int last = vals[0][0] - 1;
108 for (int[] range : vals)
114 idvector.append(sep);
116 idvector.append(range[1] - last);
121 return new StringBody(idvector.toString());