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)
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<int[]> gl = new ArrayList<int[]>();
- for (SequenceGroup sg : (Vector<SequenceGroup>)al.getGroups())
+ for (SequenceGroup sg : (Vector<SequenceGroup>) al.getGroups())
{
- // TODO: refactor to sequenceGroup for efficiency - getAlignmentRowInterval(AlignmentI al)
- int[] se=null;
- for (SequenceI sq: sg.getSequencesInOrder(al))
+ if (sg.getSize()<minsize)
+ {
+ throw new NoValidInputDataException("Group contains less than "+minsize+" sequences.");
+ }
+ // TODO: refactor to sequenceGroup for efficiency -
+ // getAlignmentRowInterval(AlignmentI al)
+ int[] se = null;
+ for (SequenceI sq : sg.getSequencesInOrder(al))
{
int p = al.findIndex(sq);
- if (se==null)
+ if (se == null)
{
- se=new int[] { p, p};
+ se = new int[]
+ { p, p };
}
- else {
- if (p<se[0])
- se[0]=p;
- if (p>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;i<vals.length;i++)
- srt[i]=vals[i][0];
+ 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)
+ list = false;
+ int last = vals[0][0] - 1;
+ for (int[] range : vals)
{
- if (range[1]>last) {
- 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