From a9570778f83fa5a2138205488da1d20049acdecf Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 5 Jan 2011 16:06:36 +0000 Subject: [PATCH] more robust calculation of partition from possibly overlapping groups, and check to ensure minimum group size is honoured --- .../ws/rest/params/SeqGroupIndexVector.java | 97 ++++++++++++-------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/src/jalview/ws/rest/params/SeqGroupIndexVector.java b/src/jalview/ws/rest/params/SeqGroupIndexVector.java index 37d2789..4e7026e 100644 --- a/src/jalview/ws/rest/params/SeqGroupIndexVector.java +++ b/src/jalview/ws/rest/params/SeqGroupIndexVector.java @@ -17,25 +17,39 @@ 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. + * 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 class SeqGroupIndexVector extends InputType implements + AlignmentProcessor +{ public SeqGroupIndexVector() { - super(new Class[] { AlignmentI.class} ); + super(new Class[] + { AlignmentI.class }); } + /** * separator for list of sequence Indices - default is ',' */ - public String sep=","; + 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 + * + * @param al + * - alignment to be processed * @return al or a new alignment with appropriate attributes/order for input */ public AlignmentI prepareAlignment(AlignmentI al) @@ -43,57 +57,68 @@ public class SeqGroupIndexVector extends InputType implements AlignmentProcessor jalview.analysis.AlignmentSorter.sortByGroup(al); return al; } + @Override - public ContentBody formatForInput(RestJob rj) throws UnsupportedEncodingException, NoValidInputDataException + public ContentBody formatForInput(RestJob rj) + throws UnsupportedEncodingException, NoValidInputDataException { StringBuffer idvector = new StringBuffer(); - boolean list=false; + boolean list = false; AlignmentI al = rj.getAlignmentForInput(token, type); - // assume that alignment is properly ordered so groups form consecutive blocks + // assume that alignment is properly ordered so groups form consecutive + // blocks ArrayList gl = new ArrayList(); - for (SequenceGroup sg : (Vector)al.getGroups()) + for (SequenceGroup sg : (Vector) al.getGroups()) { - // TODO: refactor to sequenceGroup for efficiency - getAlignmentRowInterval(AlignmentI al) - int[] se=null; - for (SequenceI sq: sg.getSequencesInOrder(al)) + if (sg.getSize()se[1]) - se[1]=p; + else + { + if (p < se[0]) + se[0] = p; + if (p > se[1]) + se[1] = p; } } - if (se!=null) + if (se != null) { gl.add(se); } } int[][] vals = gl.toArray(new int[gl.size()][]); int[] srt = new int[gl.size()]; - for (int i=0;ilast) { - if (list) + if (range[1] > last) { - idvector.append(sep); - } - idvector.append(range[1]-last); - last=range[1]; - list=true; + if (list) + { + idvector.append(sep); + } + idvector.append(range[1] - last); + last = range[1]; + list = true; } } return new StringBody(idvector.toString()); } - + } \ No newline at end of file -- 1.7.10.2