* create a sequence features on each subrange of 1-5
*/
SequenceI seq0 = new Sequence("seq", "ABCDE");
+ int start = 8;
+ int end = 12;
+ seq0.setStart(start);
+ seq0.setEnd(end);
AlignmentI alignment = new Alignment(new SequenceI[] { seq0 });
alignment.setDataset(null);
- for (int from = 1; from <= seq0.getLength(); from++)
+ for (int from = start; from <= end; from++)
{
- for (int to = from; to <= seq0.getLength(); to++)
+ for (int to = from; to <= end; to++)
{
String desc = String.format("%d-%d", from, to);
SequenceFeature sf = new SequenceFeature("test", desc, from, to,
assertEquals(func(5), sfs.size());
/*
- * now perform all possible cuts of subranges of 1-5 (followed by Undo)
+ * now perform all possible cuts of subranges of columns 1-5
* and validate the resulting remaining sequence features!
*/
SequenceI[] sqs = new SequenceI[] { seq0 };
- from + 1), alignment);
final String msg = String.format("Cut %d-%d ", from + 1, to + 1);
- verifyCut(seq0, from, to, msg);
+ verifyCut(seq0, from, to, msg, start);
/*
- * undo and verify
+ * undo and verify all restored
*/
AlignmentI[] views = new AlignmentI[] { alignment };
ec.undoCommand(views);
* redo and verify
*/
ec.doCommand(views);
- verifyCut(seq0, from, to, msg);
+ verifyCut(seq0, from, to, msg, start);
/*
* undo ready for next cut
* @param from
* @param to
* @param msg
+ * @param seqStart
*/
protected void verifyCut(SequenceI seq0, int from, int to,
- final String msg)
+ final String msg, int seqStart)
{
List<SequenceFeature> sfs;
sfs = seq0.getSequenceFeatures();
*/
for (SequenceFeature sf : sfs)
{
- verifyFeatureRelocation(sf, from + 1, to + 1, !datasetRetained);
+ verifyFeatureRelocation(sf, from + 1, to + 1, !datasetRetained,
+ seqStart);
}
}
*
* @param sf
* @param from
- * start of cut (first residue cut)
+ * start of cut (first residue cut 1..)
* @param to
- * end of cut (last residue cut)
+ * end of cut (last residue cut 1..)
* @param newDataset
+ * @param seqStart
*/
private void verifyFeatureRelocation(SequenceFeature sf, int from, int to,
- boolean newDataset)
+ boolean newDataset, int seqStart)
{
// TODO handle the gapped sequence case as well
int cutSize = to - from + 1;
final int oldFrom = ((Integer) sf.getValue("from")).intValue();
final int oldTo = ((Integer) sf.getValue("to")).intValue();
+ final int oldFromPosition = oldFrom - seqStart + 1; // 1..
+ final int oldToPosition = oldTo - seqStart + 1; // 1..
String msg = String.format(
"Feature %s relocated to %d-%d after cut of %d-%d",
assertEquals("0: " + msg, oldFrom, sf.getBegin());
assertEquals("0: " + msg, oldTo, sf.getEnd());
}
- else if (oldTo < from)
+ else if (oldToPosition < from)
{
// before cut region so unchanged
assertEquals("1: " + msg, oldFrom, sf.getBegin());
assertEquals("2: " + msg, oldTo, sf.getEnd());
}
- else if (oldFrom > to)
+ else if (oldFromPosition > to)
{
// follows cut region - shift by size of cut
assertEquals("3: " + msg, newDataset ? oldFrom - cutSize : oldFrom,
assertEquals("4: " + msg, newDataset ? oldTo - cutSize : oldTo,
sf.getEnd());
}
- else if (oldFrom < from && oldTo > to)
+ else if (oldFromPosition < from && oldToPosition > to)
{
// feature encloses cut region - shrink it right
assertEquals("5: " + msg, oldFrom, sf.getBegin());
assertEquals("6: " + msg, oldTo - cutSize, sf.getEnd());
}
- else if (oldFrom < from)
+ else if (oldFromPosition < from)
{
// feature overlaps left side of cut region - truncated right
- assertEquals("7: " + msg, from - 1, sf.getEnd());
+ assertEquals("7: " + msg, from - 1 + seqStart - 1, sf.getEnd());
}
- else if (oldTo > to)
+ else if (oldToPosition > to)
{
// feature overlaps right side of cut region - truncated left
- assertEquals("8: " + msg, newDataset ? from : to + 1, sf.getBegin());
+ assertEquals("8: " + msg, newDataset ? from + seqStart - 1 : to + 1,
+ sf.getBegin());
assertEquals("9: " + msg, newDataset ? from + oldTo - to - 1 : oldTo,
sf.getEnd());
}