Skip to content

Commit

Permalink
fixup(data-pipeline): PR review, use saxutils built in quoteattr func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
rileyhgrant committed Nov 18, 2024
1 parent bacbc86 commit 01d67b0
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions data-pipeline/src/data_pipeline/datasets/clinvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys
from xml.etree import ElementTree
import xml.sax.saxutils as saxutils
from xml.sax.saxutils import quoteattr

import hail as hl
from tqdm import tqdm
Expand Down Expand Up @@ -36,20 +36,13 @@
}


def escape_xpath_value(value):
if value is None:
return ""
value = value.replace('"', """).replace("'", "'")
return saxutils.escape(value)


def find_mapping_elements_by_xref(trait_element, submission_element, trait_mapping_list_element):
if trait_mapping_list_element is None:
return None

xref_elements = trait_element.findall("XRef")
for xref_element in xref_elements:
selector = f"./TraitMapping[@ClinicalAssertionID='{submission_element.attrib['ID']}'][@TraitType='{trait_element.attrib['Type']}'][@MappingType='XRef'][@MappingValue='{escape_xpath_value(xref_element.attrib['ID'])}']" # noqa
selector = f"./TraitMapping[@ClinicalAssertionID='{submission_element.attrib['ID']}'][@TraitType='{trait_element.attrib['Type']}'][@MappingType='XRef'][@MappingValue={quoteattr(xref_element.attrib['ID'])}]" # noqa
mapping_element = trait_mapping_list_element.find(selector)
if mapping_element is not None:
return mapping_element
Expand All @@ -60,7 +53,7 @@ def find_mapping_elements_by_preferred_name(trait_element, submission_element, t
preferred_name_element = trait_element.find("./Name/ElementValue[@Type='Preferred']")

if preferred_name_element is not None and trait_mapping_list_element is not None:
selector = f"./TraitMapping[@ClinicalAssertionID='{submission_element.attrib['ID']}'][@TraitType='{trait_element.attrib['Type']}'][@MappingType='Name'][@MappingValue='{escape_xpath_value(preferred_name_element.text)}']" # noqa
selector = f"./TraitMapping[@ClinicalAssertionID='{submission_element.attrib['ID']}'][@TraitType='{trait_element.attrib['Type']}'][@MappingType='Name'][@MappingValue={quoteattr(preferred_name_element.text)}]" # noqa
mapping_element = trait_mapping_list_element.find(selector)
return mapping_element, preferred_name_element

Expand All @@ -76,7 +69,7 @@ def find_mapping_elements_by_name(trait_element, submission_element, trait_mappi
preferred_name_element = name_element

if trait_mapping_list_element is not None:
selector = f"./TraitMapping[@ClinicalAssertionID='{submission_element.attrib['ID']}'][@TraitType='{trait_element.attrib['Type']}'][@MappingType='Name'][@MappingValue='{escape_xpath_value(name_element.text)}']" # noqa
selector = f"./TraitMapping[@ClinicalAssertionID='{submission_element.attrib['ID']}'][@TraitType='{trait_element.attrib['Type']}'][@MappingType='Name'][@MappingValue={quoteattr(name_element.text)}]" # noqa
mapping_element = trait_mapping_list_element.find(selector)
if mapping_element:
return mapping_element, preferred_name_element
Expand Down

0 comments on commit 01d67b0

Please sign in to comment.