SampleStats.scala 1.09 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1 2 3 4 5
package nl.lumc.sasc.biopet.tools.vcfstats

import scala.collection.mutable

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
6 7 8 9 10
 * class to store all sample relative stats
 *
 * @param genotypeStats Stores all genotype relative stats
 * @param sampleToSample Stores sample to sample compare stats
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
11 12 13 14 15 16 17 18 19 20 21
case class SampleStats(genotypeStats: mutable.Map[String, mutable.Map[String, mutable.Map[Any, Int]]] = mutable.Map(),
                       sampleToSample: mutable.Map[String, SampleToSampleStats] = mutable.Map()) {
  /** Add an other class */
  def +=(other: SampleStats): Unit = {
    for ((key, value) <- other.sampleToSample) {
      if (this.sampleToSample.contains(key)) this.sampleToSample(key) += value
      else this.sampleToSample(key) = value
    }
    for ((chr, chrMap) <- other.genotypeStats; (field, fieldMap) <- chrMap) {
      if (!this.genotypeStats.contains(chr)) genotypeStats += (chr -> mutable.Map[String, mutable.Map[Any, Int]]())
      val thisField = this.genotypeStats(chr).get(field)
Peter van 't Hof's avatar
Peter van 't Hof committed
22
      if (thisField.isDefined) Stats.mergeStatsMap(thisField.get, fieldMap)
Peter van 't Hof's avatar
Peter van 't Hof committed
23 24 25 26
      else this.genotypeStats(chr) += field -> fieldMap
    }
  }
}