Commit 702a85e8 authored by Peter van 't Hof's avatar Peter van 't Hof Committed by GitHub

Merge pull request #171 from biopet/fix-BIOPET-759

Merge stats.json files
parents df582f1a 1a7fd7db
......@@ -165,7 +165,7 @@ case class Stats(generalStats: mutable.Map[String, mutable.Map[Any, Int]] = muta
sampleDistributions: List[String],
contig: Option[String]): Unit = {
outputDir.mkdirs()
this.writeToFile(new File(outputDir, "stats.json"),
this.writeToFile(new File(outputDir, s"${contig.getOrElse("total")}.json"),
samples,
genotypeFields,
infoFields,
......
......@@ -6,7 +6,7 @@ import java.net.URLClassLoader
import htsjdk.variant.variantcontext.{Genotype, VariantContext}
import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.intervals.{BedRecord, BedRecordList}
import nl.lumc.sasc.biopet.utils.{FastaUtils, ToolCommand, VcfUtils}
import nl.lumc.sasc.biopet.utils._
import org.apache.spark.{SparkConf, SparkContext}
import scala.collection.JavaConversions._
......@@ -108,6 +108,19 @@ object VcfStats extends ToolCommand {
Await.result(totalStats, Duration.Inf)
val completeStatsJson = regions
.flatMap(_.map(_.chr))
.foldLeft(ConfigUtils.fileToConfigMap(new File(cmdArgs.outputDir, "total.json"))) {
case (map, contig) =>
val contigMap = ConfigUtils.fileToConfigMap(
new File(cmdArgs.outputDir,
"contigs" + File.separator + contig + File.separator + s"$contig.json"))
ConfigUtils.mergeMaps(map, contigMap)
}
IoUtils.writeLinesToFile(new File(cmdArgs.outputDir, "stats.json"),
ConfigUtils.mapToJson(completeStatsJson).nospaces :: Nil)
sc.stop
logger.info("Done")
}
......
......@@ -284,44 +284,6 @@ class VcfStatsTest extends TestNGSuite with Matchers {
general.get("NotFiltered") shouldEqual Some(1)
general.get("Symbolic") shouldEqual Some(0)
general.get("SimpleInsertion") shouldEqual Some(1)
val total = generalStats
total.get("SampleDistribution-NonInformative") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-Called") shouldEqual Some(Map(3 -> 1))
total.get("SampleDistribution-Mixed") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-Hom") shouldEqual Some(Map(1 -> 1))
total.get("SampleDistribution-HomRef") shouldEqual Some(Map(1 -> 1))
total.get("SampleDistribution-Available") shouldEqual Some(Map(3 -> 1))
total.get("QUAL") shouldEqual Some(Map(1541 -> 1))
total.get("SampleDistribution-HetNonRef") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-Het") shouldEqual Some(Map(2 -> 1))
total.get("SampleDistribution-NoCall") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-Filtered") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-HomVar") shouldEqual Some(Map(0 -> 1))
total.get("SampleDistribution-Variant") shouldEqual Some(Map(2 -> 1))
generalStats.get("general") should not be empty
val totGeneral = generalStats("general")
totGeneral.get("PolymorphicInSamples") shouldEqual Some(1)
totGeneral.get("ComplexIndel") shouldEqual Some(0)
totGeneral.get("FullyDecoded") shouldEqual Some(0)
totGeneral.get("PointEvent") shouldEqual Some(0)
totGeneral.get("MNP") shouldEqual Some(0)
totGeneral.get("Indel") shouldEqual Some(1)
totGeneral.get("Biallelic") shouldEqual Some(1)
totGeneral.get("SimpleDeletion") shouldEqual Some(0)
totGeneral.get("Variant") shouldEqual Some(1)
totGeneral.get("SymbolicOrSV") shouldEqual Some(0)
totGeneral.get("MonomorphicInSamples") shouldEqual Some(0)
totGeneral.get("SNP") shouldEqual Some(0)
totGeneral.get("Filtered") shouldEqual Some(0)
totGeneral.get("StructuralIndel") shouldEqual Some(0)
totGeneral.get("Total") shouldEqual Some(1)
totGeneral.get("Mixed") shouldEqual Some(0)
totGeneral.get("NotFiltered") shouldEqual Some(1)
totGeneral.get("Symbolic") shouldEqual Some(0)
totGeneral.get("SimpleInsertion") shouldEqual Some(1)
}
@Test
......@@ -354,29 +316,5 @@ class VcfStatsTest extends TestNGSuite with Matchers {
general.get("Available") shouldEqual Some(1)
general.get("Het") shouldEqual Some(1)
general.get("HetNonRef") shouldEqual Some(0)
val total = genotypeStats
total.get("GQ") shouldEqual Some(Map(99 -> 1))
total.get("AD") shouldEqual Some(Map(24 -> 1, 21 -> 1))
total.get("AD-used") shouldEqual Some(Map(24 -> 1, 21 -> 1))
total.get("DP") shouldEqual Some(Map(45 -> 1))
total.get("AD-alt") shouldEqual Some(Map(21 -> 1))
total.get("AD-ref") shouldEqual Some(Map(24 -> 1))
total.get("general") should not be empty
val totGeneral = genotypeStats("general")
totGeneral.get("Hom") shouldEqual Some(0)
totGeneral.get("NoCall") shouldEqual Some(0)
totGeneral.get("Variant") shouldEqual Some(1)
totGeneral.get("Filtered") shouldEqual Some(0)
totGeneral.get("NonInformative") shouldEqual Some(0)
totGeneral.get("Called") shouldEqual Some(1)
totGeneral.get("Total") shouldEqual Some(1)
totGeneral.get("HomVar") shouldEqual Some(0)
totGeneral.get("HomRef") shouldEqual Some(0)
totGeneral.get("Mixed") shouldEqual Some(0)
totGeneral.get("Available") shouldEqual Some(1)
totGeneral.get("Het") shouldEqual Some(1)
totGeneral.get("HetNonRef") shouldEqual Some(0)
}
}
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