Commit 5a853052 authored by bow's avatar bow
Browse files

Merge branch 'fix-seqstat_merge' into 'develop'

fix seqstat merge summary

See merge request !196
parents 9a1b11ee d9732c8a
......@@ -57,9 +57,12 @@ class SeqStat(val root: Configurable) extends ToolCommandFuntion with Summarizab
override def resolveSummaryConflict(v1: Any, v2: Any, key: String): Any = {
(v1, v2) match {
case (v1: Array[_], v2: Array[_]) => v1.zip(v2).map(v => resolveSummaryConflict(v._1, v._2, key))
case (v1: List[_], v2: List[_]) => v1.zip(v2).map(v => resolveSummaryConflict(v._1, v._2, key))
case (v1: Int, v2: Int) if key == "len_min" => if (v1 < v2) v1 else v2
case (v1: Int, v2: Int) if key == "len_max" => if (v1 > v2) v1 else v2
case (v1: Int, v2: Int) => v1 + v2
case (v1: Long, v2: Long) => v1 + v2
case _ => v1
}
}
......
......@@ -46,7 +46,7 @@ object ConfigUtils extends Logging {
map1(key) match {
case m1: Map[_, _] =>
map2(key) match {
case m2: Map[_, _] => newMap += (key -> mergeMaps(any2map(m1), any2map(m2)))
case m2: Map[_, _] => newMap += (key -> mergeMaps(any2map(m1), any2map(m2), resolveConflict))
case _ => newMap += (key -> map1(key))
}
case _ => newMap += (key -> resolveConflict(map1(key), map2(key), key))
......
......@@ -205,7 +205,26 @@ class ConfigUtilsTest extends TestNGSuite with Matchers {
//TODO: test BiopetQScript error message
}
}
@Test def testMergeConflict: Unit = {
val map1 = Map("c" -> "1")
val map2 = Map("c" -> "2")
mergeMaps(map1, map2) shouldBe Map("c" -> "1")
mergeMaps(map1, map2, (a, b, k) => a.toString + b.toString) shouldBe Map("c" -> "12")
mergeMaps(map2, map1, (a, b, k) => a.toString + b.toString) shouldBe Map("c" -> "21")
mergeMaps(map2, map2, (a, b, k) => a.toString + b.toString) shouldBe Map("c" -> "22")
}
@Test def testNestedMergeConflict: Unit = {
val map1 = Map("c" -> Map("x" -> "1"))
val map2 = Map("c" -> Map("x" -> "2"))
mergeMaps(map1, map2) shouldBe Map("c" -> Map("x" -> "1"))
mergeMaps(map1, map2, (a, b, k) => a.toString + b.toString) shouldBe Map("c" -> Map("x" -> "12"))
mergeMaps(map2, map1, (a, b, k) => a.toString + b.toString) shouldBe Map("c" -> Map("x" -> "21"))
mergeMaps(map2, map2, (a, b, k) => a.toString + b.toString) shouldBe Map("c" -> Map("x" -> "22"))
}
}
object ConfigUtilsTest {
def writeTemp(text: String, extension: String): File = {
val file = File.createTempFile("TestConfigUtils.", extension)
......
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