aboutsummaryrefslogtreecommitdiff
path: root/gn3/data_helpers.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-01 07:09:26 +0300
committerBonfaceKilz2021-11-04 12:45:57 +0300
commitff23701bbfd90799f04fdf21c482f113bb408e34 (patch)
tree333f0def96018bfa3a315f22d24cea267a9da013 /gn3/data_helpers.py
parent4a6be7e1b6514f3c7db8c672970b27e27ecde305 (diff)
downloadgenenetwork3-ff23701bbfd90799f04fdf21c482f113bb408e34.tar.gz
Parse single line from CSV file
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/data_helpers.py: New function (parse_csv_line) * tests/unit/test_data_helpers.py: Add tests for new function (parse_csv_line) Add a function to parse a single line from a CSV file.
Diffstat (limited to 'gn3/data_helpers.py')
-rw-r--r--gn3/data_helpers.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/gn3/data_helpers.py b/gn3/data_helpers.py
index f0d971e..741a885 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,14 @@ 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))