From 186b5775c7ad9406f1b1b839593e3ff155481c31 Mon Sep 17 00:00:00 2001 From: Peter van 't Hof <p.j.van_t_hof@lumc.nl> Date: Mon, 24 Aug 2015 11:35:03 +0200 Subject: [PATCH] Move combine method inside class --- .../sasc/biopet/tools/RegionAfCount.scala | 2 +- .../nl/lumc/sasc/biopet/tools/SquishBed.scala | 4 +-- .../utils/intervals/BedRecordList.scala | 36 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala index 8ba1caabd..81e9283e0 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala @@ -68,7 +68,7 @@ object RegionAfCount extends ToolCommand { logger.info(s"Combine ${bedRecords.allRecords.size} bed records") - val combinedBedRecords = BedRecordList.combineOverlap(bedRecords) + val combinedBedRecords = bedRecords.combineOverlap logger.info(s"${combinedBedRecords.allRecords.size} left") diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala index 7a424f510..16e518429 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala @@ -39,14 +39,14 @@ object SquishBed extends ToolCommand { val records = BedRecordList.fromFile(cmdArgs.input) val length = records.length - val refLength = BedRecordList.combineOverlap(records).length + val refLength = records.combineOverlap.length logger.info(s"Total bases: $length") logger.info(s"Total bases on reference: $refLength") logger.info("Start squishing") val squishBed = records.squishBed(cmdArgs.strandSensitive).sort logger.info("Done squishing") val squishLength = squishBed.length - val squishRefLength = BedRecordList.combineOverlap(squishBed).length + val squishRefLength = squishBed.combineOverlap.length logger.info(s"Total bases left: $squishLength") logger.info(s"Total bases left on reference: $squishRefLength") logger.info(s"Total bases removed from ref: ${refLength - squishRefLength}") diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala index 029356e5f..351ab6b08 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordList.scala @@ -50,6 +50,24 @@ class BedRecordList(val chrRecords: Map[String, List[BedRecord]], header: List[S }).flatten } + def combineOverlap: BedRecordList = { + new BedRecordList(for ((chr, records) <- sort.chrRecords) yield chr -> { + def combineOverlap(records: List[BedRecord], + newRecords: ListBuffer[BedRecord] = ListBuffer()): List[BedRecord] = { + if (records.nonEmpty) { + val chr = records.head.chr + val start = records.head.start + val overlapRecords = records.takeWhile(_.start <= records.head.end) + val end = overlapRecords.map(_.end).max + + newRecords += BedRecord(chr, start, end, _originals = overlapRecords) + combineOverlap(records.drop(overlapRecords.length), newRecords) + } else newRecords.toList + } + combineOverlap(records) + }) + } + def writeToFile(file: File): Unit = { val writer = new PrintWriter(file) allRecords.foreach(writer.println) @@ -91,22 +109,4 @@ object BedRecordList { throw e } } - - def combineOverlap(list: BedRecordList): BedRecordList = { - new BedRecordList(for ((chr, records) <- list.sort.chrRecords) yield chr -> { - def combineOverlap(records: List[BedRecord], - newRecords: ListBuffer[BedRecord] = ListBuffer()): List[BedRecord] = { - if (records.nonEmpty) { - val chr = records.head.chr - val start = records.head.start - val overlapRecords = records.takeWhile(_.start <= records.head.end) - val end = overlapRecords.map(_.end).max - - newRecords += BedRecord(chr, start, end, _originals = overlapRecords) - combineOverlap(records.drop(overlapRecords.length), newRecords) - } else newRecords.toList - } - combineOverlap(records) - }) - } } \ No newline at end of file -- GitLab