diff --git a/tests/cases/dummy_haploid.vcf.gz b/tests/cases/dummy_haploid.vcf.gz new file mode 100644 index 0000000000000000000000000000000000000000..e0f25567c4e32ae177347b1243e8ed439852a78e Binary files /dev/null and b/tests/cases/dummy_haploid.vcf.gz differ diff --git a/tests/cases/dummy_haploid.vcf.gz.tbi b/tests/cases/dummy_haploid.vcf.gz.tbi new file mode 100644 index 0000000000000000000000000000000000000000..a45d08c4d0fe3703b41aa5274203d985e7e934d9 Binary files /dev/null and b/tests/cases/dummy_haploid.vcf.gz.tbi differ diff --git a/tests/test_evaluate.py b/tests/test_evaluate.py index 85bd91a03a2ad4af2e1a51fb5b976443b58ad079..895a5b717dd6416b09dcace21610566bb6e5b183 100644 --- a/tests/test_evaluate.py +++ b/tests/test_evaluate.py @@ -158,3 +158,29 @@ def test_decomposed_call_file(): match='Decomposed variants are not supported'): site_concordancy(call, positive, call_samples=['BLANK'], positive_samples=['NA12878']) + + +def test_haploid_positive_file(): + """ Test error message when the positive vcf contains non-diploid variants + """ + filename = 'tests/cases/gatk.vcf.gz' + haploid = 'tests/cases/dummy_haploid.vcf.gz' + call = VCF(filename, gts012=True) + positive = VCF(haploid, gts012=True) + with pytest.raises(NotImplementedError, + match='Non-diploid variants are not supported'): + site_concordancy(call, positive, call_samples=['NA12878'], + positive_samples=['BLANK']) + + +def test_haploid_call_file(): + """ Test error message when the call vcf contains non-diploid variants + """ + filename = 'tests/cases/gatk.vcf.gz' + haploid = 'tests/cases/dummy_haploid.vcf.gz' + call = VCF(haploid, gts012=True) + positive = VCF(filename, gts012=True) + with pytest.raises(NotImplementedError, + match='Non-diploid variants are not supported'): + site_concordancy(call, positive, call_samples=['BLANK'], + positive_samples=['NA12878']) diff --git a/vtools/evaluate.py b/vtools/evaluate.py index bb751ec7c2b4ad0dac0d4108711b07b8fa18174f..498e1ea4ce21614b301c13636095dd536e466340 100644 --- a/vtools/evaluate.py +++ b/vtools/evaluate.py @@ -174,6 +174,10 @@ def site_concordancy(call_vcf: VCF, pos = pos_record.genotypes[p_s] cal = call_record.genotypes[c_s] + # If the genotypes are not diploid + if len(pos) != 3 or len(cal) != 3: + raise NotImplementedError('Non-diploid variants are not ' + 'supported') # If the genotypes are phased if pos[2] or cal[2]: raise NotImplementedError('Phased variants are not supported')