Commit c8ac4699 authored by Peter van 't Hof's avatar Peter van 't Hof

Begin to convert to scalaz \/

parent df4cf4cd
......@@ -25,6 +25,8 @@ import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scalaz._
import Scalaz._
class BammetricsReport(val parent: Configurable) extends ReportBuilderExtension {
def builder = BammetricsReport
......@@ -64,14 +66,14 @@ object BammetricsReport extends ReportBuilder {
//val pipelineId: Int = summary.getPipelineId(runId, metricsTag).map(_.get)
val wgsExecuted = summary.getStatsSize(runId, Right(metricsTag), Some(Right("wgs")), sample = sampleId.map(Left(_)), library = libId.map(Left(_))) >= 1
val rnaExecuted = summary.getStatsSize(runId, Right(metricsTag), Some(Right("rna")), sample = sampleId.map(Left(_)), library = libId.map(Left(_))) >= 1
val wgsExecuted = summary.getStatsSize(runId, metricsTag.right, Some("wgs".right), sample = sampleId.map(_.left), library = libId.map(_.left)) >= 1
val rnaExecuted = summary.getStatsSize(runId, metricsTag.right, Some("rna".right), sample = sampleId.map(_.left), library = libId.map(_.left)) >= 1
val insertsizeMetrics = summary.getStatKeys(runId, Right(metricsTag), Some(Right("CollectInsertSizeMetrics")),
sample = sampleId.map(Left(_)), library = libId.map(Left(_)), Map("metrics" -> List("metrics")))
val insertsizeMetrics = summary.getStatKeys(runId, metricsTag.right, Some("CollectInsertSizeMetrics".right),
sample = sampleId.map(_.left), library = libId.map(_.left), Map("metrics" -> List("metrics")))
.exists(_._2.isDefined)
val targetSettings = summary.getSettingKeys(runId, Right(metricsTag), None, sample = sampleId.map(Left(_)), library = libId.map(Left(_)),
val targetSettings = summary.getSettingKeys(runId, metricsTag.right, None, sample = sampleId.map(_.left), library = libId.map(_.left),
Map("amplicon_name" -> List("amplicon_name"), "roi_name" -> List("roi_name")))
val targets = (
targetSettings("amplicon_name"),
......@@ -132,10 +134,10 @@ object BammetricsReport extends ReportBuilder {
)
val results: Map[(Int, Option[Int]), Map[String, Option[Any]]] = if (libraryLevel) {
summary.getStatsForLibraries(runId, Right("bammetrics"), Some(Right("bamstats")),
summary.getStatsForLibraries(runId, "bammetrics".right, Some("bamstats".right),
sampleId = sampleId, keyValues = statsPaths).map(x => (x._1._1, Some(x._1._2)) -> x._2)
} else summary.getStatsForSamples(runId, Right("bammetrics"), Some(Right("bamstats")),
sample = sampleId.map(Left(_)), keyValues = statsPaths).map(x => (x._1, None) -> x._2)
} else summary.getStatsForSamples(runId, "bammetrics".right, Some("bamstats".right),
sample = sampleId.map(_.left), keyValues = statsPaths).map(x => (x._1, None) -> x._2)
for (((s, l), result) <- results) {
val sampleName: String = summary.getSampleName(s).map(_.get)
......@@ -175,8 +177,8 @@ object BammetricsReport extends ReportBuilder {
statsPaths: Map[String, List[String]],
xKey: String,
yKey: String,
pipeline: Either[Int, String],
module: Option[Either[Int, String]],
pipeline: \/[Int, String],
module: Option[\/[Int, String]],
xlabel: Option[String] = None,
ylabel: Option[String] = None,
title: Option[String] = None,
......@@ -187,7 +189,7 @@ object BammetricsReport extends ReportBuilder {
val results: Map[(Int, Option[Int]), Map[String, Option[Array[Any]]]] = if (libraryLevel) {
summary.getStatsForLibraries(runId, pipeline, module, sampleId = sampleId, keyValues = statsPaths)
.map(x => (x._1._1, Some(x._1._2)) -> x._2.map(x => x._1 -> x._2.map(ConfigUtils.any2list(_).toArray)))
} else summary.getStatsForSamples(runId, pipeline, module, sample = sampleId.map(Left(_)), keyValues = statsPaths)
} else summary.getStatsForSamples(runId, pipeline, module, sample = sampleId.map(_.left), keyValues = statsPaths)
.map(x => (x._1, None) -> x._2.map(x => x._1 -> x._2.map(ConfigUtils.any2list(_).toArray)))
val tables: Array[Map[String, Array[Any]]] = results.map {
......@@ -231,7 +233,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"insert_size", "count", Right("bammetrics"), Some(Right("CollectInsertSizeMetrics")),
"insert_size", "count", "bammetrics".right, Some("CollectInsertSizeMetrics".right),
"Insert size", "Reads", "Insert size")
}
......@@ -247,7 +249,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"mapping_quality", "count", Right("bammetrics"), Some(Right("bamstats")),
"mapping_quality", "count", "bammetrics".right, Some("bamstats".right),
"Mapping quality", "Reads", "Mapping quality")
}
......@@ -263,7 +265,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"clipping", "count", Right("bammetrics"), Some(Right("bamstats")),
"clipping", "count", "bammetrics".right, Some("bamstats".right),
"Clipping", "Reads", "Clipping")
}
......@@ -288,7 +290,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"coverage", "count", Right("bammetrics"), Some(Right("wgs")),
"coverage", "count", "bammetrics".right, Some("wgs".right),
"Coverage", "Bases", "Whole genome coverage")
}
......@@ -313,7 +315,7 @@ object BammetricsReport extends ReportBuilder {
)
writePlotFromSummary(outputDir, prefix, summary, libraryLevel, sampleId, libraryId, statsPaths,
"coverage", "count", Right("bammetrics"), Some(Right("rna")),
"coverage", "count", "bammetrics".right, Some("rna".right),
"Relative position", "Coverage", "Rna coverage")
}
......
......@@ -14,7 +14,7 @@
*/
package nl.lumc.sasc.biopet.core.extensions
import java.io.{File, FileOutputStream}
import java.io.{ File, FileOutputStream }
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.utils.Logging
......
......@@ -32,6 +32,8 @@ import org.testng.annotations.{ AfterClass, Test }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scala.util.matching.Regex
import scalaz._
import Scalaz._
/**
* Created by pjvanthof on 15/01/16.
......@@ -98,8 +100,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -119,8 +121,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -140,8 +142,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -161,8 +163,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), Some(Right("sampleName")), Some(Right("libName")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), Some(Right("sampleName")), Some(Right("libName")), key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), Some("sampleName".right), Some("libName".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), Some("sampleName".right), Some("libName".right), key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@Test
......@@ -202,8 +204,8 @@ class WriteSummaryTest extends TestNGSuite with Matchers {
val summary = SummaryDb.openSqliteSummary(qscript.summaryDbFile)
basicSummaryTest(summary, qscript.summaryRunId, dir)
summary.getStatKeys(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, Right("test"), Some(Right("tool_1")), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
summary.getStatKeys(qscript.summaryRunId, "test".right, Some("tool_1".right), keyValues = Map("key" -> List("key"))) shouldBe Map("key" -> Some("value"))
Await.result(summary.getFile(qscript.summaryRunId, "test".right, Some("tool_1".right), None, None, key = "file_1"), Duration.Inf).map(_.md5) shouldBe Some("checksum")
}
@AfterClass
......
......@@ -10,6 +10,9 @@ import org.testng.annotations.Test
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import scalaz._
import Scalaz._
/**
* Testing voor [[SummaryDb]]
* Created by pjvanthof on 14/02/2017.
......@@ -133,9 +136,9 @@ class SummaryDbTest extends TestNGSuite with Matchers {
db.createTables()
Await.result(db.createOrUpdateSetting(0, 0, None, None, None, """{"content": "test" }"""), Duration.Inf)
Await.result(db.getSetting(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.getSetting(0, 0.left, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.createOrUpdateSetting(0, 0, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Await.result(db.getSetting(0, Left(0), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
Await.result(db.getSetting(0, 0.left, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
db.close()
}
......@@ -155,9 +158,9 @@ class SummaryDbTest extends TestNGSuite with Matchers {
|}
| }""".stripMargin), Duration.Inf)
db.getSettingKeys(0, Left(0), Some(Left(0)), Some(Left(0)), Some(Left(0)), keyValues = Map()) shouldBe Map()
db.getSettingKeys(0, Left(0), Some(Left(0)), Some(Left(0)), Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map("content" -> Some("test"))
db.getSettingKeys(0, Left(0), Some(Left(0)), Some(Left(0)), Some(Left(0)), keyValues = Map("content" -> List("content2", "key"))) shouldBe Map("content" -> Some("value"))
db.getSettingKeys(0, 0.left, Some(0.left), Some(0.left), Some(0.left), keyValues = Map()) shouldBe Map()
db.getSettingKeys(0, 0.left, Some(0.left), Some(0.left), Some(0.left), keyValues = Map("content" -> List("content"))) shouldBe Map("content" -> Some("test"))
db.getSettingKeys(0, 0.left, Some(0.left), Some(0.left), Some(0.left), keyValues = Map("content" -> List("content2", "key"))) shouldBe Map("content" -> Some("value"))
db.close()
}
......@@ -180,8 +183,8 @@ class SummaryDbTest extends TestNGSuite with Matchers {
|}
| }""".stripMargin), Duration.Inf)
db.getSettingsForSamples(0, Left(0), Some(Left(0)), keyValues = Map()) shouldBe Map(0 -> Map())
db.getSettingsForSamples(0, Left(0), Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map(0 -> Map("content" -> Some("test")))
db.getSettingsForSamples(0, 0.left, Some(0.left), keyValues = Map()) shouldBe Map(0 -> Map())
db.getSettingsForSamples(0, 0.left, Some(0.left), keyValues = Map("content" -> List("content"))) shouldBe Map(0 -> Map("content" -> Some("test")))
db.close()
}
......@@ -205,8 +208,8 @@ class SummaryDbTest extends TestNGSuite with Matchers {
|}
| }""".stripMargin), Duration.Inf)
db.getSettingsForLibraries(0, Left(0), Some(Left(0)), keyValues = Map()) shouldBe Map((0, 0) -> Map())
db.getSettingsForLibraries(0, Left(0), Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map((0, 0) -> Map("content" -> Some("test")))
db.getSettingsForLibraries(0, 0.left, Some(0.left), keyValues = Map()) shouldBe Map((0, 0) -> Map())
db.getSettingsForLibraries(0, 0.left, Some(0.left), keyValues = Map("content" -> List("content"))) shouldBe Map((0, 0) -> Map("content" -> Some("test")))
db.close()
}
......@@ -227,15 +230,15 @@ class SummaryDbTest extends TestNGSuite with Matchers {
Await.result(db.getStatsSize(), Duration.Inf) shouldBe 0
Await.result(db.createOrUpdateStat(runId, pipelineId, None, None, None, """{"content": "test" }"""), Duration.Inf)
Await.result(db.getStat(runId, Left(pipelineId), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.getStat(runId, pipelineId.left, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test"))
Await.result(db.getStatsSize(), Duration.Inf) shouldBe 1
Await.result(db.createOrUpdateStat(runId, pipelineId, None, None, None, """{"content": "test2" }"""), Duration.Inf)
Await.result(db.getStat(runId, Left(pipelineId), None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
Await.result(db.getStat(runId, pipelineId.left, None, None, None), Duration.Inf) shouldBe Some(Map("content" -> "test2"))
Await.result(db.getStatsSize(), Duration.Inf) shouldBe 1
// Test join queries
Await.result(db.createOrUpdateStat(runId, pipelineId, Some(moduleId), Some(sampleId), Some(libraryId), """{"content": "test3" }"""), Duration.Inf)
Await.result(db.getStat(runId, Right("test_pipeline"), Some(Right("test_module")), Some(Right("test_sample")), Some(Right("test_library"))), Duration.Inf) shouldBe Some(Map("content" -> "test3"))
Await.result(db.getStat(runId, "test_pipeline".right, Some("test_module".right), Some("test_sample".right), Some("test_library".right)), Duration.Inf) shouldBe Some(Map("content" -> "test3"))
Await.result(db.getStatsSize(), Duration.Inf) shouldBe 2
db.close()
......@@ -257,9 +260,9 @@ class SummaryDbTest extends TestNGSuite with Matchers {
|}
| }""".stripMargin), Duration.Inf)
db.getStatKeys(0, Left(0), Some(Left(0)), Some(Left(0)), Some(Left(0)), keyValues = Map()) shouldBe Map()
db.getStatKeys(0, Left(0), Some(Left(0)), Some(Left(0)), Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map("content" -> Some("test"))
db.getStatKeys(0, Left(0), Some(Left(0)), Some(Left(0)), Some(Left(0)), keyValues = Map("content" -> List("content2", "key"))) shouldBe Map("content" -> Some("value"))
db.getStatKeys(0, 0.left, Some(0.left), Some(0.left), Some(0.left), keyValues = Map()) shouldBe Map()
db.getStatKeys(0, 0.left, Some(0.left), Some(0.left), Some(0.left), keyValues = Map("content" -> List("content"))) shouldBe Map("content" -> Some("test"))
db.getStatKeys(0, 0.left, Some(0.left), Some(0.left), Some(0.left), keyValues = Map("content" -> List("content2", "key"))) shouldBe Map("content" -> Some("value"))
db.close()
}
......@@ -282,8 +285,8 @@ class SummaryDbTest extends TestNGSuite with Matchers {
|}
| }""".stripMargin), Duration.Inf)
db.getStatsForSamples(0, Left(0), Some(Left(0)), keyValues = Map()) shouldBe Map(0 -> Map())
db.getStatsForSamples(0, Left(0), Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map(0 -> Map("content" -> Some("test")))
db.getStatsForSamples(0, 0.left, Some(0.left), keyValues = Map()) shouldBe Map(0 -> Map())
db.getStatsForSamples(0, 0.left, Some(0.left), keyValues = Map("content" -> List("content"))) shouldBe Map(0 -> Map("content" -> Some("test")))
db.close()
}
......@@ -307,8 +310,8 @@ class SummaryDbTest extends TestNGSuite with Matchers {
|}
| }""".stripMargin), Duration.Inf)
db.getStatsForLibraries(0, Left(0), Some(Left(0)), keyValues = Map()) shouldBe Map((0, 0) -> Map())
db.getStatsForLibraries(0, Left(0), Some(Left(0)), keyValues = Map("content" -> List("content"))) shouldBe Map((0, 0) -> Map("content" -> Some("test")))
db.getStatsForLibraries(0, 0.left, Some(0.left), keyValues = Map()) shouldBe Map((0, 0) -> Map())
db.getStatsForLibraries(0, 0.left, Some(0.left), keyValues = Map("content" -> List("content"))) shouldBe Map((0, 0) -> Map("content" -> Some("test")))
db.close()
}
......@@ -327,15 +330,15 @@ class SummaryDbTest extends TestNGSuite with Matchers {
val libraryId = Await.result(db.createLibrary("test_library", runId, sampleId), Duration.Inf)
Await.result(db.createOrUpdateFile(runId, pipelineId, None, None, None, "key", "path", "md5", link = false, 1), Duration.Inf)
Await.result(db.getFile(runId, Left(pipelineId), None, None, None, "key"), Duration.Inf) shouldBe Some(Schema.File(0, 0, None, None, None, "key", "path", "md5", link = false, 1))
Await.result(db.getFile(runId, pipelineId.left, None, None, None, "key"), Duration.Inf) shouldBe Some(Schema.File(0, 0, None, None, None, "key", "path", "md5", link = false, 1))
Await.result(db.getFiles(), Duration.Inf) shouldBe Seq(Schema.File(0, 0, None, None, None, "key", "path", "md5", link = false, 1))
Await.result(db.createOrUpdateFile(runId, pipelineId, None, None, None, "key", "path2", "md5", link = false, 1), Duration.Inf)
Await.result(db.getFile(runId, Left(pipelineId), None, None, None, "key"), Duration.Inf) shouldBe Some(Schema.File(0, 0, None, None, None, "key", "path2", "md5", link = false, 1))
Await.result(db.getFile(runId, pipelineId.left, None, None, None, "key"), Duration.Inf) shouldBe Some(Schema.File(0, 0, None, None, None, "key", "path2", "md5", link = false, 1))
Await.result(db.getFiles(), Duration.Inf) shouldBe Seq(Schema.File(0, 0, None, None, None, "key", "path2", "md5", link = false, 1))
// Test join queries
Await.result(db.createOrUpdateFile(runId, pipelineId, Some(moduleId), Some(sampleId), Some(libraryId), "key", "path3", "md5", link = false, 1), Duration.Inf)
Await.result(db.getFile(runId, Right("test_pipeline"), Some(Right("test_module")), Some(Right("test_sample")), Some(Right("test_library")), "key"), Duration.Inf) shouldBe Some(Schema.File(0, 0, Some(moduleId), Some(sampleId), Some(libraryId), "key", "path3", "md5", link = false, 1))
Await.result(db.getFile(runId, "test_pipeline".right, Some("test_module".right), Some("test_sample".right), Some("test_library".right), "key"), Duration.Inf) shouldBe Some(Schema.File(0, 0, Some(moduleId), Some(sampleId), Some(libraryId), "key", "path3", "md5", link = false, 1))
Await.result(db.getFiles(), Duration.Inf) shouldBe Seq(Schema.File(0, 0, None, None, None, "key", "path2", "md5", link = false, 1), Schema.File(0, 0, Some(moduleId), Some(sampleId), Some(libraryId), "key", "path3", "md5", link = false, 1))
db.close()
......
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