-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from helxplatform/radx-parser
Radx parser
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
from typing import List | ||
from xml.etree import ElementTree as ET | ||
|
||
from dug import utils as utils | ||
from ._base import DugElement, FileParser, Indexable, InputFile | ||
|
||
logger = logging.getLogger('dug') | ||
|
||
|
||
class RADxParser(FileParser): | ||
|
||
def __call__(self, input_file: InputFile) -> List[Indexable]: | ||
tree = ET.parse(input_file, ET.XMLParser(encoding='utf-8')) | ||
root = tree.getroot() | ||
study_id = root.attrib['id'] | ||
# If still None, raise an error message | ||
study_name = root.attrib['study_name'] | ||
elements = [] | ||
for variable in root.iter('variable'): | ||
desc = variable.find('description').text if variable.find('description') is not None else '' | ||
desc = desc or '' | ||
elem = DugElement(elem_id=f"{variable.attrib['id']}", | ||
name=variable.find('name').text, | ||
desc=desc, | ||
elem_type=root.attrib['module'], | ||
collection_id=f"{study_id}", | ||
collection_name=study_name) | ||
|
||
# Create DBGaP links as study/variable actions | ||
elem.collection_action = utils.get_dbgap_study_link(study_id=elem.collection_id) | ||
logger.debug(elem) | ||
elements.append(elem) | ||
|
||
# You don't actually create any concepts | ||
return elements |