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

Added simple test on main

parent 99b31701
......@@ -87,12 +87,10 @@ 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 =>
Future { processContig(contig, bamFile, binSize, threadBinSize, outputDir) }
processContig(contig, bamFile, binSize, threadBinSize, outputDir)
}
val unmappedFuture = Future { processUnmappedReads(bamFile) }
val stats = waitOnFutures(unmappedFuture :: contigsFutures.toList)
val stats = waitOnFutures(processUnmappedReads(bamFile) :: contigsFutures.toList)
stats.writeStatsToFiles(outputDir)
}
......@@ -106,11 +104,11 @@ object BamStats extends ToolCommand {
* @param threadBinSize Thread binsize
* @return Output stats
*/
def processContig(region: BedRecord, bamFile: File, binSize: Int, threadBinSize: Int, outputDir: File): Stats = {
def processContig(region: BedRecord, bamFile: File, binSize: Int, threadBinSize: Int, outputDir: File): Future[Stats] = Future {
val scattersFutures = region
.scatter(binSize)
.grouped((region.length.toDouble / binSize).ceil.toInt / (region.length.toDouble / threadBinSize).ceil.toInt)
.map(scatters => Future { processThread(scatters, bamFile) })
.map(scatters => processThread(scatters, bamFile))
.toList
val stats = waitOnFutures(scattersFutures, Some(region.chr))
val contigDir = new File(outputDir, "contigs" + File.separator + region.chr)
......@@ -153,7 +151,7 @@ object BamStats extends ToolCommand {
* @param bamFile Input bamfile
* @return Output stats
*/
def processThread(scatters: List[BedRecord], bamFile: File): Stats = {
def processThread(scatters: List[BedRecord], bamFile: File): Future[Stats] = Future {
val totalStats = Stats()
val sortedScatters = scatters.sortBy(_.start)
val samReader = SamReaderFactory.makeDefault().open(bamFile)
......@@ -203,7 +201,7 @@ object BamStats extends ToolCommand {
* @param bamFile Input bamfile
* @return Output stats
*/
def processUnmappedReads(bamFile: File): Stats = {
def processUnmappedReads(bamFile: File): Future[Stats] = Future {
val stats = Stats()
val samReader = SamReaderFactory.makeDefault().open(bamFile)
for (samRecord <- samReader.queryUnmapped()) {
......
package nl.lumc.sasc.biopet.tools.bamstats
import java.io.File
import java.nio.file.Paths
import com.google.common.io.Files
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
/**
* Created by pjvan_thof on 21-7-16.
*/
class BamStatsTest extends TestNGSuite with Matchers {
@Test
def testMain: Unit = {
val outputDir = Files.createTempDir()
outputDir.deleteOnExit()
BamStats.main(Array("-b", BamStatsTest.pairedBam01.getAbsolutePath, "-o", outputDir.getAbsolutePath))
new File(outputDir, "flagstats") should exist
new File(outputDir, "flagstats.summary.json") should exist
new File(outputDir, "mapping_quality.tsv") should exist
new File(outputDir, "insert_size.tsv") should exist
new File(outputDir, "clipping.tsv") should exist
new File(outputDir, "left_clipping.tsv") should exist
new File(outputDir, "right_clipping.tsv") should exist
new File(outputDir, "5_prime_clipping.tsv") should exist
new File(outputDir, "3_prime_clipping.tsv") should exist
}
}
object BamStatsTest {
private def resourcePath(p: String): String = {
Paths.get(getClass.getResource(p).toURI).toString
}
val pairedBam01 = new File(resourcePath("/paired01.bam"))
}
\ No newline at end of file
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