From 1f4aead0af92e5d66d9c8ea3bae9ac37d9c03e88 Mon Sep 17 00:00:00 2001 From: Peter van 't Hof <p.j.van_t_hof@lumc.nl> Date: Sat, 22 Aug 2015 13:50:07 +0200 Subject: [PATCH] Adding exons and introns --- .../biopet/utils/intervals/BedRecord.scala | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala index 320a98a1e..55f5907cc 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala @@ -16,6 +16,36 @@ case class BedRecord(chr: String, blockSizes: Array[Int] = Array(), blockStarts: Array[Int] = Array()) { + protected[intervals] var _originals: List[BedRecord] = Nil + + def originals = _originals + + lazy val exons = if (blockCount.isDefined && blockSizes.length > 0 && blockStarts.length > 0) { + Some(BedRecordList.fromList(for (i <- 0 to blockCount.get) yield { + val exonNumber = strand match { + case Some(false) => blockCount.get - i + case _ => i + 1 + } + val record = BedRecord(chr, start + blockStarts(i), start + blockStarts(i) + blockSizes(i), + name.map(_ + s"_exon-$exonNumber")) + record._originals :+= this + record + })) + } else None + + lazy val introns = if (blockCount.isDefined && blockSizes.length > 0 && blockStarts.length > 0) { + Some(BedRecordList.fromList(for (i <- 0 to (blockCount.get - 1)) yield { + val intronNumber = strand match { + case Some(false) => blockCount.get - i + case _ => i + 1 + } + val record = BedRecord(chr, start + start + blockStarts(i) + blockSizes(i) + 1, start + blockStarts(i + 1) - 1, + name.map(_ + s"_intron-$intronNumber")) + record._originals :+= this + record + })) + } else None + //TODO: Complete bed line output override def toString = { s"$chr\t$start\t$end" -- GitLab