Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Pulls all the attributes of an xml.dom.minidom xml branch.
These are generally things like index, id, etc.
:param xml.dom.minidom branch: An xml.dom.minidom object.
:return: A dictionary of attributes with each key being the attribute name and its value being the value of that
attribute.
:rtype: dict
**Notes**
The script will attempt to convert any values to float or
integer in order to reduce TypeErrors when trying to use
the extracted values.
"""
return {key: stringtodigit(val) for key, val in branch.attributes.items()}
def branch_cvparams(branch):
"""
Interprets an xml branch as CVParams
:param branch:
:return: controlled value parameter set with values
:rtype: CVParameterSet
"""
out = {}
for cvParam in branch.getElementsByTagName('cvParam'):
acc = cvParam.getAttribute('accession') # accession key
out[acc] = {}
for attribute, value in cvParam.attributes.items(): # pull all the attributes
if attribute != 'accession':
# attempt to convert to integer or float, keep as string otherwise
out[acc][attribute] = stringtodigit(value)
return CVParameterSet(**out)