Commit 09da7b13 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'tests-increase_utilcoverage' into 'develop'

Branch for adding tests to increase test coverage for tools and utils



See merge request !332
parents 5ce42de7 d11105a2
......@@ -197,7 +197,7 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
object WriteSummaryTest {
def makeWriter(root: Configurable, c: Map[String, Any] = Map()) = new WriteSummary(root) {
override def globalConfig = new Config(c)
override def globalConfig = new Config(c + ("exe" -> "test"))
override def outputs = Seq()
override def inputs = Seq()
qSettings = new QSettings {
......@@ -238,7 +238,7 @@ object WriteSummaryTest {
libId = l
summaryName = "test"
outputDir = new File(".").getAbsoluteFile
override def globalConfig = new Config(c)
override def globalConfig = new Config(c + ("exe" -> "test"))
def summarySettings: Map[String, Any] = settings
def summaryFiles: Map[String, File] = files
val tempFile = File.createTempFile("summary", ".json")
......@@ -256,7 +256,7 @@ object WriteSummaryTest {
new MultiSampleQScript with QScript {
summaryName = "test"
outputDir = new File(".").getAbsoluteFile
override def globalConfig = new Config(c)
override def globalConfig = new Config(c + ("exe" -> "test"))
def summarySettings: Map[String, Any] = settings
def summaryFiles: Map[String, File] = files
val tempFile = File.createTempFile("summary", ".json")
......
......@@ -31,15 +31,37 @@ class BamUtilsTest extends TestNGSuite with MockitoSugar with Matchers {
new SAMLineParser(samh)
}
private def makeSams(raws: String*): Seq[SAMRecord] =
raws.map(s => samHeaderTemplate.parseLine(s))
private val samHeaderTemplateDoubleSample: SAMLineParser = {
val samh = new SAMFileHeader
samh.setSortOrder(SAMFileHeader.SortOrder.coordinate)
samh.addSequence(new SAMSequenceRecord("chrQ", 10000))
samh.addSequence(new SAMSequenceRecord("chrR", 10000))
val readGroup1 = new SAMReadGroupRecord("001")
readGroup1.setSample("sampleX")
samh.addReadGroup(readGroup1)
val readGroup2 = new SAMReadGroupRecord("002")
readGroup2.setSample("sampleY")
samh.addReadGroup(readGroup2)
new SAMLineParser(samh)
}
private val samHeaderTemplateErrornousNoReadgroup: SAMLineParser = {
val samh = new SAMFileHeader
samh.setSortOrder(SAMFileHeader.SortOrder.coordinate)
samh.addSequence(new SAMSequenceRecord("chrQ", 10000))
samh.addSequence(new SAMSequenceRecord("chrR", 10000))
new SAMLineParser(samh)
}
private def makeSams(header: SAMLineParser, raws: Seq[String]): Seq[SAMRecord] =
raws.map(s => header.parseLine(s))
private def makeSamReader(f: File): SamReader = SamReaderFactory
.make()
.validationStringency(ValidationStringency.LENIENT)
.open(f)
val sBamRecs1 = makeSams(
val sBamRecs1 = Seq(
"r02\t0\tchrQ\t50\t60\t10M\t*\t0\t0\tTACGTACGTA\tEEFFGGHHII\tRG:Z:001",
"r01\t16\tchrQ\t190\t60\t10M\t*\t0\t0\tTACGTACGTA\tEEFFGGHHII\tRG:Z:001",
"r01\t16\tchrQ\t290\t60\t10M\t*\t0\t0\tGGGGGAAAAA\tGGGGGGGGGG\tRG:Z:001",
......@@ -49,7 +71,12 @@ class BamUtilsTest extends TestNGSuite with MockitoSugar with Matchers {
"r06\t4\t*\t0\t0\t*\t*\t0\t0\tATATATATAT\tHIHIHIHIHI\tRG:Z:001"
)
val pBamRecs1 = makeSams(
val sBamRecs2 = Seq(
"r02\t0\tchrQ\t50\t60\t10M\t*\t0\t0\tTACGTACGTA\tEEFFGGHHII\t",
"r01\t16\tchrQ\t190\t60\t10M\t*\t0\t0\tTACGTACGTA\tEEFFGGHHII\t"
)
val pBamRecs1 = Seq(
"r02\t99\tchrQ\t50\t60\t10M\t=\t90\t50\tTACGTACGTA\tEEFFGGHHII\tRG:Z:001",
"r02\t147\tchrQ\t90\t60\t10M\t=\t50\t-50\tATGCATGCAT\tEEFFGGHHII\tRG:Z:001",
"r01\t163\tchrQ\t150\t60\t10M\t=\t190\t50\tAAAAAGGGGG\tGGGGGGGGGG\tRG:Z:001",
......@@ -66,18 +93,32 @@ class BamUtilsTest extends TestNGSuite with MockitoSugar with Matchers {
"r06\t4\t*\t0\t0\t*\t*\t0\t0\tGCGCGCGCGC\tHIHIHIHIHI\tRG:Z:001"
)
val pBamRecs2 = Seq(
"r01\t163\tchrQ\t150\t60\t10M\t=\t190\t50\tAAAAAGGGGG\tGGGGGGGGGG\t",
"r01\t83\tchrQ\t190\t60\t10M\t=\t150\t-50\tGGGGGAAAAA\tGGGGGGGGGG\t",
"r01\t163\tchrQ\t250\t60\t10M\t=\t290\t50\tAAAAAGGGGG\tGGGGGGGGGG\t",
"r01\t83\tchrQ\t290\t60\t10M\t=\t250\t-50\tGGGGGAAAAA\tGGGGGGGGGG\t"
)
@BeforeClass
def start: Unit = {
createTestFileFrom(sBamRecs1, BamUtilsTest.singleEndBam01)
createTestFileFrom(pBamRecs1, BamUtilsTest.pairedEndBam01)
createTestFileFrom(makeSams(samHeaderTemplate, sBamRecs1), samHeaderTemplate, BamUtilsTest.singleEndBam01)
createTestFileFrom(makeSams(samHeaderTemplate, pBamRecs1), samHeaderTemplate, BamUtilsTest.pairedEndBam01)
createTestFileFrom(makeSams(samHeaderTemplate, pBamRecs1), samHeaderTemplate, BamUtilsTest.pairedEndBam02)
createTestFileFrom(makeSams(samHeaderTemplateDoubleSample, sBamRecs1), samHeaderTemplateDoubleSample, BamUtilsTest.singleEndBam01WithDoubleSamples)
createTestFileFrom(makeSams(samHeaderTemplateDoubleSample, pBamRecs1), samHeaderTemplateDoubleSample, BamUtilsTest.pairedEndBam01WithDoubleSamples)
createTestFileFrom(makeSams(samHeaderTemplateErrornousNoReadgroup, sBamRecs2), samHeaderTemplateErrornousNoReadgroup, BamUtilsTest.singleEndBam01NoRG)
createTestFileFrom(makeSams(samHeaderTemplateErrornousNoReadgroup, pBamRecs2), samHeaderTemplateErrornousNoReadgroup, BamUtilsTest.pairedEndBam01NoRG)
}
private def createTestFileFrom(records: Seq[SAMRecord], output: File): File = {
private def createTestFileFrom(records: Seq[SAMRecord], header: SAMLineParser, output: File): File = {
output.getParentFile.createNewFile()
val outBam = new SAMFileWriterFactory()
.setCreateIndex(true)
.setUseAsyncIo(true)
.makeBAMWriter(samHeaderTemplate.getFileHeader, true, output)
.makeBAMWriter(header.getFileHeader, true, output)
writeBam(records, outBam)
output
}
......@@ -132,6 +173,40 @@ class BamUtilsTest extends TestNGSuite with MockitoSugar with Matchers {
)
}
@Test def testSampleBamNamesMultipleSamplesSE = {
val thrown = intercept[IllegalArgumentException] {
sampleBamMap(List(BamUtilsTest.singleEndBam01WithDoubleSamples))
}
thrown.getMessage should ===("Bam contains multiple sample IDs: " + BamUtilsTest.singleEndBam01WithDoubleSamples)
}
@Test def testSampleBamNamesMultipleSamplesPE = {
val thrown = intercept[IllegalArgumentException] {
sampleBamMap(List(BamUtilsTest.pairedEndBam01WithDoubleSamples))
}
thrown.getMessage should ===("Bam contains multiple sample IDs: " + BamUtilsTest.pairedEndBam01WithDoubleSamples)
}
@Test def testSampleBamNamesNoRGSE = {
val thrown = intercept[IllegalArgumentException] {
sampleBamMap(List(BamUtilsTest.singleEndBam01NoRG))
}
thrown.getMessage should ===("Bam does not contain sample ID or have no readgroups defined: " + BamUtilsTest.singleEndBam01NoRG)
}
@Test def testSampleBamNamesNoRGPE = {
val thrown = intercept[IllegalArgumentException] {
sampleBamMap(List(BamUtilsTest.pairedEndBam01NoRG))
}
thrown.getMessage should ===("Bam does not contain sample ID or have no readgroups defined: " + BamUtilsTest.pairedEndBam01NoRG)
}
@Test def testSampleFoundTwice = {
val thrown = intercept[IllegalArgumentException] {
sampleBamMap(List(BamUtilsTest.pairedEndBam01, BamUtilsTest.pairedEndBam02))
}
thrown.getMessage should ===("Samples has been found twice")
}
}
object BamUtilsTest {
......@@ -139,4 +214,16 @@ object BamUtilsTest {
singleEndBam01.deleteOnExit()
var pairedEndBam01: File = File.createTempFile("bamutils", "paired01.bam")
singleEndBam01.deleteOnExit()
}
\ No newline at end of file
var pairedEndBam02: File = File.createTempFile("bamutils", "paired02.bam")
singleEndBam01.deleteOnExit()
var singleEndBam01WithDoubleSamples: File = File.createTempFile("bamutils", "single01ds.bam")
singleEndBam01WithDoubleSamples.deleteOnExit()
var pairedEndBam01WithDoubleSamples: File = File.createTempFile("bamutils", "paired01ds.bam")
pairedEndBam01WithDoubleSamples.deleteOnExit()
var singleEndBam01NoRG: File = File.createTempFile("bamutils", "single01norg.bam")
singleEndBam01NoRG.deleteOnExit()
var pairedEndBam01NoRG: File = File.createTempFile("bamutils", "paired01norg.bam")
singleEndBam01NoRG.deleteOnExit()
}
Markdown is supported
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