-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat - add HiSeq RunParameters file parser (#2653)(MINOR)
Closes #2651. Creates a child class of `RunParameters` that reads files from HiSeq sequencers, both 2500 and X. This is with the purpose of knowing the reads and index reads of the sequencing. ### Added - Class `RunParametersHiSeq`, implementing abstract methods from parent. - Constants to parse the elements from the XML file - XMLError exception - Test for new class ### Changed - Moved and renamed function `node_not_found` in `RunParameters` class to `cg/io/xml.py:validate_node_exists` - Replaced RunParametersError exception for XMLError in the validation of the nodes. ### Fixed - Removed unused sample sheets in fixtures
- Loading branch information
Showing
29 changed files
with
1,133 additions
and
319 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
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
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
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 |
---|---|---|
@@ -1,19 +1,40 @@ | ||
"""Module for reading and writing xml files.""" | ||
|
||
import xml.etree.ElementTree as ET | ||
import logging | ||
from pathlib import Path | ||
from xml.etree.ElementTree import Element, ElementTree, parse | ||
|
||
from cg.constants import FileExtensions | ||
from cg.exc import XMLError | ||
from cg.io.validate_path import validate_file_suffix | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def read_xml(file_path: Path) -> ET.ElementTree: | ||
def read_xml(file_path: Path) -> ElementTree: | ||
"""Read content in a xml file to an ElementTree.""" | ||
validate_file_suffix(path_to_validate=file_path, target_suffix=FileExtensions.XML) | ||
tree = ET.parse(file_path) | ||
tree = parse(file_path) | ||
return tree | ||
|
||
|
||
def write_xml(tree: ET.ElementTree, file_path: Path) -> None: | ||
def write_xml(tree: ElementTree, file_path: Path) -> None: | ||
"""Write content to a xml file.""" | ||
tree.write(file_path, encoding="utf-8", xml_declaration=True) | ||
|
||
|
||
def validate_node_exists(node: Element | None, name: str) -> None: | ||
"""Validates if the given node is not None. | ||
Raises: | ||
XMLError: If the node is None | ||
""" | ||
if node is None: | ||
message = f"Could not find node with name {name} in XML tree" | ||
LOG.warning(message) | ||
raise XMLError(message) | ||
|
||
|
||
def get_tree_node(tree: ElementTree, node_name: str) -> Element: | ||
"""Return the node of a tree given its name if it exists.""" | ||
xml_node: Element = tree.find(node_name) | ||
validate_node_exists(node=xml_node, name=node_name) | ||
return xml_node |
Oops, something went wrong.