Skip to content

Commit

Permalink
Merge pull request #9 from VariantEffect/targetseq-fix
Browse files Browse the repository at this point in the history
fix amino acid target seq validation
  • Loading branch information
afrubin committed Jan 8, 2021
2 parents 9b2929b + 7830d81 commit 39d71ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
11 changes: 10 additions & 1 deletion mavehgvs/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
import itertools
from typing import Optional, Union, List, Tuple, Mapping, Any, Sequence, Dict, Generator

from fqfa.constants import AA_CODES

from mavehgvs.position import VariantPosition
from mavehgvs.patterns.combined import any_variant
from mavehgvs.exceptions import MaveHgvsParseError

__all__ = ["Variant"]

AA_3_TO_1 = {value: key for key, value in AA_CODES.items()}
"""Dict[str, str]: for converting three-letter amino acid codes to single-letter codes.
"""

class Variant:
fullmatch = re.compile(any_variant, flags=re.ASCII).fullmatch
Expand Down Expand Up @@ -178,7 +183,11 @@ def sort_key(x):
if targetseq is not None:
for vtype, pos, seq in self.variant_tuples():
if vtype == "sub":
self._target_validate_substitution(pos, seq[0], targetseq)
if self._prefix == "p":
ref = AA_3_TO_1[seq[0]]
else:
ref = seq[0]
self._target_validate_substitution(pos, ref, targetseq)
elif vtype in ("ins", "del", "dup", "delins"):
self._target_validate_indel(pos, targetseq)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setuptools.setup(
name="mavehgvs",
version="0.2.0",
version="0.2.1",
author="Daniel Esposito and Alan F Rubin",
author_email="alan.rubin@wehi.edu.au",
description=(
Expand Down
24 changes: 24 additions & 0 deletions tests/test_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,30 @@ def test_invalid_dna_delins(self):
with self.assertRaises(MaveHgvsParseError):
Variant(s, targetseq=target)

def test_matching_protein_substitution(self):
variant_tuples = [
("RCQY", "p.Arg1Ala"),
("RCQY", "p.Gln3Trp"),
("RCQY", "p.[Arg1Ala;Gln3Trp]"),
]

for target, s in variant_tuples:
with self.subTest(target=target, s=s):
v = Variant(s, targetseq=target)
self.assertEqual(s, str(v))

def test_nonmatching_protein_substitution(self):
variant_tuples = [
("RCQY", "p.Cys1Ala"),
("RCQY", "p.Ala3Trp"),
("RCQY", "p.[Arg1Ala;Cys3Trp]"),
]

for target, s in variant_tuples:
with self.subTest(target=target, s=s):
with self.assertRaises(MaveHgvsParseError):
Variant(s, targetseq=target)


class TestMiscMethods(unittest.TestCase):
def test_is_multi_variant(self):
Expand Down

0 comments on commit 39d71ce

Please sign in to comment.