Skip to content

Commit 4d4c7ea

Browse files
committed
Validate allele format
- Validate that the format of the fields are correct. eg. `DQA1*01:01:01:G` is invalid
1 parent 85b7c11 commit 4d4c7ea

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pyard/ard.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ def _redux_allele(
170170
:rtype: str
171171
"""
172172

173-
validate_reduction_type(redux_type)
174-
175173
# deal with leading 'HLA-'
176174
if HLA_regex.search(allele):
177175
hla, allele_name = allele.split("-")
@@ -642,14 +640,18 @@ def _is_valid(self, allele: str) -> bool:
642640
if allele.endswith(("P", "G")):
643641
# remove the last character
644642
allele = allele[:-1]
645-
if self._is_valid_allele(allele):
646-
return True
647-
else:
648-
allele = get_2field_allele(allele)
649-
if self._is_valid_allele(allele):
650-
return True
643+
# validate format: there are no empty fields eg, 2 :: together
644+
if "*" in allele:
645+
_, fields = allele.split("*")
646+
if not all(map(str.isalnum, fields.split(":"))):
647+
return False
648+
# The allele is valid as whole or as a 2 field version
649+
if self._is_valid_allele(allele):
650+
return True
651+
else:
652+
allele = get_2field_allele(allele)
653+
return self._is_valid_allele(allele)
651654

652-
return self._is_valid_allele(allele)
653655
return True
654656

655657
def _is_valid_gl(self, glstring: str) -> bool:

0 commit comments

Comments
 (0)