78cdae7249c8609dcbc743e996ea7e5eec33d75a
max
  Mon Aug 17 08:15:39 2026 -0700
lrSv: fix off-by-one anchor base in deletion coordinates across converters, refs #38099

VCF/pangenome deletions carry a non-deleted anchor (padding) base at POS.
Several lrSv converters set chromStart = pos-1, which includes that anchor, so
each deletion was 1 bp too wide on the left and svLen was 1 too big. Callsets
handled this inconsistently, so the same deletion appeared at offset coordinates
and failed to merge in lrSvAll.

For deletions only (INS/INV/CPX unchanged), advance chromStart past the anchor
so the interval covers exactly the deleted bases (svLen == |SVLEN|). Verified
against the hg38 reference: the old left base is present in both REF and ALT
(i.e. retained by the sample), so it should not be inside the deletion.

Fixed 11 converters: lrSv1kLin1218VcfToBed, lrSv1kgOntVcfToBed,
lrSvGustafsonVcfToBed, lrSvGa4kSvVcfToBed, lrSvDecodeVcfToBed,
lrSvAou1kCsvToBed, lrSvColorsDbSvVcfToBed, lrSvCardBbToBed, lrSvAprVcfToBed,
lrSvCpc1VcfToBed, lrSvVcfToBed (generic, used by han945).

Left unchanged, verified already anchor-correct: hgsvc3 and hgsvc2 (0-based
source), hprc2v21 (Ro converter prefix-trims), noyvert/tommoJp (POS is the
first deleted base), chirmade101 (1-based-closed source).

Rebuilt all affected bigBeds (hg38 + hs1 where present) and the lrSvAll merge:
3,111,026 -> 2,963,093 rows as ~148k duplicate deletions now merge.

diff --git src/hg/makeDb/scripts/lrSv/lrSvGustafsonVcfToBed.py src/hg/makeDb/scripts/lrSv/lrSvGustafsonVcfToBed.py
index 8aa12b9e016..70dc5bdbdda 100644
--- src/hg/makeDb/scripts/lrSv/lrSvGustafsonVcfToBed.py
+++ src/hg/makeDb/scripts/lrSv/lrSvGustafsonVcfToBed.py
@@ -1,135 +1,140 @@
 #!/usr/bin/env python3
 """Convert the Gustafson 2024 1000G ONT Jasmine-merged SV VCF to BED9+.
 
 Usage:
     lrSvGustafsonVcfToBed.py input.vcf.gz output.bed
 
 Source:
     https://s3.amazonaws.com/1000g-ont/Gustafson_etal_2024_preprint_SUPPLEMENTAL/
     20240423_jasmine_intrasample_noBND_custom_suppvec_alphanumeric_header_JASMINE.vcf.gz
 Paper:
     Gustafson et al. 2024, bioRxiv / Genome Res, PMID 39358015.
 """
 
 import gzip
 import os
 import sys
 
 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
 from lrSvCommon import svName, normalizeSvType, svColor
 
 # Jasmine END on chrM can overshoot by one base; clip to chrM length.
 CHRM_LEN = 16569
 
 
 def openVcf(path):
     """Open a local .vcf.gz via gzip; everything else as plain text."""
     return gzip.open(path, "rt") if path.endswith(".gz") else open(path, "rt")
 
 
 def parseInfo(infoStr):
     d = {}
     for item in infoStr.split(";"):
         if "=" in item:
             k, v = item.split("=", 1)
             d[k] = v
         else:
             d[item] = True
     return d
 
 
 def main():
     if len(sys.argv) != 3:
         print(__doc__, file=sys.stderr)
         sys.exit(1)
 
     inPath, outPath = sys.argv[1], sys.argv[2]
 
     seen = set()
     nIn = 0
     nDup = 0
     with openVcf(inPath) as fIn, open(outPath, "w") as fOut:
         for line in fIn:
             if line.startswith("#"):
                 continue
             nIn += 1
             fields = line.rstrip("\n").split("\t")
             chrom = fields[0]
             pos = int(fields[1])
             rowName = fields[2]
             info = parseInfo(fields[7])
 
             svTypeRaw = info.get("SVTYPE", ".")
             svType = normalizeSvType(svTypeRaw)
             end = int(info.get("END", pos))
             try:
                 svLenRaw = int(float(info.get("SVLEN", "0")))
             except ValueError:
                 svLenRaw = 0
             try:
                 supp = int(info.get("SUPP", "0"))
             except ValueError:
                 supp = 0
             try:
                 varCalls = int(info.get("VARCALLS", "0"))
             except ValueError:
                 varCalls = 0
             precise = 1 if "PRECISE" in info else 0
             strands = info.get("STRANDS", "")
             if strands == "??":
                 strands = ""
 
             chromStart = pos - 1
             chromEnd = end
+            # POS is the non-deleted anchor base; drop it from the left of DEL
+            # intervals so svLen == |SVLEN| and coordinates match anchor-excluded
+            # callsets. INS/other keep the anchor-based position.
+            if svType == "DEL":
+                chromStart += 1
             if chromEnd <= chromStart:
                 chromEnd = chromStart + 1
             if chrom == "chrM" and chromEnd > CHRM_LEN:
                 chromEnd = CHRM_LEN
 
             svLen = chromEnd - chromStart
             if svType in ("INS", "MEI"):
                 insLen = abs(svLenRaw)
             else:
                 insLen = 0
 
             # Gustafson callset is site-level without AC; 2 * SUPP
             # is the diploid carrier upper bound.
             ac = supp * 2
 
             color = svColor(svType)
 
             featLen = insLen if svType in ("INS", "MEI") else svLen
             name = svName(svType, featLen, ac)
 
             row = [
                 chrom,
                 str(chromStart),
                 str(chromEnd),
                 name,
                 "0",
                 ".",
                 str(chromStart),
                 str(chromEnd),
                 color,
                 svType,
                 str(svLen),
                 str(insLen),
                 str(ac),
                 str(supp),
                 str(varCalls),
                 str(precise),
                 strands,
             ]
             line_out = "\t".join(row)
             if line_out in seen:
                 nDup += 1
                 continue
             seen.add(line_out)
             fOut.write(line_out + "\n")
 
     print(f"Gustafson: {nIn:,} input records, {nDup:,} duplicate rows dropped, "
           f"{nIn - nDup:,} written", file=sys.stderr)
 
 
 if __name__ == "__main__":
     main()