Commit e46fb718 authored by Peter van 't Hof's avatar Peter van 't Hof

Adding plots to histograms

parent 181f3be8
...@@ -104,21 +104,14 @@ object BamStats extends ToolCommand { ...@@ -104,21 +104,14 @@ object BamStats extends ToolCommand {
val stats = waitOnFutures(processUnmappedReads(bamFile) :: contigsFutures.map(_._2)) val stats = waitOnFutures(processUnmappedReads(bamFile) :: contigsFutures.map(_._2))
stats.flagstat.writeAsTsv(new File(outputDir, "flagstats.tsv")) stats.flagstat.writeAsTsv(new File(outputDir, "flagstats.tsv"))
stats.insertSizeHistogram.writeHistogramToTsv(new File(outputDir, "insertsize.histogram.tsv")) stats.insertSizeHistogram.writeFilesAndPlot(outputDir, "insertsize", "Insertsize", "Reads", "Insertsize distribution")
stats.insertSizeHistogram.writeAggregateToTsv(new File(outputDir, "insertsize.stats.tsv")) stats.mappingQualityHistogram.writeFilesAndPlot(outputDir, "mappingQuality", "Mapping Quality", "Reads", "Mapping Quality distribution")
stats.mappingQualityHistogram.writeHistogramToTsv(new File(outputDir, "mappingQuality.histogram.tsv")) stats.clippingHistogram.writeFilesAndPlot(outputDir, "clipping", "CLipped bases", "Reads", "Clipping distribution")
stats.mappingQualityHistogram.writeAggregateToTsv(new File(outputDir, "mappingQualityHistogram.stats.tsv"))
stats.clippingHistogram.writeHistogramToTsv(new File(outputDir, "clipping.histogram.tsv")) stats.leftClippingHistogram.writeFilesAndPlot(outputDir, "left_clipping", "CLipped bases", "Reads", "Left Clipping distribution")
stats.clippingHistogram.writeAggregateToTsv(new File(outputDir, "clipping.stats.tsv")) stats.rightClippingHistogram.writeFilesAndPlot(outputDir, "right_clipping", "CLipped bases", "Reads", "Right Clipping distribution")
stats._3_ClippingHistogram.writeFilesAndPlot(outputDir, "3prime_clipping", "CLipped bases", "Reads", "3 Prime Clipping distribution")
stats.leftClippingHistogram.writeHistogramToTsv(new File(outputDir, "left_clipping.histogram.tsv")) stats._5_ClippingHistogram.writeFilesAndPlot(outputDir, "5prime_clipping", "CLipped bases", "Reads", "5 Prime Clipping distribution")
stats.leftClippingHistogram.writeAggregateToTsv(new File(outputDir, "left_clipping.stats.tsv"))
stats.rightClippingHistogram.writeHistogramToTsv(new File(outputDir, "right_clipping.histogram.tsv"))
stats.rightClippingHistogram.writeAggregateToTsv(new File(outputDir, "right_clipping.stats.tsv"))
stats._3_ClippingHistogram.writeHistogramToTsv(new File(outputDir, "3prime_clipping.histogram.tsv"))
stats._3_ClippingHistogram.writeAggregateToTsv(new File(outputDir, "3prime_clipping.stats.tsv"))
stats._5_ClippingHistogram.writeHistogramToTsv(new File(outputDir, "5prime_clipping.histogram.tsv"))
stats._5_ClippingHistogram.writeAggregateToTsv(new File(outputDir, "5prime_clipping.stats.tsv"))
val statsWriter = new PrintWriter(new File(outputDir, "bamstats.json")) val statsWriter = new PrintWriter(new File(outputDir, "bamstats.json"))
val totalStats = stats.toSummaryMap val totalStats = stats.toSummaryMap
......
...@@ -14,7 +14,9 @@ ...@@ -14,7 +14,9 @@
*/ */
package nl.lumc.sasc.biopet.tools.bamstats package nl.lumc.sasc.biopet.tools.bamstats
import java.io.{ File, PrintWriter } import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.rscript.LinePlot
import nl.lumc.sasc.biopet.utils.sortAnyAny import nl.lumc.sasc.biopet.utils.sortAnyAny
import scala.collection.mutable import scala.collection.mutable
...@@ -89,4 +91,16 @@ class Histogram[T](_counts: Map[T, Long] = Map[T, Long]())(implicit ord: Numeric ...@@ -89,4 +91,16 @@ class Histogram[T](_counts: Map[T, Long] = Map[T, Long]())(implicit ord: Numeric
writer.close() writer.close()
} }
def writeFilesAndPlot(outputDir: File, prefix: String, xlabel: String, ylabel: String, title: String): Unit = {
writeHistogramToTsv(new File(outputDir, prefix + ".histogram.tsv"))
writeAggregateToTsv(new File(outputDir, prefix + ".stats.tsv"))
val plot = new LinePlot(null)
plot.input = new File(outputDir, prefix + ".histogram.tsv")
plot.output = new File(outputDir, prefix + ".histogram.png")
plot.xlabel = Some(xlabel)
plot.ylabel = Some(ylabel)
plot.title = Some(title)
plot.runLocal()
}
} }
...@@ -34,6 +34,15 @@ class BamStatsTest extends TestNGSuite with Matchers { ...@@ -34,6 +34,15 @@ class BamStatsTest extends TestNGSuite with Matchers {
new File(outputDir, "bamstats.json") should exist new File(outputDir, "bamstats.json") should exist
new File(outputDir, "bamstats.summary.json") should exist new File(outputDir, "bamstats.summary.json") should exist
new File(outputDir, "flagstats.tsv") should exist
new File(outputDir, "insertsize.stats.tsv") should exist
new File(outputDir, "insertsize.histogram.tsv") should exist
new File(outputDir, "mappingQuality.stats.tsv") should exist
new File(outputDir, "mappingQuality.histogram.tsv") should exist
new File(outputDir, "clipping.stats.tsv") should exist
new File(outputDir, "clipping.histogram.tsv") should exist
new File(outputDir, "flagstats") shouldNot exist new File(outputDir, "flagstats") shouldNot exist
new File(outputDir, "flagstats.summary.json") shouldNot exist new File(outputDir, "flagstats.summary.json") shouldNot exist
new File(outputDir, "mapping_quality.tsv") shouldNot exist new File(outputDir, "mapping_quality.tsv") shouldNot exist
......
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