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

Adding toSamInterval method

parent 7d95212a
No related branches found
No related tags found
No related merge requests found
......@@ -85,7 +85,7 @@ object WipeReads extends ToolCommand {
logger.info("Parsing interval file ...")
/** Function to create iterator from BED file */
def makeIntervalFromBed(inFile: File) = BedRecordList.fromFile(inFile).sorted.samIntervals.toIterator
def makeIntervalFromBed(inFile: File) = BedRecordList.fromFile(inFile).sorted.toSamIntervals.toIterator
/**
* Parses a refFlat file to yield Interval objects
......
package nl.lumc.sasc.biopet.utils.intervals
import htsjdk.samtools.util.Interval
/**
* Created by pjvanthof on 20/08/15.
*/
......@@ -98,6 +100,11 @@ case class BedRecord(chr: String,
}
this
}
def toSamInterval = (name, strand) match {
case (Some(name), Some(strand)) => new Interval(chr, start + 1, end, !strand, name)
case _ => new Interval(chr, start + 1, end)
}
}
object BedRecord {
......
......@@ -15,12 +15,7 @@ import nl.lumc.sasc.biopet.core.Logging
class BedRecordList(val chrRecords: Map[String, List[BedRecord]], header: List[String] = Nil) {
def allRecords = for (chr <- chrRecords; record <- chr._2) yield record
def samIntervals = allRecords.map({ x =>
(x.name, x.strand) match {
case (Some(name), Some(strand)) => new Interval(x.chr, x.start + 1, x.end, !strand, name)
case _ => new Interval(x.chr, x.start + 1, x.end)
}
})
def toSamIntervals = allRecords.map(_.toSamInterval)
lazy val sorted = {
val sorted = new BedRecordList(chrRecords.map(x => x._1 -> x._2.sortWith((a, b) => a.start < b.start)))
......
package nl.lumc.sasc.biopet.utils.intervals
import htsjdk.samtools.util.Interval
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
......@@ -43,6 +44,11 @@ class BedRecordTest extends TestNGSuite with Matchers {
BedRecord("chrQ", 3, 4).length shouldBe 1
}
@Test def testToSamInterval: Unit = {
BedRecord("chrQ", 0, 4).toSamInterval shouldBe new Interval("chrQ", 1, 4)
BedRecord("chrQ", 0, 4, Some("name"), Some(0.0), Some(true)).toSamInterval shouldBe new Interval("chrQ", 1, 4, false, "name")
}
@Test def testExons: Unit = {
BedRecord.fromLine("chrQ\t0\t100\tname\t3\t+\t1\t3\t255,0,0").exons shouldBe None
......
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