Skip to content
Snippets Groups Projects
Commit 378dc2a3 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added better type casting

parent e34aac8c
No related branches found
No related tags found
No related merge requests found
package nl.lumc.sasc.biopet.tools.bamstats
import java.io.File
import java.util.concurrent.TimeoutException
import htsjdk.samtools.reference.FastaSequenceFile
import htsjdk.samtools.{ SAMSequenceDictionary, SamReaderFactory }
import htsjdk.samtools.{SAMSequenceDictionary, SamReaderFactory}
import nl.lumc.sasc.biopet.utils.BamUtils.SamDictCheck
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.intervals.{ BedRecord, BedRecordList }
import scala.collection.JavaConversions._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.concurrent.{ Await, Future }
/**
* This tool will collect stats from a bamfile
......@@ -135,7 +137,11 @@ object BamStats extends ToolCommand {
done.foreach(stats += _.value.get.get)
running = running.filterNot(done.contains(_))
if (running.nonEmpty && done.nonEmpty) msg.foreach(m => logger.info(s"Jobs for '$m', ${running.size}/${futures.size} jobs"))
if (running.nonEmpty) Thread.sleep(1000)
if (running.nonEmpty) try {
Await.ready(running.head, 1 second)
} catch {
case e: TimeoutException =>
}
}
msg.foreach(m => logger.info(s"All jobs for '$m' are done"))
stats
......
......@@ -7,25 +7,29 @@ import scala.collection.mutable
/**
* Created by pjvanthof on 05/07/16.
*/
case class Histogram() {
protected[Histogram] val histrogram: mutable.Map[Int, Long] = mutable.Map()
class Counts[T](implicit ord: Ordering[T]) {
protected[Counts] val counts: mutable.Map[T, Long] = mutable.Map()
/** This will add an other histogram to `this` */
def +=(other: Histogram): Histogram = {
other.histrogram.foreach(x => this.histrogram += x._1 -> (this.histrogram.getOrElse(x._1, 0L) + x._2))
def +=(other: Counts[T]): Counts[T] = {
other.counts.foreach(x => this.counts += x._1 -> (this.counts.getOrElse(x._1, 0L) + x._2))
this
}
/** With this a value can be added to the histogram */
def add(value: Int): Unit = {
histrogram += value -> (histrogram.getOrElse(value, 0L) + 1)
def add(value: T): Unit = {
counts += value -> (counts.getOrElse(value, 0L) + 1)
}
/** Write histogram to a tsv/count file */
def writeToTsv(file: File): Unit = {
val writer = new PrintWriter(file)
writer.println("value\tcount")
histrogram.keys.toList.sorted.foreach(x => writer.println(s"$x\t${histrogram(x)}"))
counts.keys.toList.sorted.foreach(x => writer.println(s"$x\t${counts(x)}"))
writer.close()
}
}
class Histogram[T](implicit ord: Numeric[T]) extends Counts[T] {
}
......@@ -8,13 +8,13 @@ case class Stats() {
var totalReads = 0L
var unmapped = 0L
var secondary = 0L
val mappingQualityHistogram = Histogram()
val insertSizeHistogram = Histogram()
val clippingHistogram = Histogram()
val leftClippingHistogram = Histogram()
val rightClippingHistogram = Histogram()
val _5_ClippingHistogram = Histogram()
val _3_ClippingHistogram = Histogram()
val mappingQualityHistogram = new Histogram[Int]
val insertSizeHistogram = new Histogram[Int]
val clippingHistogram = new Histogram[Int]
val leftClippingHistogram = new Histogram[Int]
val rightClippingHistogram = new Histogram[Int]
val _5_ClippingHistogram = new Histogram[Int]
val _3_ClippingHistogram = new Histogram[Int]
/** This will add an other [[Stats]] inside `this` */
def +=(other: Stats): Stats = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment