From 07c651cef649b884f4ec6fcaa3b2f27a50e7ddf8 Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Mon, 5 Jun 2023 16:04:49 -0700 Subject: [PATCH] add some tests --- .../sv/tools/AggregateSvPileup.scala | 8 ++++---- .../sv/tools/AggregateSvPileupTest.scala | 15 ++++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileup.scala b/src/main/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileup.scala index 8811887..d2aab31 100644 --- a/src/main/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileup.scala +++ b/src/main/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileup.scala @@ -432,9 +432,9 @@ case class AggregatedBreakpointPileup(id: String, */ def addTargetOverlap(targets: Option[OverlapDetector[BEDFeature]]): AggregatedBreakpointPileup = { - def annotations(contig: String, minPos: Int , maxPos: Int): (Boolean, Option[String]) = { + def annotations(contig: String, minPos: Int , maxPos: Int, defaultTargets: Option[String] = None): (Boolean, Option[String]) = { targets match { - case None => (false, None) + case None => (false, defaultTargets) case Some(detector) => val span = new Interval(contig, minPos, maxPos) if (detector.overlapsAny(span)) { @@ -446,8 +446,8 @@ case class AggregatedBreakpointPileup(id: String, } } - val (leftOverlaps, leftTargets) = annotations(left_contig, left_min_pos, left_max_pos) - val (rightOverlaps, rightTargets) = annotations(right_contig, right_min_pos, right_max_pos) + val (leftOverlaps, leftTargets) = annotations(left_contig, left_min_pos, left_max_pos, this.left_targets) + val (rightOverlaps, rightTargets) = annotations(right_contig, right_min_pos, right_max_pos, this.right_targets) this.copy( left_overlaps_target = leftOverlaps, right_overlaps_target = rightOverlaps, diff --git a/src/test/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileupTest.scala b/src/test/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileupTest.scala index 33f1c31..28c4fa1 100644 --- a/src/test/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileupTest.scala +++ b/src/test/scala/com/fulcrumgenomics/sv/tools/AggregateSvPileupTest.scala @@ -117,6 +117,7 @@ class AggregateSvPileupTest extends UnitSpec { split_reads = 1, read_pairs = 1, total = 2, + left_targets = Some("1,2,5") ) private val pileup_id8_1_500_plus_3_400_plus = BreakpointPileup( @@ -210,7 +211,7 @@ class AggregateSvPileupTest extends UnitSpec { private val bed = makeTempFile("targets", ".bed") private val bedWriter = new BufferedWriter(new FileWriter(bed.toFile)) - bedWriter.write("#header\nchr1\t400\t410\nchr3\t401\t402\n") + bedWriter.write("#header\nchr1\t400\t410\ttarget-1\nchr3\t401\t402\ttarget-2\n") bedWriter.flush() bedWriter.close() @@ -288,6 +289,7 @@ class AggregateSvPileupTest extends UnitSpec { total = 12, left_pileups = PositionList(100, 200, 300, 400, 500, 600), right_pileups = PositionList(100, 200, 200, 300, 400, 500), + left_targets = Some("1,2,5") ) // pileup_id222_1_100_plus_1_200_plus does not combine due to different chromosome @@ -380,6 +382,8 @@ class AggregateSvPileupTest extends UnitSpec { right_frequency = Some(8d/8), left_overlaps_target = true, right_overlaps_target = true, + left_targets = Some("target-1"), + right_targets = Some("target-2"), ) val expAgg2 = AggregatedBreakpointPileup( @@ -405,11 +409,6 @@ class AggregateSvPileupTest extends UnitSpec { ) val aggregatedPileups = runEndToEnd(pileups, bam = Some(bam), targets = Some(bed)) - - aggregatedPileups.foreach { p => - println(s"Pileup ${p.id} ${p.left_targets.isEmpty} ${p.left_targets.contains("")}") - } - aggregatedPileups should contain theSameElementsAs IndexedSeq(expAgg1, expAgg2) } @@ -422,7 +421,6 @@ class AggregateSvPileupTest extends UnitSpec { pileup_id10_1_525_plus_3_425_plus, ) - val expAgg = AggregatedBreakpointPileup( id = "10_7_8_9", category = "Inter-contig rearrangement", @@ -441,6 +439,7 @@ class AggregateSvPileupTest extends UnitSpec { right_pileups = PositionList(300, 400, 425, 500), left_frequency = Some(8d/16), right_frequency = Some(8d/8), + left_targets = Some("1,2,5") ) val aggregatedPileups = runEndToEnd(pileups, bam = Some(bam)) @@ -476,6 +475,8 @@ class AggregateSvPileupTest extends UnitSpec { right_frequency = None, left_overlaps_target = true, right_overlaps_target = true, + left_targets = Some("target-1"), + right_targets = Some("target-2"), ) val aggregatedPileups = runEndToEnd(pileups, targets = Some(bed))