@@ -369,66 +369,81 @@ class DownsampleVcfTest extends UnitSpec {
369
369
Metric .write(metadata, Seq (Sample (SAMPLE_NAME = sample, BASE_COUNT = 100 )))
370
370
371
371
" 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 => {
374
374
// Construct the input VCF
375
375
val outVcf = makeTempFile(" out" , " .vcf.gz" )
376
+ val windowSize = if (winnow) { 150 } else { 0 }
376
377
kind match {
377
378
case " proportion" =>
378
379
new DownsampleVcf (input= inVcf,
379
380
output= outVcf,
380
381
proportion= Some (0.01 ),
381
- windowSize= 150 ).execute()
382
+ windowSize= windowSize ).execute()
382
383
case " number" =>
383
384
new DownsampleVcf (input= inVcf,
384
385
output= outVcf,
385
386
originalBases= Some (100 ),
386
387
downsampleToBases= Some (1 ),
387
- windowSize= 150 ).execute()
388
+ windowSize= windowSize ).execute()
388
389
case " metadata" =>
389
390
new DownsampleVcf (input= inVcf,
390
391
output= outVcf,
391
392
metadata= Some (metadata),
392
393
downsampleToBases= Some (1 ),
393
- windowSize= 150 ).execute()
394
+ windowSize= windowSize ).execute()
394
395
}
395
396
396
397
val vs = readVcfRecs(outVcf)
397
- vs should have length 5
398
+ val expectedLength = if (winnow) { 5 } else { 6 }
399
+ vs should have length expectedLength
398
400
399
401
val ad0 = vs(0 ).genotypes(" test1" )[IndexedSeq [Int ]](" AD" )
400
- ad0(0 ) < 110 shouldBe true ;
402
+ ad0(0 ) < 110 shouldBe true
401
403
ad0(1 ) < 110 shouldBe true
402
404
val pl0 = vs(0 ).genotypes(" test1" )[IndexedSeq [Int ]](" PL" )
403
405
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
+ }
404
417
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
413
420
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" )
415
422
pl2(2 ) shouldBe 0
416
423
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
422
429
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
+ })
432
447
433
448
}
434
449
@@ -465,50 +480,50 @@ class DownsampleVcfTest extends UnitSpec {
465
480
vs should have length 7
466
481
467
482
val ad0 = vs(0 ).genotypes(" test1" )[IndexedSeq [Int ]](" AD" )
468
- ad0(0 ) < 110 shouldBe true ;
483
+ ad0(0 ) < 110 shouldBe true
469
484
ad0(1 ) < 110 shouldBe true
470
485
val pl0 = vs(0 ).genotypes(" test1" )[IndexedSeq [Int ]](" PL" )
471
486
pl0(1 ) shouldBe 0
472
487
473
488
val ad1 = vs(1 ).genotypes(" test1" )[IndexedSeq [Int ]](" AD" )
474
- ad1(0 ) shouldBe 0 ;
489
+ ad1(0 ) shouldBe 0
475
490
ad1(1 ) < 110 shouldBe true
476
491
val pl1 = vs(1 ).genotypes(" test1" )[IndexedSeq [Int ]](" PL" )
477
492
pl1(2 ) shouldBe 0
478
493
479
494
val ad2 = vs(2 ).genotypes(" test1" )[IndexedSeq [Int ]](" AD" )
480
- ad2(0 ) shouldBe 0 ;
495
+ ad2(0 ) shouldBe 0
481
496
ad2(1 ) shouldBe 0
482
497
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
485
500
pl2(2 ) shouldBe 0
486
501
487
502
val ad3 = vs(3 ).genotypes(" test1" )[IndexedSeq [Int ]](" AD" )
488
- ad3(0 ) < 30 shouldBe true ;
503
+ ad3(0 ) < 30 shouldBe true
489
504
ad3(1 ) < 110 shouldBe true
490
505
val pl3 = vs(3 ).genotypes(" test1" )[IndexedSeq [Int ]](" PL" )
491
506
pl3(2 ) shouldBe 0
492
507
493
508
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
496
511
val pl4 = vs(4 ).genotypes(" test1" )[IndexedSeq [Int ]](" PL" )
497
512
pl4(0 ) shouldBe 0
498
513
499
514
val ad5 = vs(5 ).genotypes(" test1" )[IndexedSeq [Int ]](" AD" )
500
- ad5(0 ) shouldBe 0 ;
515
+ ad5(0 ) shouldBe 0
501
516
ad5(1 ) shouldBe 0
502
517
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
505
520
pl5(2 ) shouldBe 0
506
521
507
522
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
512
527
val pl6 = vs(6 ).genotypes(" test1" )[IndexedSeq [Int ]](" PL" )
513
528
pl6(1 ) shouldBe 0
514
529
}
0 commit comments