Commit 993038f0 authored by bow's avatar bow
Browse files

Update FastqSync tests

parent bc9b4ce6
......@@ -30,187 +30,229 @@ class FastqSyncTest extends TestNGSuite with MockitoSugar with Matchers {
.map(x => new FastqRecord(x, "A", "", "H"))
.toIterator.asJava
@DataProvider(name = "mockReaderProvider")
def mockReaderProvider() =
@DataProvider(name = "mockProvider")
def mockProvider() =
Array(
Array(mock[FastqReader], mock[FastqReader], mock[FastqReader]))
Array(mock[FastqReader], mock[FastqReader], mock[FastqReader],
mock[AsyncFastqWriter], mock[AsyncFastqWriter])
)
@Test(dataProvider = "mockProvider")
def testDefault(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
@Test(dataProvider = "mockReaderProvider")
def testDefault(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
when(refMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver("1", "2", "3")
when(bMock.iterator) thenReturn recordsOver("1", "2", "3")
val obs = inOrd(aOutMock, bOutMock)
val exp = recordsOver("1", "2", "3").asScala.toSeq
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
obs.verify(aOutMock).write(exp(0))
obs.verify(bOutMock).write(exp(0))
obs.verify(aOutMock).write(exp(1))
obs.verify(bOutMock).write(exp(1))
obs.verify(aOutMock).write(exp(2))
obs.verify(bOutMock).write(exp(2))
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 3
sync(0) shouldBe (new FastqRecord("1", "A", "", "H"), new FastqRecord("1", "A", "", "H"))
sync(1) shouldBe (new FastqRecord("2", "A", "", "H"), new FastqRecord("2", "A", "", "H"))
sync(2) shouldBe (new FastqRecord("3", "A", "", "H"), new FastqRecord("3", "A", "", "H"))
counts.numDiscard1 shouldBe 0
counts.numDiscard2 shouldBe 0
counts.numKept shouldBe 3
numDiscard1 shouldBe 0
numDiscard2 shouldBe 0
numKept shouldBe 3
}
@Test(dataProvider = "mockReaderProvider")
def testRefTooShort(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testRefTooShort(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1", "2")
when(aMock.iterator) thenReturn recordsOver("1", "2", "3")
when(bMock.iterator) thenReturn recordsOver("1", "2", "3")
val thrown = intercept[NoSuchElementException] {
syncFastq(refMock, aMock, bMock)
syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
}
thrown.getMessage should ===("Reference record stream shorter than expected")
}
@Test(dataProvider = "mockReaderProvider")
def testSeqAEmpty(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqAEmpty(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver()
when(bMock.iterator) thenReturn recordsOver("1", "2", "3")
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 0
counts.numDiscard1 shouldBe 0
counts.numDiscard2 shouldBe 3
counts.numKept shouldBe 0
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
numDiscard1 shouldBe 0
numDiscard2 shouldBe 3
numKept shouldBe 0
}
@Test(dataProvider = "mockReaderProvider")
def testSeqBEmpty(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqBEmpty(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver("1", "2", "3")
when(bMock.iterator) thenReturn recordsOver()
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 0
counts.numDiscard1 shouldBe 3
counts.numDiscard2 shouldBe 0
counts.numKept shouldBe 0
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
numDiscard1 shouldBe 3
numDiscard2 shouldBe 0
numKept shouldBe 0
}
@Test(dataProvider = "mockReaderProvider")
def testSeqAShorter(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqAShorter(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver("2", "3")
when(bMock.iterator) thenReturn recordsOver("1", "2", "3")
val obs = inOrd(aOutMock, bOutMock)
val exp = recordsOver("1", "2", "3").asScala.toSeq
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
// exp(0) is discarded by syncFastq
obs.verify(aOutMock).write(exp(1))
obs.verify(bOutMock).write(exp(1))
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 2
sync(0) shouldBe (new FastqRecord("2", "A", "", "H"), new FastqRecord("2", "A", "", "H"))
sync(1) shouldBe (new FastqRecord("3", "A", "", "H"), new FastqRecord("3", "A", "", "H"))
counts.numDiscard1 shouldBe 0
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 2
obs.verify(aOutMock).write(exp(2))
obs.verify(bOutMock).write(exp(2))
numDiscard1 shouldBe 0
numDiscard2 shouldBe 1
numKept shouldBe 2
}
@Test(dataProvider = "mockReaderProvider")
def testSeqBShorter(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqBShorter(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver("2", "3")
when(bMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver("1", "2", "3")
when(bMock.iterator) thenReturn recordsOver("1", "3")
val obs = inOrd(aOutMock, bOutMock)
val exp = recordsOver("1", "2", "3").asScala.toSeq
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 2
sync(0) shouldBe (new FastqRecord("2", "A", "", "H"), new FastqRecord("2", "A", "", "H"))
sync(1) shouldBe (new FastqRecord("3", "A", "", "H"), new FastqRecord("3", "A", "", "H"))
counts.numDiscard1 shouldBe 0
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 2
// exp(1) is discarded by syncFastq
obs.verify(aOutMock).write(exp(0))
obs.verify(bOutMock).write(exp(0))
obs.verify(aOutMock).write(exp(2))
obs.verify(bOutMock).write(exp(2))
numDiscard1 shouldBe 1
numDiscard2 shouldBe 0
numKept shouldBe 2
}
@Test(dataProvider = "mockReaderProvider")
def testSeqABShorter(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqABShorter(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1", "2", "3")
when(aMock.iterator) thenReturn recordsOver("2", "3")
when(bMock.iterator) thenReturn recordsOver("1", "2")
val obs = inOrd(aOutMock, bOutMock)
val exp = recordsOver("1", "2", "3").asScala.toSeq
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
// exp(0) and exp(2) are discarded by syncFastq
obs.verify(aOutMock).write(exp(1))
obs.verify(bOutMock).write(exp(1))
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 1
sync(0) shouldBe (new FastqRecord("2", "A", "", "H"), new FastqRecord("2", "A", "", "H"))
counts.numDiscard1 shouldBe 1
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 1
numDiscard1 shouldBe 1
numDiscard2 shouldBe 1
numKept shouldBe 1
}
@Test(dataProvider = "mockReaderProvider")
def testSeqABShorterPairMarkSlash(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqABShorterPairMarkSlash(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1/1", "2/1", "3/1")
when(aMock.iterator) thenReturn recordsOver("2/1", "3/1")
when(bMock.iterator) thenReturn recordsOver("1/2", "2/2")
val obs = inOrd(aOutMock, bOutMock)
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
obs.verify(aOutMock).write(new FastqRecord("2/1", "A", "", "H"))
obs.verify(bOutMock).write(new FastqRecord("2/2", "A", "", "H"))
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 1
sync(0) shouldBe (new FastqRecord("2/1", "A", "", "H"), new FastqRecord("2/2", "A", "", "H"))
counts.numDiscard1 shouldBe 1
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 1
numDiscard1 shouldBe 1
numDiscard2 shouldBe 1
numKept shouldBe 1
}
@Test(dataProvider = "mockReaderProvider")
def testSeqABShorterPairMarkUnderscore(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqABShorterPairMarkUnderscore(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1_1", "2_1", "3_1")
when(aMock.iterator) thenReturn recordsOver("2_1", "3_1")
when(bMock.iterator) thenReturn recordsOver("1_2", "2_2")
val obs = inOrd(aOutMock, bOutMock)
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 1
sync(0) shouldBe (new FastqRecord("2_1", "A", "", "H"), new FastqRecord("2_2", "A", "", "H"))
counts.numDiscard1 shouldBe 1
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 1
obs.verify(aOutMock).write(new FastqRecord("2_1", "A", "", "H"))
obs.verify(bOutMock).write(new FastqRecord("2_2", "A", "", "H"))
numDiscard1 shouldBe 1
numDiscard2 shouldBe 1
numKept shouldBe 1
}
@Test(dataProvider = "mockReaderProvider")
def testSeqABShorterWithDesc(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testSeqABShorterWithDescription(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1 desc1b", "2 desc2b", "3 desc3b")
when(aMock.iterator) thenReturn recordsOver("2 desc2a", "3 desc3a")
when(bMock.iterator) thenReturn recordsOver("1 desc1b", "2 desc2b")
val obs = inOrd(aOutMock, bOutMock)
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 1
sync(0) shouldBe (new FastqRecord("2 desc2a", "A", "", "H"), new FastqRecord("2 desc2b", "A", "", "H"))
counts.numDiscard1 shouldBe 1
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 1
obs.verify(aOutMock).write(new FastqRecord("2 desc2a", "A", "", "H"))
obs.verify(bOutMock).write(new FastqRecord("2 desc2b", "A", "", "H"))
numDiscard1 shouldBe 1
numDiscard2 shouldBe 1
numKept shouldBe 1
}
@Test(dataProvider = "mockReaderProvider")
def testComplex(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader) = {
@Test(dataProvider = "mockProvider")
def testComplex(refMock: FastqReader, aMock: FastqReader, bMock: FastqReader,
aOutMock: AsyncFastqWriter, bOutMock: AsyncFastqWriter) = {
when(refMock.iterator) thenReturn recordsOver("1/2 yep", "2/2 yep", "3/2 yep", "4/2 yep", "5/2 yep")
when(aMock.iterator) thenReturn recordsOver("1/1 yep", "2/1 yep", "4/1 yep")
when(bMock.iterator) thenReturn recordsOver("1/2 yep", "3/2 yep", "4/2 yep")
val obs = inOrd(aOutMock, bOutMock)
val (sync, counts) = syncFastq(refMock, aMock, bMock)
sync.length shouldBe 2
sync(0) shouldBe (new FastqRecord("1/1 yep", "A", "", "H"), new FastqRecord("1/2 yep", "A", "", "H"))
sync(1) shouldBe (new FastqRecord("4/1 yep", "A", "", "H"), new FastqRecord("4/2 yep", "A", "", "H"))
counts.numDiscard1 shouldBe 1
counts.numDiscard2 shouldBe 1
counts.numKept shouldBe 2
}
val (numDiscard1, numDiscard2, numKept) = syncFastq(refMock, aMock, bMock, aOutMock, bOutMock)
@Test def testWriteSynced() = {
val aMock = mock[AsyncFastqWriter]
val bMock = mock[AsyncFastqWriter]
val sync = Stream(
(new FastqRecord("1", "A", "", "H"), new FastqRecord("1", "T", "", "E")),
(new FastqRecord("2", "A", "", "H"), new FastqRecord("2", "T", "", "E")))
val counts = SyncCounts(4, 3, 2)
val obs = inOrd(aMock, bMock)
val stdout = new java.io.ByteArrayOutputStream
Console.withOut(stdout) {
writeSyncedFastq(sync, counts, aMock, bMock)
}
stdout.toString should ===(List(
"Filtered 4 reads from first read file.",
"Filtered 3 reads from second read file.",
"Synced read files contain 2 reads.\n"
).mkString("\n"))
obs.verify(aMock).write(new FastqRecord("1", "A", "", "H"))
obs.verify(bMock).write(new FastqRecord("1", "T", "", "E"))
obs.verify(aMock).write(new FastqRecord("2", "A", "", "H"))
obs.verify(bMock).write(new FastqRecord("2", "T", "", "E"))
obs.verify(aOutMock).write(new FastqRecord("1/1 yep", "A", "", "H"))
obs.verify(bOutMock).write(new FastqRecord("1/2 yep", "A", "", "H"))
obs.verify(aOutMock).write(new FastqRecord("4/1 yep", "A", "", "H"))
obs.verify(bOutMock).write(new FastqRecord("4/2 yep", "A", "", "H"))
numDiscard1 shouldBe 1
numDiscard2 shouldBe 1
numKept shouldBe 2
}
@Test def testArgsMinimum() = {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment