SequenceI sq = new Sequence("test/8-13", "ABCDEF");
assertEquals(8, sq.findPosition(0));
// Sequence should now hold a cursor at [8, 0]
- assertEquals("test:Pos8:Col1:startCol1:endCol0:tok0",
+ assertEquals("test:Pos8:Col1:startCol1:endCol0:tok1",
PA.getValue(sq, "cursor").toString());
SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
int token = (int) PA.getValue(sq, "changeCount");
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(++token, (int) PA.getValue(sq, "changeCount"));
assertEquals(new SequenceCursor(sq, 13, 6, token), cursor);
- assertEquals("test:Pos13:Col6:startCol1:endCol6:tok1",
+ assertEquals("test:Pos13:Col6:startCol1:endCol6:tok2",
PA.getValue(sq, "cursor").toString());
// assertEquals(-1, seq.findPosition(6)); // fails
sq = new Sequence("test/8-11", "AB-C-D--");
- token = (int) PA.getValue(sq, "changeCount"); // 0
+ token = (int) PA.getValue(sq, "changeCount"); // 1 for setStart
assertEquals(8, sq.findPosition(0));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 8, 1, token), cursor);
- assertEquals("test:Pos8:Col1:startCol1:endCol0:tok0",
+ assertEquals("test:Pos8:Col1:startCol1:endCol0:tok1",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(9, sq.findPosition(1));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 9, 2, ++token), cursor);
- assertEquals("test:Pos9:Col2:startCol1:endCol0:tok1",
+ assertEquals("test:Pos9:Col2:startCol1:endCol0:tok2",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(10, sq.findPosition(2));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 9, 2, ++token), cursor);
- assertEquals("test:Pos9:Col2:startCol1:endCol0:tok2",
+ assertEquals("test:Pos9:Col2:startCol1:endCol0:tok3",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(10, sq.findPosition(3));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 10, 4, ++token), cursor);
- assertEquals("test:Pos10:Col4:startCol1:endCol0:tok3",
+ assertEquals("test:Pos10:Col4:startCol1:endCol0:tok4",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(11, sq.findPosition(4));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 10, 4, ++token), cursor);
- assertEquals("test:Pos10:Col4:startCol1:endCol0:tok4",
+ assertEquals("test:Pos10:Col4:startCol1:endCol0:tok5",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 11, 6, ++token), cursor);
// lastCol has been found and saved in the cursor
- assertEquals("test:Pos11:Col6:startCol1:endCol6:tok5",
+ assertEquals("test:Pos11:Col6:startCol1:endCol6:tok6",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
sq = new Sequence("test/8-13", "--AB-C-DEF--");
assertEquals(8, sq.findPosition(0));
assertNull(PA.getValue(sq, "cursor"));
+ assertEquals(1, PA.getValue(sq, "changeCount"));
sq.sequenceChanged();
assertEquals(8, sq.findPosition(1));
sq.sequenceChanged();
assertEquals(8, sq.findPosition(2));
- assertEquals("test:Pos8:Col3:startCol3:endCol0:tok2",
+ assertEquals("test:Pos8:Col3:startCol3:endCol0:tok3",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(9, sq.findPosition(3));
- assertEquals("test:Pos9:Col4:startCol3:endCol0:tok3",
+ assertEquals("test:Pos9:Col4:startCol3:endCol0:tok4",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
// column[4] is a gap, returns next residue pos (C10)
// cursor is set to last residue found [B]
assertEquals(10, sq.findPosition(4));
- assertEquals("test:Pos9:Col4:startCol3:endCol0:tok4",
+ assertEquals("test:Pos9:Col4:startCol3:endCol0:tok5",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(10, sq.findPosition(5));
- assertEquals("test:Pos10:Col6:startCol3:endCol0:tok5",
+ assertEquals("test:Pos10:Col6:startCol3:endCol0:tok6",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
// column[6] is a gap, returns next residue pos (D11)
// cursor is set to last residue found [C]
assertEquals(11, sq.findPosition(6));
- assertEquals("test:Pos10:Col6:startCol3:endCol0:tok6",
+ assertEquals("test:Pos10:Col6:startCol3:endCol0:tok7",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(11, sq.findPosition(7));
- assertEquals("test:Pos11:Col8:startCol3:endCol0:tok7",
+ assertEquals("test:Pos11:Col8:startCol3:endCol0:tok8",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(12, sq.findPosition(8));
- assertEquals("test:Pos12:Col9:startCol3:endCol0:tok8",
+ assertEquals("test:Pos12:Col9:startCol3:endCol0:tok9",
PA.getValue(sq, "cursor").toString());
/*
*/
sq.sequenceChanged();
assertEquals(13, sq.findPosition(9));
- assertEquals("test:Pos13:Col10:startCol3:endCol10:tok9",
+ assertEquals("test:Pos13:Col10:startCol3:endCol10:tok10",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(14, sq.findPosition(10));
- assertEquals("test:Pos13:Col10:startCol3:endCol10:tok10",
+ assertEquals("test:Pos13:Col10:startCol3:endCol10:tok11",
PA.getValue(sq, "cursor").toString());
/*
*/
sq.sequenceChanged();
assertEquals(14, sq.findPosition(11));
- assertEquals("test:Pos13:Col10:startCol3:endCol10:tok11",
+ assertEquals("test:Pos13:Col10:startCol3:endCol10:tok12",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(14, sq.findPosition(99));
- assertEquals("test:Pos13:Col10:startCol3:endCol10:tok12",
+ assertEquals("test:Pos13:Col10:startCol3:endCol10:tok13",
PA.getValue(sq, "cursor").toString());
/*
*/
sq = new Sequence("test/8-13", "--AB-C-DEF");
assertEquals(13, sq.findPosition(9));
- assertEquals("test:Pos13:Col10:startCol3:endCol10:tok0",
+ assertEquals("test:Pos13:Col10:startCol3:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
sq.sequenceChanged();
assertEquals(12, sq.findPosition(8)); // E12
// sequenceChanged() invalidates cursor.lastResidueColumn
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
- assertEquals("test:Pos12:Col9:startCol3:endCol0:tok1",
+ assertEquals("test:Pos12:Col9:startCol3:endCol0:tok2",
cursor.toString());
// findPosition with cursor accepts base 1 column values
assertEquals(13, ((Sequence) sq).findPosition(10, cursor));
assertEquals(13, sq.findPosition(9)); // F13
// lastResidueColumn has now been found and saved in cursor
- assertEquals("test:Pos13:Col10:startCol3:endCol10:tok1",
+ assertEquals("test:Pos13:Col10:startCol3:endCol10:tok2",
PA.getValue(sq, "cursor").toString());
}
public void testFindIndex_withCursor()
{
Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
+ final int tok = (int) PA.getValue(sq, "changeCount");
+ assertEquals(1, tok);
// find F given A, check cursor is now at the found position
- assertEquals(10, sq.findIndex(13, new SequenceCursor(sq, 8, 2, 0)));
+ assertEquals(10, sq.findIndex(13, new SequenceCursor(sq, 8, 2, tok)));
SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(13, cursor.residuePosition);
assertEquals(10, cursor.columnPosition);
// find A given F
- assertEquals(2, sq.findIndex(8, new SequenceCursor(sq, 13, 10, 0)));
+ assertEquals(2, sq.findIndex(8, new SequenceCursor(sq, 13, 10, tok)));
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(8, cursor.residuePosition);
assertEquals(2, cursor.columnPosition);
// find C given C (no cursor update is done for this case)
- assertEquals(6, sq.findIndex(10, new SequenceCursor(sq, 10, 6, 0)));
+ assertEquals(6, sq.findIndex(10, new SequenceCursor(sq, 10, 6, tok)));
SequenceCursor cursor2 = (SequenceCursor) PA.getValue(sq, "cursor");
assertSame(cursor2, cursor);
public void testFindPosition_withCursor()
{
Sequence sq = new Sequence("test/8-13", "-A--BCD-EF--");
+ final int tok = (int) PA.getValue(sq, "changeCount");
+ assertEquals(1, tok);
// find F pos given A - lastCol gets set in cursor
- assertEquals(13, sq.findPosition(10, new SequenceCursor(sq, 8, 2, 0)));
- assertEquals("test:Pos13:Col10:startCol0:endCol10:tok0",
+ assertEquals(13,
+ sq.findPosition(10, new SequenceCursor(sq, 8, 2, tok)));
+ assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
// find A pos given F - first residue column is saved in cursor
- assertEquals(8, sq.findPosition(2, new SequenceCursor(sq, 13, 10, 0)));
- assertEquals("test:Pos8:Col2:startCol2:endCol10:tok0",
+ assertEquals(8,
+ sq.findPosition(2, new SequenceCursor(sq, 13, 10, tok)));
+ assertEquals("test:Pos8:Col2:startCol2:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
// find C pos given C (neither startCol nor endCol is set)
- assertEquals(10, sq.findPosition(6, new SequenceCursor(sq, 10, 6, 0)));
- assertEquals("test:Pos10:Col6:startCol0:endCol0:tok0",
+ assertEquals(10,
+ sq.findPosition(6, new SequenceCursor(sq, 10, 6, tok)));
+ assertEquals("test:Pos10:Col6:startCol0:endCol0:tok1",
PA.getValue(sq, "cursor").toString());
// now the grey area - what residue position for a gapped column? JAL-2562
// find 'residue' for column 3 given cursor for D (so working left)
// returns B9; cursor is updated to [B 5]
- assertEquals(9, sq.findPosition(3, new SequenceCursor(sq, 11, 7, 0)));
- assertEquals("test:Pos9:Col5:startCol0:endCol0:tok0",
+ assertEquals(9, sq.findPosition(3, new SequenceCursor(sq, 11, 7, tok)));
+ assertEquals("test:Pos9:Col5:startCol0:endCol0:tok1",
PA.getValue(sq, "cursor").toString());
// find 'residue' for column 8 given cursor for D (so working right)
// returns E12; cursor is updated to [D 7]
- assertEquals(12, sq.findPosition(8, new SequenceCursor(sq, 11, 7, 0)));
- assertEquals("test:Pos11:Col7:startCol0:endCol0:tok0",
+ assertEquals(12,
+ sq.findPosition(8, new SequenceCursor(sq, 11, 7, tok)));
+ assertEquals("test:Pos11:Col7:startCol0:endCol0:tok1",
PA.getValue(sq, "cursor").toString());
// find 'residue' for column 12 given cursor for B
// returns 1 more than last residue position; cursor is updated to [F 10]
// lastCol position is saved in cursor
- assertEquals(14, sq.findPosition(12, new SequenceCursor(sq, 9, 5, 0)));
- assertEquals("test:Pos13:Col10:startCol0:endCol10:tok0",
+ assertEquals(14,
+ sq.findPosition(12, new SequenceCursor(sq, 9, 5, tok)));
+ assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
/*
* returns 1 more than the last residue position
* cursor is set to last real residue position [F 10]
*/
- assertEquals(14, sq.findPosition(99, new SequenceCursor(sq, 8, 2, 0)));
- assertEquals("test:Pos13:Col10:startCol0:endCol10:tok0",
+ assertEquals(14,
+ sq.findPosition(99, new SequenceCursor(sq, 8, 2, tok)));
+ assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
/*
*/
sq = new Sequence("test/8-13", "-A--BCD-EF");
// first find C from A
- assertEquals(10, sq.findPosition(6, new SequenceCursor(sq, 8, 2, 0)));
+ assertEquals(10, sq.findPosition(6, new SequenceCursor(sq, 8, 2, tok)));
SequenceCursor cursor = (SequenceCursor) PA.getValue(sq, "cursor");
- assertEquals("test:Pos10:Col6:startCol0:endCol0:tok0",
+ assertEquals("test:Pos10:Col6:startCol0:endCol0:tok1",
cursor.toString());
// now 'find' 99 from C
// cursor is set to [F 10] and saved lastCol
assertEquals(14, sq.findPosition(99, cursor));
- assertEquals("test:Pos13:Col10:startCol0:endCol10:tok0",
+ assertEquals("test:Pos13:Col10:startCol0:endCol10:tok1",
PA.getValue(sq, "cursor").toString());
}
// cursor should now be at [F 10]
cursor = (SequenceCursor) PA.getValue(sq, "cursor");
assertEquals(new SequenceCursor(sq, 13, 10, ++token), cursor);
+
+ /*
+ * changing sequence start should invalidate cursor
+ */
+ sq = new Sequence("test/8-13", "-A--BCD-EF--");
+ assertEquals(8, sq.getStart());
+ assertEquals(9, sq.findPosition(4)); // B(9)
+ sq.setStart(7);
+ assertEquals(8, sq.findPosition(4)); // is now B(8)
+ sq.setStart(10);
+ assertEquals(11, sq.findPosition(4)); // is now B(11)
}
@Test(groups = { "Functional" })
{
String seqstring = "-A--BCD-EF--";
SequenceI sq = new Sequence("test/8-13", seqstring);
- assertEquals(0, PA.getValue(sq, "changeCount"));
+ // changeCount is incremented for setStart
+ assertEquals(1, PA.getValue(sq, "changeCount"));
assertEquals(0, sq.replace('A', 'A')); // same char
assertEquals(seqstring, sq.getSequenceAsString());
- assertEquals(0, PA.getValue(sq, "changeCount"));
+ assertEquals(1, PA.getValue(sq, "changeCount"));
assertEquals(0, sq.replace('X', 'Y')); // not there
assertEquals(seqstring, sq.getSequenceAsString());
- assertEquals(0, PA.getValue(sq, "changeCount"));
+ assertEquals(1, PA.getValue(sq, "changeCount"));
assertEquals(1, sq.replace('A', 'K'));
assertEquals("-K--BCD-EF--", sq.getSequenceAsString());
- assertEquals(1, PA.getValue(sq, "changeCount"));
+ assertEquals(2, PA.getValue(sq, "changeCount"));
assertEquals(6, sq.replace('-', '.'));
assertEquals(".K..BCD.EF..", sq.getSequenceAsString());
- assertEquals(2, PA.getValue(sq, "changeCount"));
+ assertEquals(3, PA.getValue(sq, "changeCount"));
}
@Test(groups = { "Functional" })