Commit 5edadca1 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Moved tags to the "tags" key

parent 4b86b485
......@@ -31,7 +31,7 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
require(globalConfig.map.contains("samples"), "No Samples found in config")
/** Sample class with basic functions build in */
abstract class AbstractSample(val sampleId: String) extends Summarizable {
abstract class AbstractSample(val sampleId: String) extends Summarizable { sample =>
/** Overrules config of qscript with default sample */
val config = new ConfigFunctions(defaultSample = sampleId)
......@@ -39,7 +39,7 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
def summarySettings: Map[String, Any] = Map()
/** Library class with basic functions build in */
abstract class AbstractLibrary(val libId: String) extends Summarizable {
abstract class AbstractLibrary(val libId: String) extends Summarizable { lib =>
/** Overrules config of qscript with default sample and default library */
val config = new ConfigFunctions(defaultSample = sampleId, defaultLibrary = libId)
......@@ -69,7 +69,16 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
/** Returns library directory */
def libDir = new File(sampleDir, "lib_" + libId)
lazy val libGroups: List[String] = config("groups", sample = sampleId, library = libId)
lazy val libTags: Map[String, Any] =
config("tags", default = Map(), freeVar = false, submodule = libId, path = List("samples", sampleId, "libraries"))
def sampleId = sample.sampleId
lazy val libGroups: List[String] = libTags.get("groups") match {
case Some(g: List[_]) => g.map(_.toString)
case Some(g: String) => List(g)
case _ => Nil
}
/** Function that add library jobs */
protected def addJobs()
......@@ -81,20 +90,23 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
/** Stores all libraries */
val libraries: Map[String, Library] = libIds.map(id => id -> makeLibrary(id)).toMap
lazy val sampleTags: Map[String, Any] =
config("tags", default = Map(), freeVar = false, submodule = sampleId, path = List("samples"))
lazy val gender = {
val g: Option[String] = config("gender", sample = sampleId, library = null)
val g: Option[String] = sampleTags.get("gender").map(_.toString)
g.map(_.toLowerCase) match {
case Some("male") => Gender.Male
case Some("female") => Gender.Female
case Some(s) =>
logger.warn(s"Could not convert '$g' to a gender")
Gender.Unknown
case _ => Gender.Unknown
case _ => Gender.Unknown
}
}
lazy val father = {
val g: Option[String] = config("father", sample = sampleId, library = null)
val g: Option[String] = sampleTags.get("father").map(_.toString)
g.foreach { father =>
if (sampleId != father) Logging.addError(s"Father for $sampleId can not be itself")
if (samples.contains(father)) if (samples(father).gender == Gender.Male)
......@@ -105,7 +117,7 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
}
lazy val mother = {
val g: Option[String] = config("mother", sample = sampleId, library = null)
val g: Option[String] = sampleTags.get("mother").map(_.toString)
g.foreach { mother =>
if (sampleId != mother) Logging.addError(s"mother for $sampleId can not be itself")
if (samples.contains(mother)) if (samples(mother).gender == Gender.Female)
......@@ -115,7 +127,11 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
g
}
lazy val sampleGroups: List[String] = config("groups", sample = sampleId, library = null)
lazy val sampleGroups: List[String] = sampleTags.get("groups") match {
case Some(g: List[_]) => g.map(_.toString)
case Some(g: String) => List(g)
case _ => Nil
}
/**
* Factory method for Library class
......
......@@ -14,8 +14,8 @@ import org.testng.annotations.Test
import scala.collection.mutable.ListBuffer
/**
* Created by pjvan_thof on 12/29/15.
*/
* Created by pjvan_thof on 12/29/15.
*/
class MultiSampleQScriptTest extends TestNGSuite with Matchers {
import MultiSampleQScriptTest._
......@@ -29,23 +29,25 @@ class MultiSampleQScriptTest extends TestNGSuite with Matchers {
script.functions.size shouldBe 5
script.samples.foreach { case (sampleId, sample) =>
sample.gender shouldBe Gender.Unknown
sample.father shouldBe None
sample.mother shouldBe None
sample.summaryFiles shouldBe Map()
sample.summaryStats shouldBe Map()
sample.summarySettings shouldBe Map()
sample.sampleDir shouldBe new File(script.outputDir, "samples" + File.separator + sampleId)
sample.createFile("bla.txt") shouldBe new File(sample.sampleDir, s"$sampleId.bla.txt")
sample.libraries.foreach { case (libId, library) =>
library.libDir shouldBe new File(sample.sampleDir, s"lib_$libId")
library.createFile("bla.txt") shouldBe new File(library.libDir, s"$sampleId-$libId.bla.txt")
library.summaryFiles shouldBe Map()
library.summaryStats shouldBe Map()
library.summarySettings shouldBe Map()
}
script.samples.foreach {
case (sampleId, sample) =>
sample.gender shouldBe Gender.Unknown
sample.father shouldBe None
sample.mother shouldBe None
sample.summaryFiles shouldBe Map()
sample.summaryStats shouldBe Map()
sample.summarySettings shouldBe Map()
sample.sampleDir shouldBe new File(script.outputDir, "samples" + File.separator + sampleId)
sample.createFile("bla.txt") shouldBe new File(sample.sampleDir, s"$sampleId.bla.txt")
sample.libraries.foreach {
case (libId, library) =>
library.libDir shouldBe new File(sample.sampleDir, s"lib_$libId")
library.createFile("bla.txt") shouldBe new File(library.libDir, s"$sampleId-$libId.bla.txt")
library.summaryFiles shouldBe Map()
library.summaryStats shouldBe Map()
library.summarySettings shouldBe Map()
}
}
}
......@@ -73,7 +75,7 @@ class MultiSampleQScriptTest extends TestNGSuite with Matchers {
script.functions.size shouldBe 5
script.samples("sample1").sampleGroups shouldBe List("1")
script.samples("sample1").libraries("lib1").libGroups shouldBe List("1")
script.samples("sample1").libraries("lib1").libGroups should not be List("1")
script.samples("sample2").sampleGroups shouldBe List("2")
script.samples("sample2").libraries("lib1").libGroups shouldBe List("3")
......@@ -92,17 +94,23 @@ class MultiSampleQScriptTest extends TestNGSuite with Matchers {
object MultiSampleQScriptTest {
val sample1 = Map("samples" -> Map("sample1" -> Map(
"gender" -> "blablablablabla",
"groups" -> List("1"),
"tags" -> Map(
"gender" -> "blablablablabla",
"groups" -> List("1")
),
"libraries" -> Map(
"lib1" -> Map("test" -> "1-1")
)))
)
val sample2 = Map("samples" -> Map("sample2" -> Map(
"groups" -> List("2"),
"tags" -> Map(
"groups" -> List("2")
),
"libraries" -> Map(
"lib1" -> Map("test" -> "2-1", "groups" -> List("3")),
"lib1" -> Map("test" -> "2-1", "tags" -> Map(
"groups" -> List("3")
)),
"lib2" -> Map("test" -> "2-2")
))))
......@@ -112,9 +120,10 @@ object MultiSampleQScriptTest {
"lib3" -> Map("test" -> "3-3")
))))
val child = Map("samples" -> Map("child" -> Map("gender" -> "male", "father" -> "father", "mother" -> "mother")))
val father = Map("samples" -> Map("father" -> Map("gender" -> "male")))
val mother = Map("samples" -> Map("mother" -> Map("gender" -> "female")))
val child = Map("samples" -> Map("child" -> Map("tags" -> Map(
"gender" -> "male", "father" -> "father", "mother" -> "mother"))))
val father = Map("samples" -> Map("father" -> Map("tags" -> Map("gender" -> "male"))))
val mother = Map("samples" -> Map("mother" -> Map("tags" -> Map("gender" -> "female"))))
def apply(configs: List[Map[String, Any]], only: List[String] = Nil) = {
new QScript with MultiSampleQScript { qscript =>
......@@ -124,7 +133,7 @@ object MultiSampleQScriptTest {
var buffer = new ListBuffer[String]()
override def globalConfig = new Config(configs
.foldLeft(Map[String, Any]()) { case (a, b) => ConfigUtils.mergeMaps(a, b)} )
.foldLeft(Map[String, Any]()) { case (a, b) => ConfigUtils.mergeMaps(a, b) })
val root = null
class Sample(id: String) extends AbstractSample(id) {
......@@ -142,10 +151,10 @@ object MultiSampleQScriptTest {
}
/**
* Factory method for Library class
* @param id SampleId
* @return Sample class
*/
* Factory method for Library class
* @param id SampleId
* @return Sample class
*/
def makeLibrary(id: String): Library = new Library(id)
/** Function to add sample jobs */
......@@ -163,17 +172,17 @@ object MultiSampleQScriptTest {
}
/**
* Method where the multisample jobs should be added, this will be executed only when running the -sample argument is not given.
*/
* Method where the multisample jobs should be added, this will be executed only when running the -sample argument is not given.
*/
def addMultiSampleJobs(): Unit = {
add(new Md5sum(qscript))
}
/**
* Factory method for Sample class
* @param id SampleId
* @return Sample class
*/
* Factory method for Sample class
* @param id SampleId
* @return Sample class
*/
def makeSample(id: String): Sample = new Sample(id)
/** Must return a map with used settings for this pipeline */
......
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