Skip to content

Commit

Permalink
Merge branch 'biocommons:main' into issue_178_abc_EDit
Browse files Browse the repository at this point in the history
  • Loading branch information
davmlaw authored Mar 21, 2024
2 parents 0734cfa + 3c6c265 commit 76e5f01
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/hgvs/extras/babelfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,24 @@ def hgvs_to_vcf(self, var_g):
return chrom, start_i + 1, ref, alt, typ

def vcf_to_g_hgvs(self, chrom, position, ref, alt):
# VCF spec https://samtools.github.io/hts-specs/VCFv4.1.pdf
# says for REF/ALT "Each base must be one of A,C,G,T,N (case insensitive)"
ref = ref.upper()
alt = alt.upper()

ac = self.name_to_ac_map[chrom]

# Strip common prefix
if len(alt) > 1 and len(ref) > 1:
pfx = os.path.commonprefix([ref, alt])
lp = len(pfx)
if lp > 0:
ref = ref[lp:]
alt = alt[lp:]
position += lp
if ref != alt:
# Strip common prefix
if len(alt) > 1 and len(ref) > 1:
pfx = os.path.commonprefix([ref, alt])
lp = len(pfx)
if lp > 0:
ref = ref[lp:]
alt = alt[lp:]
position += lp
elif alt == ".":
alt = ref

if ref == "": # Insert
# Insert uses coordinates around the insert point.
Expand All @@ -93,9 +101,6 @@ def vcf_to_g_hgvs(self, chrom, position, ref, alt):
start = position
end = position + len(ref) - 1

if alt == ".":
alt = ref

var_g = SequenceVariant(
ac=ac,
type="g",
Expand Down
Binary file modified tests/data/cache-py3.hdp
Binary file not shown.
12 changes: 11 additions & 1 deletion tests/test_hgvs_extras_babelfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
"NC_000006.12:g.49949407=",
[],
("6", 49949407, "A", ".", "identity"),
[("6", 49949407, "A", "A", "identity")],
[("6", 49949407, "A", "A", "identity"),
# Test case insensitivity
("6", 49949407, "A", "a", "identity"),
("6", 49949407, "a", "A", "identity"),]
),
# Test multi-base identity
(
"NC_000006.12:g.49949407_49949408=",
[],
("6", 49949407, "AA", ".", "identity"),
[("6", 49949407, "AA", "AA", "identity")],
),
# snv
(
Expand Down

0 comments on commit 76e5f01

Please sign in to comment.