Commit 575110d4 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Combining all into 1 file

parent 5ce12b5f
......@@ -98,12 +98,21 @@ object BamStats extends ToolCommand {
*/
def init(outputDir: File, bamFile: File, referenceDict: SAMSequenceDictionary, binSize: Int, threadBinSize: Int): Unit = {
val contigsFutures = BedRecordList.fromDict(referenceDict).allRecords.map { contig =>
processContig(contig, bamFile, binSize, threadBinSize, outputDir)
}
contig.chr -> processContig(contig, bamFile, binSize, threadBinSize, outputDir)
}.toList
val stats = waitOnFutures(processUnmappedReads(bamFile) :: contigsFutures.map(_._2))
val stats = waitOnFutures(processUnmappedReads(bamFile) :: contigsFutures.toList)
val statsWriter = new PrintWriter(new File(outputDir, "stats.json"))
val statsMap = Map(
"total" -> stats.toSummaryMap,
"contigs" -> contigsFutures.map(x => x._1 -> x._2.value.get.get.toSummaryMap).toMap
)
statsWriter.println(ConfigUtils.mapToJson(statsMap).spaces2)
statsWriter.close()
//stats.writeStatsToFiles(outputDir)
stats.writeStatsToFiles(outputDir)
// FIXME: getting aggregated stats
val clippingHistogram = tsvToMap(new File(outputDir, "clipping.tsv"))
val mappingQualityHistogram = tsvToMap(new File(outputDir, "mapping_quality.tsv"))
......@@ -157,11 +166,7 @@ object BamStats extends ToolCommand {
.grouped((region.length.toDouble / binSize).ceil.toInt / (region.length.toDouble / threadBinSize).ceil.toInt)
.map(scatters => processThread(scatters, bamFile))
.toList
val stats = waitOnFutures(scattersFutures, Some(region.chr))
val contigDir = new File(outputDir, "contigs" + File.separator + region.chr)
contigDir.mkdirs()
stats.writeStatsToFiles(contigDir)
stats
waitOnFutures(scattersFutures, Some(region.chr))
}
/**
......
......@@ -15,6 +15,7 @@
package nl.lumc.sasc.biopet.tools.bamstats
import java.io.{ File, PrintWriter }
import nl.lumc.sasc.biopet.utils.sortAnyAny
import scala.collection.mutable
......@@ -49,6 +50,11 @@ class Counts[T](_counts: Map[T, Long] = Map[T, Long]())(implicit ord: Ordering[T
writer.close()
}
def toSummaryMap = {
val values = counts.keySet.toList.sortWith(sortAnyAny)
Map("values" -> values, "counts" -> values.map(counts(_)))
}
override def equals(other: Any): Boolean = {
other match {
case c: Counts[T] => this.counts == c.counts
......
......@@ -58,4 +58,17 @@ case class Stats(flagstat: FlagstatCollector = new FlagstatCollector(),
this._5_ClippingHistogram.writeToTsv(new File(outputDir, "5_prime_clipping.tsv"))
this._3_ClippingHistogram.writeToTsv(new File(outputDir, "3_prime_clipping.tsv"))
}
def toSummaryMap = {
Map(
"flagstats" -> flagstat.toSummaryMap,
"mapping_quality" -> mappingQualityHistogram.toSummaryMap,
"insert_size" -> insertSizeHistogram.toSummaryMap,
"clipping" -> clippingHistogram.toSummaryMap,
"left_clipping" -> leftClippingHistogram.toSummaryMap,
"right_clipping" -> rightClippingHistogram.toSummaryMap,
"5_prime_clipping" -> _5_ClippingHistogram.toSummaryMap,
"3_prime_clipping" -> _3_ClippingHistogram.toSummaryMap
)
}
}
......@@ -201,6 +201,15 @@ class FlagstatCollector {
buffer.toString()
}
def toSummaryMap = {
val sortedKeys = names.keys.toArray.sorted
Map(
"keys" -> sortedKeys.map(names(_)),
"total" -> totalCounts,
"cross_counts" -> crossCounts
)
}
def +=(other: FlagstatCollector): FlagstatCollector = {
require(this.names == other.names)
//require(this.functions == other.functions)
......
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