Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Jun 5, 2023
1 parent efc65a7 commit 07c651c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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)

}
Expand All @@ -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",
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 07c651c

Please sign in to comment.