aboutsummaryrefslogtreecommitdiff
path: root/gn3/data_helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/data_helpers.py')
-rw-r--r--gn3/data_helpers.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/gn3/data_helpers.py b/gn3/data_helpers.py
index f0d971e..d3f942b 100644
--- a/gn3/data_helpers.py
+++ b/gn3/data_helpers.py
@@ -5,7 +5,7 @@ data structures.
from math import ceil
from functools import reduce
-from typing import Any, Tuple, Sequence
+from typing import Any, Tuple, Sequence, Optional
def partition_all(num: int, items: Sequence[Any]) -> Tuple[Tuple[Any, ...], ...]:
"""
@@ -23,3 +23,15 @@ def partition_all(num: int, items: Sequence[Any]) -> Tuple[Tuple[Any, ...], ...]
tuple(items[start:stop]) for start, stop # type: ignore[has-type]
in reduce(
__compute_start_stop__, iterations, tuple())])
+
+def parse_csv_line(
+ line: str, delimiter: str = ",",
+ quoting: Optional[str] = '"') -> Tuple[str, ...]:
+ """
+ Parses a line from a CSV file into a tuple of strings.
+
+ This is a migration of the `web.webqtl.utility.webqtlUtil.readLineCSV`
+ function in GeneNetwork1.
+ """
+ return tuple(
+ col.strip("{} \t\n".format(quoting)) for col in line.split(delimiter))