package jalview.ws.rest.params; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.ws.rest.AlignmentProcessor; import jalview.ws.rest.InputType; import jalview.ws.rest.NoValidInputDataException; import jalview.ws.rest.RestJob; import jalview.ws.rest.InputType.molType; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Vector; import org.apache.http.entity.mime.content.ContentBody; import org.apache.http.entity.mime.content.StringBody; /** * Represents the partitions defined on the alignment as indices e.g. for a * partition (A,B,C),(D,E),(F) The indices would be 3,2,1. Note, the alignment * must be ordered so groups are contiguous before this input type can be used. * * @author JimP * */ public class SeqGroupIndexVector extends InputType implements AlignmentProcessor { public SeqGroupIndexVector() { super(new Class[] { AlignmentI.class }); } /** * separator for list of sequence Indices - default is ',' */ public String sep = ","; /** * min size of each partition */ public int minsize = 1; molType type; /** * prepare the context alignment for this input * * @param al * - alignment to be processed * @return al or a new alignment with appropriate attributes/order for input */ public AlignmentI prepareAlignment(AlignmentI al) { jalview.analysis.AlignmentSorter.sortByGroup(al); return al; } @Override public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException { StringBuffer idvector = new StringBuffer(); boolean list = false; AlignmentI al = rj.getAlignmentForInput(token, type); // assume that alignment is properly ordered so groups form consecutive // blocks ArrayList gl = new ArrayList(); for (SequenceGroup sg : (Vector) al.getGroups()) { if (sg.getSize() se[1]) se[1] = p; } } if (se != null) { gl.add(se); } } int[][] vals = gl.toArray(new int[gl.size()][]); int[] srt = new int[gl.size()]; for (int i = 0; i < vals.length; i++) srt[i] = vals[i][0]; jalview.util.QuickSort.sort(srt, vals); list = false; int last = vals[0][0] - 1; for (int[] range : vals) { if (range[1] > last) { if (list) { idvector.append(sep); } idvector.append(range[1] - last); last = range[1]; list = true; } } return new StringBody(idvector.toString()); } }