Commit f5f18a61 authored by bow's avatar bow
Browse files

Add 'readAll' attribute to seq stats for combining read1 and read2 stats

parent ba7ca1c2
......@@ -1440,6 +1440,20 @@ class StatsControllerSpec extends SentinelServletSpec {
priorResponse.body must /("read2") / "pctBasesC" /("nDataPoints" -> 2)
priorResponse.body must /("read2") / "pctBasesN" /("nDataPoints" -> 2)
priorResponse.body must /("read2") / "pctBasesGC" /("nDataPoints" -> 2)
// readAll
priorResponse.body must /("readAll") / "nBases" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesA" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesT" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesG" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesC" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesN" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nReads" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesA" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesT" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesG" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesC" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesN" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesGC" /("nDataPoints" -> 6)
}
}
}
......@@ -1485,6 +1499,20 @@ class StatsControllerSpec extends SentinelServletSpec {
priorResponse.body must /("read2") / "pctBasesC" /("nDataPoints" -> 2)
priorResponse.body must /("read2") / "pctBasesN" /("nDataPoints" -> 2)
priorResponse.body must /("read2") / "pctBasesGC" /("nDataPoints" -> 2)
// readAll
priorResponse.body must /("readAll") / "nBases" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "nBasesA" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "nBasesT" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "nBasesG" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "nBasesC" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "nBasesN" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "nReads" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "pctBasesA" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "pctBasesT" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "pctBasesG" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "pctBasesC" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "pctBasesN" /("nDataPoints" -> 2)
priorResponse.body must /("readAll") / "pctBasesGC" /("nDataPoints" -> 2)
}
}
}
......@@ -1518,6 +1546,8 @@ class StatsControllerSpec extends SentinelServletSpec {
priorResponse.body must /("read1") / "pctBasesGC" /("nDataPoints" -> 4)
// read2
priorResponse.body must not / "read2"
// readAll
priorResponse.body must not / "readAll"
}
}
}
......@@ -1563,6 +1593,20 @@ class StatsControllerSpec extends SentinelServletSpec {
priorResponse.body must /("read2") / "pctBasesC" /("nDataPoints" -> 2)
priorResponse.body must /("read2") / "pctBasesN" /("nDataPoints" -> 2)
priorResponse.body must /("read2") / "pctBasesGC" /("nDataPoints" -> 2)
// readAll
priorResponse.body must /("readAll") / "nBases" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesA" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesT" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesG" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesC" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nBasesN" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "nReads" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesA" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesT" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesG" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesC" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesN" /("nDataPoints" -> 6)
priorResponse.body must /("readAll") / "pctBasesGC" /("nDataPoints" -> 6)
}
"return a different object than when qcPhase is set to 'processed'" in {
......
......@@ -25,9 +25,26 @@ import nl.lumc.sasc.sentinel.utils.pctOf
*
* @param read1 Statistics of the first read (if paired-end) or the only read (if single-end).
* @param read2 Statistics of the second read. Only defined for paired-end inputs.
* @param labels data point labels.
* @param labels Data point labels.
*/
case class SeqStats(read1: ReadStats, read2: Option[ReadStats] = None, labels: Option[DataPointLabels] = None)
case class SeqStats(read1: ReadStats, read2: Option[ReadStats] = None, labels: Option[DataPointLabels] = None) {
/** Combined counts for both read1 and read2 (if present). */
@Persist lazy val readAll: ReadStats = read2 match {
case Some(r2) =>
ReadStats(
nBases = read1.nBases + r2.nBases,
nBasesA = read1.nBasesA + r2.nBasesA,
nBasesT = read1.nBasesT + r2.nBasesT,
nBasesG = read1.nBasesG + r2.nBasesG,
nBasesC = read1.nBasesC + r2.nBasesC,
nBasesN = read1.nBasesN + r2.nBasesN,
nReads = read1.nReads, // nReads for each pair is equal
nBasesByQual = Seq.empty[Long],
medianQualByPosition = Seq.empty[Double])
case otherwise => read1
}
}
// TODO: generate the aggregate stats programmatically (using macros?)
/**
......@@ -35,8 +52,11 @@ case class SeqStats(read1: ReadStats, read2: Option[ReadStats] = None, labels: O
*
* @param read1 Aggregated statistics of the first read (if paired-end) or the only read (if single-end).
* @param read2 Aggregated statistics of the second read. Only defined for paired-end inputs.
* @param readAll Aggregated statistics of both reads. Only defined if there is at least a paired-end data point
* in aggregation.
*/
case class SeqStatsAggr(read1: ReadStatsAggr, read2: Option[ReadStatsAggr] = None)
case class SeqStatsAggr(read1: ReadStatsAggr, read2: Option[ReadStatsAggr] = None,
readAll: Option[ReadStatsAggr] = None)
/**
* Statistics of a single read file.
......
......@@ -519,7 +519,10 @@ class GentrapOutputProcessor(protected val mongo: MongodbAccessObject) extends M
"pctBasesN",
"pctBasesGC")
val readNames = Seq("read1", "read2")
val readNames = libType match {
case Some(LibType.Single) => Seq("read1")
case otherwise => Seq("read1", "read2", "readAll")
}
val aggrStats = readNames.par
.map {
......@@ -529,8 +532,13 @@ class GentrapOutputProcessor(protected val mongo: MongodbAccessObject) extends M
.foldLeft(MongoDBObject.empty) { case (acc, x) => acc ++ x }
if (res.nonEmpty) (rn, Option(grater[ReadStatsAggr].asObject(res)))
else (rn, None)
}.seq.toMap
}.seq
.filter { case (rn, res) => res.isDefined }
.map { case (rn, res) => (rn, res.get) }
.toMap
aggrStats("read1").collect { case r1 => SeqStatsAggr(read1 = r1, read2 = aggrStats("read2")) }
aggrStats.get("read1").collect {
case r1 => SeqStatsAggr(read1 = r1, read2 = aggrStats.get("read2"), readAll = aggrStats.get("readAll"))
}
}
}
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