Commit 186b5775 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Move combine method inside class

parent 92f6a098
......@@ -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")
......
......@@ -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}")
......
......@@ -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
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