Skip to content

Commit 4ec5d3b

Browse files
committed
add strand flip unit tests
1 parent 1e1afc7 commit 4ec5d3b

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

tests/testthat/test-pgs-application.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ test_that(
737737
test_that(
738738
'apply.polygenic.score correctly handles strand flipping', {
739739
load('data/strand.flip.test.data.Rda');
740+
# no strand flip correction
740741
strand.flip.raw.data <- apply.polygenic.score(
741742
vcf.data = strand.flip.test.data$strand.flip.vcf.data,
742743
pgs.weight.data = strand.flip.test.data$strand.flip.pgs.weight.data,
@@ -754,6 +755,7 @@ test_that(
754755
c(0, 0, 0)
755756
);
756757

758+
# strand flip correction
757759
strand.flip.correct.flips <- apply.polygenic.score(
758760
vcf.data = strand.flip.test.data$strand.flip.vcf.data,
759761
pgs.weight.data = strand.flip.test.data$strand.flip.pgs.weight.data,
@@ -771,6 +773,7 @@ test_that(
771773
c(0, 0, 0)
772774
);
773775

776+
# ambiguous allele matches removed
774777
strand.flip.remove.ambiguous <- apply.polygenic.score(
775778
vcf.data = strand.flip.test.data$strand.flip.vcf.data,
776779
pgs.weight.data = strand.flip.test.data$strand.flip.pgs.weight.data,
@@ -789,6 +792,28 @@ test_that(
789792
c(2, 2, 2)
790793
);
791794

795+
# ambiguous allele matches not removed due to threshold
796+
strand.flip.threshold.ambiguous <- apply.polygenic.score(
797+
vcf.data = strand.flip.test.data$strand.flip.vcf.data,
798+
pgs.weight.data = strand.flip.test.data$strand.flip.pgs.weight.data,
799+
correct.strand.flips = TRUE,
800+
missing.genotype.method = c('none', 'mean.dosage', 'normalize'),
801+
remove.ambiguous.allele.matches = TRUE,
802+
max.strand.flips = 3 # there are two unambiguous strand flips in the test data, setting threshold above that
803+
);
804+
805+
# expect equal to not removing ambiguous allele matches
806+
expect_equal(
807+
strand.flip.threshold.ambiguous$pgs.output$PGS, # dosage is unaffected because unresolved mismatch does not contain an effect allele so dosage is 0
808+
strand.flip.correct.flips$pgs.output$PGS
809+
);
810+
811+
expect_equal(
812+
strand.flip.threshold.ambiguous$pgs.output$n.missing.genotypes,
813+
c(1, 1, 1) # the unresolved mismatch is marked missing
814+
);
815+
816+
# indels removed
792817
strand.flip.remove.indel.mismatches <- apply.polygenic.score(
793818
vcf.data = strand.flip.test.data$strand.flip.vcf.data,
794819
pgs.weight.data = strand.flip.test.data$strand.flip.pgs.weight.data,

tests/testthat/test-strand-flip-handling.R

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,61 @@ test_that(
442442
c('A', NA)
443443
);
444444

445+
# palindromic case, return.ambiguous.as.missing == TRUE, max.strand.flips = 1
446+
# expected output: all ambiguous returned as-is due to lack of unambiguous strand flips
447+
448+
test.ambiguous.below.threshold <- assess.pgs.vcf.allele.match(
449+
c('A', 'A'),
450+
c('G', 'T'),
451+
c('A', 'T'),
452+
c('G', 'A'),
453+
return.ambiguous.as.missing = TRUE,
454+
max.strand.flips = 1
455+
);
456+
457+
expect_equal(
458+
test.ambiguous.below.threshold$match.status,
459+
c('default_match', 'ambiguous_flip')
460+
);
461+
462+
expect_equal(
463+
test.ambiguous.below.threshold$new.pgs.effect.allele,
464+
c('G', 'A')
465+
);
466+
467+
expect_equal(
468+
test.ambiguous.below.threshold$new.pgs.other.allele,
469+
c('A', 'T')
470+
);
471+
472+
# palindromic case, return.ambiguous.as.missing == TRUE, max.strand.flips = 2, strand flips exceed threshold
473+
# expected output: all ambiguous returned as missing due to number of unambiguous strand flips exceeding threshold
474+
475+
test.ambiguous.above.threshold <- assess.pgs.vcf.allele.match(
476+
# last three alleles are unambiguous strand flips
477+
c('A', 'A', 'A', 'A', 'A'),
478+
c('G', 'T', 'G', 'C', 'G'),
479+
c('A', 'T', 'T', 'T', 'T'),
480+
c('G', 'A', 'C', 'G', 'C'),
481+
return.ambiguous.as.missing = TRUE,
482+
max.strand.flips = 2
483+
);
484+
485+
expect_equal(
486+
test.ambiguous.above.threshold$match.status,
487+
c('default_match', 'ambiguous_flip', 'strand_flip', 'strand_flip', 'strand_flip')
488+
);
489+
490+
expect_equal(
491+
test.ambiguous.above.threshold$new.pgs.effect.allele,
492+
c('G', NA, 'G', 'C', 'G')
493+
);
494+
495+
expect_equal(
496+
test.ambiguous.above.threshold$new.pgs.other.allele,
497+
c('A', NA, 'A', 'A', 'A')
498+
);
499+
445500
# unresolved case, return.ambiguous.as.missing == TRUE
446501
test.unresolved.missing <- assess.pgs.vcf.allele.match(
447502
c('A', 'A'),

0 commit comments

Comments
 (0)