Skip to content

Commit 6eb1762

Browse files
committed
test
non-winnowing
1 parent f6052af commit 6eb1762

File tree

1 file changed

+60
-45
lines changed

1 file changed

+60
-45
lines changed

src/test/scala/com/fulcrumgenomics/vcf/DownsampleVcfTest.scala

+60-45
Original file line numberDiff line numberDiff line change
@@ -369,66 +369,81 @@ class DownsampleVcfTest extends UnitSpec {
369369
Metric.write(metadata, Seq(Sample(SAMPLE_NAME = sample, BASE_COUNT = 100)))
370370

371371
"DownsampleVcf" should "write a new vcf with downsampled genotypes when provided a vcf" in {
372-
List("proportion", "number", "metadata").foreach(
373-
kind => {
372+
List("proportion", "number", "metadata").foreach(kind => {
373+
List(true, false).foreach(winnow => {
374374
// Construct the input VCF
375375
val outVcf = makeTempFile("out", ".vcf.gz")
376+
val windowSize = if (winnow) { 150 } else { 0 }
376377
kind match {
377378
case "proportion" =>
378379
new DownsampleVcf(input=inVcf,
379380
output=outVcf,
380381
proportion=Some(0.01),
381-
windowSize=150).execute()
382+
windowSize=windowSize).execute()
382383
case "number" =>
383384
new DownsampleVcf(input=inVcf,
384385
output=outVcf,
385386
originalBases=Some(100),
386387
downsampleToBases=Some(1),
387-
windowSize=150).execute()
388+
windowSize=windowSize).execute()
388389
case "metadata" =>
389390
new DownsampleVcf(input=inVcf,
390391
output=outVcf,
391392
metadata=Some(metadata),
392393
downsampleToBases=Some(1),
393-
windowSize=150).execute()
394+
windowSize=windowSize).execute()
394395
}
395396

396397
val vs = readVcfRecs(outVcf)
397-
vs should have length 5
398+
val expectedLength = if (winnow) { 5 } else { 6 }
399+
vs should have length expectedLength
398400

399401
val ad0 = vs(0).genotypes("test1")[IndexedSeq[Int]]("AD")
400-
ad0(0) < 110 shouldBe true;
402+
ad0(0) < 110 shouldBe true
401403
ad0(1) < 110 shouldBe true
402404
val pl0 = vs(0).genotypes("test1")[IndexedSeq[Int]]("PL")
403405
pl0(1) shouldBe 0
406+
407+
val offset = if (winnow) {
408+
0
409+
} else {
410+
val ad1 = vs(1).genotypes("test1")[IndexedSeq[Int]]("AD")
411+
ad1(0) shouldBe 8
412+
ad1(1) < 110 shouldBe true
413+
val pl1 = vs(1).genotypes("test1")[IndexedSeq[Int]]("PL")
414+
pl1(2) shouldBe 160
415+
1
416+
}
404417

405-
val ad1 = vs(1).genotypes("test1")[IndexedSeq[Int]]("AD")
406-
ad1(0) shouldBe 0;
407-
ad1(1) < 110 shouldBe true
408-
val pl1 = vs(1).genotypes("test1")[IndexedSeq[Int]]("PL")
409-
pl1(2) shouldBe 0
410-
411-
val ad2 = vs(2).genotypes("test1")[IndexedSeq[Int]]("AD")
412-
ad2(0) < 30 shouldBe true;
418+
val ad2 = vs(1 + offset).genotypes("test1")[IndexedSeq[Int]]("AD")
419+
ad2(0) shouldBe 0
413420
ad2(1) < 110 shouldBe true
414-
val pl2 = vs(2).genotypes("test1")[IndexedSeq[Int]]("PL")
421+
val pl2 = vs(1 + offset).genotypes("test1")[IndexedSeq[Int]]("PL")
415422
pl2(2) shouldBe 0
416423

417-
val ad3 = vs(3).genotypes("test1")[IndexedSeq[Int]]("AD")
418-
ad3(0) < 110 shouldBe true;
419-
ad3(1) shouldBe 0;
420-
val pl3 = vs(3).genotypes("test1")[IndexedSeq[Int]]("PL")
421-
pl3(0) shouldBe 0
424+
val ad3 = vs(2 + offset).genotypes("test1")[IndexedSeq[Int]]("AD")
425+
ad3(0) < 30 shouldBe true
426+
ad3(1) < 110 shouldBe true
427+
val pl3 = vs(2 + offset).genotypes("test1")[IndexedSeq[Int]]("PL")
428+
pl3(2) shouldBe 0
422429

423-
val ad4 = vs(4).genotypes("test1")[IndexedSeq[Int]]("AD")
424-
ad4(0) < 100 shouldBe true;
425-
ad4(1) < 100 shouldBe true;
426-
ad4(0) > 1 shouldBe true;
427-
ad4(1) > 2 shouldBe true;
428-
val pl4 = vs(4).genotypes("test1")[IndexedSeq[Int]]("PL")
429-
pl4(1) shouldBe 0
430-
}
431-
)
430+
val ad4 = vs(3 + offset).genotypes("test1")[IndexedSeq[Int]]("AD")
431+
ad4(0) < 110 shouldBe true
432+
// changes due to random number generator
433+
val expectedAD41 = if (winnow) { 0 } else { 1 }
434+
ad4(1) shouldBe expectedAD41
435+
val pl4 = vs(3 + offset).genotypes("test1")[IndexedSeq[Int]]("PL")
436+
pl4(0) shouldBe 0
437+
438+
val ad5 = vs(4 + offset).genotypes("test1")[IndexedSeq[Int]]("AD")
439+
ad5(0) < 100 shouldBe true
440+
ad5(1) < 100 shouldBe true
441+
ad5(0) > 1 shouldBe true
442+
ad5(1) > 2 shouldBe true
443+
val pl5 = vs(4 + offset).genotypes("test1")[IndexedSeq[Int]]("PL")
444+
pl5(1) shouldBe 0
445+
})
446+
})
432447

433448
}
434449

@@ -465,50 +480,50 @@ class DownsampleVcfTest extends UnitSpec {
465480
vs should have length 7
466481

467482
val ad0 = vs(0).genotypes("test1")[IndexedSeq[Int]]("AD")
468-
ad0(0) < 110 shouldBe true;
483+
ad0(0) < 110 shouldBe true
469484
ad0(1) < 110 shouldBe true
470485
val pl0 = vs(0).genotypes("test1")[IndexedSeq[Int]]("PL")
471486
pl0(1) shouldBe 0
472487

473488
val ad1 = vs(1).genotypes("test1")[IndexedSeq[Int]]("AD")
474-
ad1(0) shouldBe 0;
489+
ad1(0) shouldBe 0
475490
ad1(1) < 110 shouldBe true
476491
val pl1 = vs(1).genotypes("test1")[IndexedSeq[Int]]("PL")
477492
pl1(2) shouldBe 0
478493

479494
val ad2 = vs(2).genotypes("test1")[IndexedSeq[Int]]("AD")
480-
ad2(0) shouldBe 0;
495+
ad2(0) shouldBe 0
481496
ad2(1) shouldBe 0
482497
val pl2 = vs(2).genotypes("test1")[IndexedSeq[Int]]("PL")
483-
pl2(0) shouldBe 0;
484-
pl2(1) shouldBe 0;
498+
pl2(0) shouldBe 0
499+
pl2(1) shouldBe 0
485500
pl2(2) shouldBe 0
486501

487502
val ad3 = vs(3).genotypes("test1")[IndexedSeq[Int]]("AD")
488-
ad3(0) < 30 shouldBe true;
503+
ad3(0) < 30 shouldBe true
489504
ad3(1) < 110 shouldBe true
490505
val pl3 = vs(3).genotypes("test1")[IndexedSeq[Int]]("PL")
491506
pl3(2) shouldBe 0
492507

493508
val ad4 = vs(4).genotypes("test1")[IndexedSeq[Int]]("AD")
494-
ad4(0) < 110 shouldBe true;
495-
ad4(1) shouldBe 0;
509+
ad4(0) < 110 shouldBe true
510+
ad4(1) shouldBe 0
496511
val pl4 = vs(4).genotypes("test1")[IndexedSeq[Int]]("PL")
497512
pl4(0) shouldBe 0
498513

499514
val ad5 = vs(5).genotypes("test1")[IndexedSeq[Int]]("AD")
500-
ad5(0) shouldBe 0;
515+
ad5(0) shouldBe 0
501516
ad5(1) shouldBe 0
502517
val pl5 = vs(5).genotypes("test1")[IndexedSeq[Int]]("PL")
503-
pl5(0) shouldBe 0;
504-
pl5(1) shouldBe 0;
518+
pl5(0) shouldBe 0
519+
pl5(1) shouldBe 0
505520
pl5(2) shouldBe 0
506521

507522
val ad6 = vs(6).genotypes("test1")[IndexedSeq[Int]]("AD")
508-
ad6(0) < 100 shouldBe true;
509-
ad6(1) < 100 shouldBe true;
510-
ad6(0) > 1 shouldBe true;
511-
ad6(1) > 2 shouldBe true;
523+
ad6(0) < 100 shouldBe true
524+
ad6(1) < 100 shouldBe true
525+
ad6(0) > 1 shouldBe true
526+
ad6(1) > 2 shouldBe true
512527
val pl6 = vs(6).genotypes("test1")[IndexedSeq[Int]]("PL")
513528
pl6(1) shouldBe 0
514529
}

0 commit comments

Comments
 (0)