From 22064e83561421f12a7178c1e7f9dd57969033e3 Mon Sep 17 00:00:00 2001
From: Peter van 't Hof <p.j.van_t_hof@lumc.nl>
Date: Sat, 22 Aug 2015 20:37:20 +0200
Subject: [PATCH] Add nested option to originals

---
 .../nl/lumc/sasc/biopet/tools/RegionAfCount.scala  | 10 +++-------
 .../sasc/biopet/utils/intervals/BedRecord.scala    | 14 +++++++++-----
 2 files changed, 12 insertions(+), 12 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 ad29bd5f7..8ba1caabd 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
@@ -40,8 +40,7 @@ object RegionAfCount extends ToolCommand {
   case class Args(bedFile: File = null,
                   outputFile: File = null,
                   scatterpPlot: Option[File] = None,
-                  vcfFiles: List[File] = Nil,
-                  exonsOnly: Boolean = false) extends AbstractArgs
+                  vcfFiles: List[File] = Nil) extends AbstractArgs
 
   class OptParser extends AbstractOptParser {
     opt[File]('b', "bedFile") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
@@ -56,9 +55,6 @@ object RegionAfCount extends ToolCommand {
     opt[File]('V', "vcfFile") unbounded () minOccurs 1 action { (x, c) =>
       c.copy(vcfFiles = c.vcfFiles ::: x :: Nil)
     }
-    opt[Unit]("exonsOnly") unbounded () action { (x, c) =>
-      c.copy(exonsOnly = true)
-    }
   }
 
   def main(args: Array[String]): Unit = {
@@ -89,8 +85,8 @@ object RegionAfCount extends ToolCommand {
             case a: util.ArrayList[_] => a.map(_.toString.toDouble).toArray
             case s                    => Array(s.toString.toDouble)
           }).sum
-          region.originals
-            .map(_.name.getOrElse("error"))
+          region.originals()
+            .map(x => x.name.getOrElse(s"${x.chr}:${x.start}-${x.end}"))
             .distinct
             .foreach(name => afCounts += name -> (afCounts.getOrElse(name, 0.0) + sum))
         }
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 58901c955..d396464ff 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
@@ -18,7 +18,11 @@ case class BedRecord(chr: String,
 
   protected[intervals] var _originals: List[BedRecord] = Nil
 
-  def originals = _originals
+  def originals(nested: Boolean = false): List[BedRecord] = {
+    if (_originals.isEmpty) List(this)
+    else if (nested) _originals.flatMap(_.originals(true))
+    else _originals
+  }
 
   lazy val exons = if (blockCount.isDefined && blockSizes.length > 0 && blockStarts.length > 0) {
     Some(BedRecordList.fromList(for (i <- 0 to blockCount.get) yield {
@@ -62,14 +66,14 @@ object BedRecord {
       values(2).toInt,
       values.lift(3),
       values.lift(4).map(_.toInt),
-      values.lift(5).map(_ match {
+      values.lift(5).map {
         case "-" => false
         case "+" => true
-        case _   => throw new IllegalStateException("Strand (column 6) must be '+' or '-'")
-      }),
+        case _ => throw new IllegalStateException("Strand (column 6) must be '+' or '-'")
+      },
       values.lift(6).map(_.toInt),
       values.lift(7) map (_.toInt),
-      values.lift(8).map(_.split(",", 3).map(_.toInt)).map(x => (x.lift(0).getOrElse(0), x.lift(1).getOrElse(0), x.lift(2).getOrElse(0))),
+      values.lift(8).map(_.split(",", 3).map(_.toInt)).map(x => (x.headOption.getOrElse(0), x.lift(1).getOrElse(0), x.lift(2).getOrElse(0))),
       values.lift(9).map(_.toInt),
       values.lift(10).map(_.split(",").map(_.toInt)).getOrElse(Array()),
       values.lift(11).map(_.split(",").map(_.toInt)).getOrElse(Array())
-- 
GitLab