Commit 0f03cdf4 authored by Peter van 't Hof's avatar Peter van 't Hof

Reducing number of tests in gentrap

parent 0bc09ac2
......@@ -27,7 +27,7 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
@Argument(doc = "Only Sample", shortName = "s", required = false, fullName = "sample")
private[core] val onlySamples: List[String] = Nil
require(globalConfig.map.contains("samples"), "No Samples found in config")
if (!globalConfig.map.contains("samples")) Logging.addError("No Samples found in config")
/** Sample class with basic functions build in */
abstract class AbstractSample(val sampleId: String) extends Summarizable { sample =>
......@@ -190,7 +190,7 @@ trait MultiSampleQScript extends SummaryQScript { qscript: QScript =>
val samples: Map[String, Sample] = sampleIds.map(id => id -> makeSample(id)).toMap
/** Returns a list of all sampleIDs */
protected def sampleIds: Set[String] = ConfigUtils.any2map(globalConfig.map("samples")).keySet
protected def sampleIds: Set[String] = ConfigUtils.any2map(globalConfig.map.getOrElse("samples", Map())).keySet
protected lazy val nameRegex = """^[a-zA-Z0-9][a-zA-Z0-9-_]+[a-zA-Z0-9]$""".r
protected lazy val nameError = "has an invalid name. " +
......
......@@ -14,22 +14,22 @@
*/
package nl.lumc.sasc.biopet.pipelines.gentrap
import java.io.{ File, FileOutputStream }
import java.io.{File, FileOutputStream}
import com.google.common.io.Files
import nl.lumc.sasc.biopet.core.{ BiopetFifoPipe, BiopetPipe }
import nl.lumc.sasc.biopet.core.{BiopetFifoPipe, BiopetPipe}
import nl.lumc.sasc.biopet.extensions._
import nl.lumc.sasc.biopet.extensions.gmap.Gsnap
import nl.lumc.sasc.biopet.extensions.hisat.Hisat2
import nl.lumc.sasc.biopet.extensions.tools.{ BaseCounter, WipeReads }
import nl.lumc.sasc.biopet.utils.ConfigUtils
import nl.lumc.sasc.biopet.extensions.tools.{BaseCounter, WipeReads}
import nl.lumc.sasc.biopet.utils.{ConfigUtils, Logging}
import nl.lumc.sasc.biopet.utils.config.Config
import org.broadinstitute.gatk.queue.QSettings
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.{ DataProvider, Test }
import org.testng.annotations.{DataProvider, Test}
abstract class GentrapTestAbstract(val expressionMeasure: String, val aligner: Option[String]) extends TestNGSuite with Matchers {
abstract class GentrapTestAbstract(val expressionMeasures: List[String]) extends TestNGSuite with Matchers {
def initPipeline(map: Map[String, Any]): Gentrap = {
new Gentrap() {
......@@ -42,104 +42,82 @@ abstract class GentrapTestAbstract(val expressionMeasure: String, val aligner: O
}
}
/** Convenience method for making library config */
private def makeLibConfig(idx: Int, paired: Boolean = true) = {
val files = Map("R1" -> GentrapTest.inputTouch("test_R1.fq"))
if (paired) (s"lib_$idx", files ++ Map("R2" -> GentrapTest.inputTouch("test_R2.fq")))
else (s"lib_$idx", files)
}
/** Convenience type for sample config */
private type SamplesConfig = Map[String, Map[String, Map[String, Map[String, Map[String, String]]]]]
/** Convenience method for making a single sample config */
private def makeSampleConfig(sampleIdx: Int, numLibs: Int, paired: Boolean) =
(s"sample_$sampleIdx",
Map("libraries" ->
(1 to numLibs)
.map(n => makeLibConfig(n, paired))
.toMap
)
)
def strandProtocols = Array("non_specific", "dutp")
/** Convenience method for making all samples config */
private def makeSamplesConfig(numSamples: Int, numLibsEachSample: Int, pairMode: String): SamplesConfig =
Map("samples" ->
(1 to numSamples)
// if paired == "mixed", alternate paired/not paired between each number
.map(n => makeSampleConfig(n, numLibsEachSample, if (pairMode == "mixed") n % 2 == 0 else pairMode == "paired"))
.toMap
)
def aligner: Option[String] = None
def removeRiboReads: Option[Boolean] = Some(false)
def sample1: Boolean = true
def sample2: Boolean = true
@DataProvider(name = "expMeasuresstrandProtocol")
def expMeasuresStrandProtocolProvider = {
//val sampleConfigs = Array(pairedOneSampleOneLib, pairedOneSampleTwoLib, pairedOneSampleThreeLib)
val sampleConfigs = for {
(sampleNum, libNum) <- Seq(
// check multiple libs for single run only ~ to trim down less-informative tests
// need to check 2 and 3 samples since multi-sample plotting differs when sample is 1 or 2 and 3
(1, 1), (1, 2), (2, 1), (3, 1)
)
libType <- Seq("paired", "single", "mixed")
} yield makeSamplesConfig(sampleNum, libNum, libType)
val strandProtocols = Array("non_specific", "dutp")
for {
sampleConfig <- sampleConfigs.toArray
strandProtocol <- strandProtocols
removeRiboReads <- Array(true, false)
} yield Array(sampleConfig, List(expressionMeasure), strandProtocol, removeRiboReads)
} yield Array(strandProtocol)
}
@Test(dataProvider = "expMeasuresstrandProtocol")
def testGentrap(sampleConfig: SamplesConfig, expMeasures: List[String], strandProtocol: String, removeRiboReads: Boolean) = {
def testGentrap(strandProtocol: String) = {
val settings = Map(
"output_dir" -> GentrapTest.outputDir,
"gsnap" -> Map("db" -> "test", "dir" -> "test"),
"expression_measures" -> expMeasures,
"strand_protocol" -> strandProtocol,
"remove_ribosomal_reads" -> removeRiboReads
) ++ aligner.map("aligner" -> _)
val config = ConfigUtils.mergeMaps(settings ++ sampleConfig, Map(GentrapTest.executables.toSeq: _*))
"expression_measures" -> expressionMeasures,
"strand_protocol" -> strandProtocol
) ++
aligner.map("aligner" -> _) ++
removeRiboReads.map("remove_ribosomal_reads" -> _)
val configs: List[Option[Map[String, Any]]] = List(Some(settings), (if (sample1) Some(GentrapTest.sample1) else None), (if (sample2) Some(GentrapTest.sample2) else None))
val config = configs.flatten.foldLeft(GentrapTest.executables)( (a,b) => ConfigUtils.mergeMaps(a, b))
val gentrap: Gentrap = initPipeline(config)
val numSamples = (sample1, sample2) match {
case (true, true) => 2
case (_, true) => 1
case (true, _) => 1
case _ => 0
}
if (numSamples == 0) {
intercept[IllegalArgumentException] {
gentrap.script()
}
Logging.errors.clear()
} else {
gentrap.script()
val functions = gentrap.functions.flatMap {
case f: BiopetFifoPipe => f.pipesJobs
case f: BiopetPipe => f.pipesJobs
case f => List(f)
}.groupBy(_.getClass)
val numSamples = sampleConfig("samples").size
if (expMeasures.contains("fragments_per_gene"))
if (expressionMeasures.contains("fragments_per_gene"))
assert(gentrap.functions.exists(_.isInstanceOf[HtseqCount]))
if (expMeasures.contains("fragments_per_exon"))
if (expressionMeasures.contains("fragments_per_exon"))
assert(gentrap.functions.exists(_.isInstanceOf[HtseqCount]))
if (expMeasures.contains("base_counts"))
if (expressionMeasures.contains("base_counts"))
gentrap.functions.count(_.isInstanceOf[BaseCounter]) shouldBe numSamples
if (expMeasures.contains("cufflinks_strict")) {
if (expressionMeasures.contains("cufflinks_strict")) {
assert(gentrap.functions.exists(_.isInstanceOf[Cufflinks]))
assert(gentrap.functions.exists(_.isInstanceOf[Ln]))
}
if (expMeasures.contains("cufflinks_guided")) {
if (expressionMeasures.contains("cufflinks_guided")) {
assert(gentrap.functions.exists(_.isInstanceOf[Cufflinks]))
assert(gentrap.functions.exists(_.isInstanceOf[Ln]))
}
if (expMeasures.contains("cufflinks_blind")) {
if (expressionMeasures.contains("cufflinks_blind")) {
assert(gentrap.functions.exists(_.isInstanceOf[Cufflinks]))
assert(gentrap.functions.exists(_.isInstanceOf[Ln]))
}
gentrap.removeRibosomalReads shouldBe removeRiboReads
gentrap.functions.exists(_.isInstanceOf[WipeReads]) shouldBe removeRiboReads
gentrap.removeRibosomalReads shouldBe removeRiboReads.getOrElse(false)
gentrap.functions.exists(_.isInstanceOf[WipeReads]) shouldBe removeRiboReads.getOrElse(false)
val classMap = Map(
"gsnap" -> classOf[Gsnap],
......@@ -154,15 +132,24 @@ abstract class GentrapTestAbstract(val expressionMeasure: String, val aligner: O
alignerClass.foreach(c => assert(functions.keys.exists(_ == c)))
classMap.values.filterNot(Some(_) == alignerClass).foreach(x => assert(!functions.keys.exists(_ == x)))
}
}
}
class GentrapFragmentsPerGeneTest extends GentrapTestAbstract("fragments_per_gene", None)
//class GentrapFragmentsPerExonTest extends GentrapTestAbstract("fragments_per_exon", None)
class GentrapBaseCountsTest extends GentrapTestAbstract("base_counts", None)
class GentrapCufflinksStrictTest extends GentrapTestAbstract("cufflinks_strict", None)
class GentrapCufflinksGuidedTest extends GentrapTestAbstract("cufflinks_guided", None)
class GentrapCufflinksBlindTest extends GentrapTestAbstract("cufflinks_blind", None)
class GentrapFragmentsPerGeneTest extends GentrapTestAbstract(List("fragments_per_gene"))
//class GentrapFragmentsPerExonTest extends GentrapTestAbstract("fragments_per_exon")
class GentrapBaseCountsTest extends GentrapTestAbstract(List("base_counts"))
class GentrapCufflinksStrictTest extends GentrapTestAbstract(List("cufflinks_strict"))
class GentrapCufflinksGuidedTest extends GentrapTestAbstract(List("cufflinks_guided"))
class GentrapCufflinksBlindTest extends GentrapTestAbstract(List("cufflinks_blind"))
class GentrapAllTest extends GentrapTestAbstract(List("fragments_per_gene", "base_counts", "cufflinks_strict", "cufflinks_guided", "cufflinks_blind"))
class GentrapNoSamplesTest extends GentrapTestAbstract(List("fragments_per_gene")) {
override def sample1 = false
override def sample2 = false
}
class GentrapRemoveRibosomeTest extends GentrapTestAbstract(List("fragments_per_gene")) {
override def removeRiboReads = Some(true)
}
object GentrapTest {
val outputDir = Files.createTempDir()
......@@ -185,7 +172,7 @@ object GentrapTest {
copyFile("ref.dict")
copyFile("ref.fa.fai")
val executables = Map(
val executables: Map[String, Any] = Map(
"reference_fasta" -> (outputDir + File.separator + "ref.fa"),
"refFlat" -> (outputDir + File.separator + "ref.fa"),
"annotation_gtf" -> (outputDir + File.separator + "ref.fa"),
......@@ -204,4 +191,26 @@ object GentrapTest {
// bam2wig executables
"igvtools", "wigtobigwig"
).map { case exe => exe -> Map("exe" -> "test") }.toMap
val sample1: Map[String, Any] = Map(
"samples" -> Map("sample1" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> inputTouch("1_1_R1.fq"),
"R2" -> inputTouch("1_1_R2.fq")
)
)
)))
val sample2: Map[String, Any] = Map(
"samples" -> Map("sample3" -> Map("libraries" -> Map(
"lib1" -> Map(
"R1" -> inputTouch("2_1_R1.fq"),
"R2" -> inputTouch("2_1_R2.fq")
),
"lib2" -> Map(
"R1" -> inputTouch("2_2_R1.fq"),
"R2" -> inputTouch("2_2_R2.fq")
)
)
)))
}
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