aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-11-01 07:09:26 +0300
committerFrederick Muriuki Muriithi2021-11-01 07:09:26 +0300
commit21c8c341956bb3c9cac427ab5b951976d70f4245 (patch)
tree7d4a67cc8639a2ae3bc06add0793a9f36fac98db /gn3
parent1a7b59a4d58c21759c265e5b5f413a533c1a2293 (diff)
downloadgenenetwork3-21c8c341956bb3c9cac427ab5b951976d70f4245.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')
-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))