Skip to content
Snippets Groups Projects
Commit 8a5bf774 authored by Sander Bollen's avatar Sander Bollen
Browse files

SummaryToTsvTest

parent d1bd5949
No related branches found
No related tags found
No related merge requests found
......@@ -44,7 +44,7 @@ object SamplesTsvToJson extends ToolCommand {
println(jsonString)
}
def mapFromFile(inputFile: File) : Map[String, Any] = {
def mapFromFile(inputFile: File): Map[String, Any] = {
val reader = Source.fromFile(inputFile)
val lines = reader.getLines().toList.filter(!_.isEmpty)
val header = lines.head.split("\t")
......@@ -78,7 +78,7 @@ object SamplesTsvToJson extends ToolCommand {
librariesValues.foldLeft(Map[String, Any]())((acc, kv) => mergeMaps(acc, kv))
}
def stringFromInputs(inputs: List[File]) : String = {
def stringFromInputs(inputs: List[File]): String = {
val map = inputs.map(f => mapFromFile(f)).foldLeft(Map[String, Any]())((acc, kv) => mergeMaps(acc, kv))
mapToJson(map).spaces2
}
......
{
"samples" : {
"016" : {
"libraries" : {
"L001" : {
"flexiprep" : {
"settings" : {
"skip_trim" : false,
"skip_clip" : false,
"paired" : true
}
}
}
}
}
}
}
......@@ -13,7 +13,6 @@ import org.testng.annotations.Test
import scala.collection.JavaConversions._
/**
* Created by ahbbollen on 27-8-15.
*/
......@@ -52,7 +51,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def extraValidateOutVcf() = {
val tmp = File.createTempFile("mpileup", ".vcf")
val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath, "--minDP", "1" ,"--minAP", "1")
val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath, "--minDP", "1", "--minAP", "1")
main(args)
val vcfReader = new VCFFileReader(tmp, false)
......
......@@ -11,7 +11,6 @@ import org.testng.annotations.Test
import scala.collection.JavaConversions._
/**
* Created by ahbbollen on 28-8-15.
*/
......@@ -41,7 +40,7 @@ class PrefixFastqTest extends TestNGSuite with MockitoSugar with Matchers {
val reader = new FastqReader(temp)
for (read <- reader.iterator()){
for (read <- reader.iterator()) {
read.getReadString.startsWith("AAA") shouldBe true
}
}
......
......@@ -8,7 +8,6 @@ import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by ahbbollen on 28-8-15.
*/
......@@ -28,22 +27,22 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
@Test
def testNoSampleColumn() = {
val tsv = resourcePath("/no_sample.tsv")
val thrown = the [IllegalStateException] thrownBy main(Array("-i", tsv))
thrown.getMessage should equal ("Sample column does not exist in: " + tsv)
val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv))
thrown.getMessage should equal("Sample column does not exist in: " + tsv)
}
@Test
def testNumberInLibs = {
val tsv = resourcePath("/number.tsv")
val thrown = the [IllegalStateException] thrownBy main(Array("-i", tsv))
thrown.getMessage should equal ("Sample or library may not start with a number")
val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv))
thrown.getMessage should equal("Sample or library may not start with a number")
}
@Test
def testSampleIDs = {
val tsv = resourcePath("/same.tsv")
val thrown = the [IllegalStateException] thrownBy main(Array("-i", tsv))
thrown.getMessage should equal ("Combination of Sample_ID_1 and Lib_ID_1 is found multiple times")
val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv))
thrown.getMessage should equal("Combination of Sample_ID_1 and Lib_ID_1 is found multiple times")
}
......@@ -52,7 +51,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
val tsv = new File(resourcePath("/sample.tsv"))
val json = stringFromInputs(List(tsv))
json should equal (
json should equal(
"""|{
| "samples" : {
| "Sample_ID_1" : {
......@@ -73,6 +72,4 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
|}""".stripMargin)
}
}
package nl.lumc.sasc.biopet.tools
import java.io.File
import java.nio.file.Paths
import nl.lumc.sasc.biopet.tools.SamplesTsvToJson._
import org.scalatest.Matchers
import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
import nl.lumc.sasc.biopet.core.summary.Summary
/**
* Created by ahbbollen on 31-8-15.
*/
class SummaryToTsvTest extends TestNGSuite with MockitoSugar with Matchers {
import SummaryToTsv._
private def resourcePath(p: String): String = {
Paths.get(getClass.getResource(p).toURI).toString
}
@Test
def testMain = {
val tsv = resourcePath("/test.summary.json")
noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
"-m", "root"))
noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
"-m", "sample"))
noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
"-m", "lib"))
}
@Test
def testHeader = {
val tsv = resourcePath("/test.summary.json")
val path = List("something=flexiprep:settings:skip_trim")
val paths = path.map(x => {
val split = x.split("=", 2)
split(0) -> split(1).split(":")
}).toMap
createHeader(paths) should equal("\tsomething")
}
@Test
def testLine = {
val tsv = resourcePath("/test.summary.json")
val path = List("something=flexiprep:settings:skip_trim")
val paths = path.map(x => {
val split = x.split("=", 2)
split(0) -> split(1).split(":")
}).toMap
val summary = new Summary(new File(tsv))
val values = fetchValues(summary, paths)
val line = values.head._2.keys.map(x => createLine(paths, values, x)).head
line should equal("value\t")
val sample_values = fetchValues(summary, paths, true, false)
val sample_line = sample_values.head._2.keys.map(x => createLine(paths, sample_values, x)).head
sample_line should equal("016\t")
val lib_values = fetchValues(summary, paths, false, true)
val lib_line = lib_values.head._2.keys.map(x => createLine(paths, lib_values, x)).head
lib_line should equal("016-L001\tfalse")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment