Skip to content

Commit

Permalink
ClinVarXMLParser: more fixes to HGVS parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMadBug committed Sep 1, 2023
1 parent e5eae44 commit 3c66ae5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion annotation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def refresh_force_vcv(self, request, queryset: QuerySet[ClinVarRecordCollection]
messages.info(request, message=f"Fetching took {duration}")


@admin_action("Refresh: Force (using RCVS)")
@admin_action("Refresh: Force (using RCVs)")
def refresh_force_rcvs(self, request, queryset: QuerySet[ClinVarRecordCollection]):
start = datetime.now()
for obj in queryset:
Expand Down
7 changes: 4 additions & 3 deletions annotation/clinvar_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def parse_xml_date(text: str) -> Optional[datetime]:

@staticmethod
def parse_hgvs(text: str) -> str:
if match := ClinVarXmlParser.RE_GOOD_CHGVS.match(text):
return match.group(1)
return text
if text:
if match := ClinVarXmlParser.RE_GOOD_CHGVS.match(text):
return match.group(1)
return None

@classmethod
@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions annotation/clinvar_xml_parser_via_rcvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def parse_allele_origin(self, elem):
"AttributeSet",
PP("Attribute", Type="HGVS"))
def parse_c_hgvs(self, elem):
if hgvs := elem.text:
self.latest.c_hgvs = ClinVarXmlParser.parse_hgvs(hgvs)
if hgvs := ClinVarXmlParser.parse_hgvs(elem.text):
self.latest.c_hgvs = hgvs

@parser_path(
PP("MeasureSet", Type="Variant"),
Expand Down
13 changes: 7 additions & 6 deletions annotation/clinvar_xml_parser_via_vcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ClinVarXmlParserViaVCV(ClinVarXmlParser):

PARSER_VERSION = 201 # change this whenever the parsing changes, so we know to ignore the old cache
PARSER_VERSION = 202 # change this whenever the parsing changes, so we know to ignore the old cache

@classmethod
def load_from_clinvar_id(cls, clinvar_variation_id: int) -> ClinVarXmlParserOutput:
Expand Down Expand Up @@ -79,18 +79,19 @@ def parse_clinical_significance(self, elem):
"OtherNameList",
"Name"
)
def parse_possible_c_hgvs(self, elem):
def _parse_possible_c_hgvs(self, elem):
if elem.get("Type") is None and (hgvs := elem.text):
self.latest.c_hgvs = ClinVarXmlParser.parse_hgvs(hgvs)
if hgvs := ClinVarXmlParser.parse_hgvs(hgvs):
self.latest.c_hgvs = hgvs

@parser_path(
"SimpleAllele",
"AttributeSet",
PP("Attribute", Type="HGVS"))
def parse_c_hgvs(self, elem):
def _parse_c_hgvs(self, elem):
if not self.latest.c_hgvs:
if hgvs := elem.text:
self.latest.c_hgvs = ClinVarXmlParser.parse_hgvs(hgvs)
if hgvs := ClinVarXmlParser.parse_hgvs(elem.text):
self.latest.c_hgvs = hgvs

@parser_path(
"SimpleAllele",
Expand Down

0 comments on commit 3c66ae5

Please sign in to comment.