From a662866807407021a0bebec995b10ae0e593c37a Mon Sep 17 00:00:00 2001 From: pd3 Date: Sun, 17 Nov 2024 20:30:03 +0100 Subject: [PATCH] Fix a bug in breakend detection it was incorrectly assumed that the ALT allele is of equal length to REF allele, but the VCF specification allows breakend insertions, such as C > CAGTNNNNNCA[2:321682[ Resolves https://github.com/samtools/bcftools/issues/2317 --- test/test-bcf_set_variant_type.c | 13 +++++++++++++ vcf.c | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/test-bcf_set_variant_type.c b/test/test-bcf_set_variant_type.c index eb12ecde3..4fd3313dd 100644 --- a/test/test-bcf_set_variant_type.c +++ b/test/test-bcf_set_variant_type.c @@ -91,6 +91,19 @@ static void test_bcf_set_variant_type(void) { error("[16:33625444[N was not detected as a breakend"); } + + bcf_set_variant_type("T", "]chrB:123]AGTNNNNNCAT", &var3d); + if ( var3d.type != VCF_BND) + { + error("]chrB:123]AGTNNNNNCAT was not detected as a breakend"); + } + bcf_set_variant_type("C", "CAGTNNNNNCA[chrA:321[", &var3d); + if ( var3d.type != VCF_BND) + { + error("CAGTNNNNNCA[chrA:321[ was not detected as a breakend"); + } + + // Test special reference alleles bcf_variant_t var4a; bcf_set_variant_type("A", "", &var4a); diff --git a/vcf.c b/vcf.c index 105c7539d..f22f4450d 100644 --- a/vcf.c +++ b/vcf.c @@ -5025,8 +5025,8 @@ static void bcf_set_variant_type(const char *ref, const char *alt, bcf_variant_t if ( *a && !*r ) { - if ( *a==']' || *a=='[' ) { var->type = VCF_BND; return; } // "joined after" breakend while ( *a ) a++; + if ( *(a-1)==']' || *(a-1)=='[' ) { var->type = VCF_BND; return; } // "joined after" breakend var->n = (a-alt)-(r-ref); var->type = VCF_INDEL | VCF_INS; return; } else if ( *r && !*a )