aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-10 04:44:53 +0300
committerFrederick Muriuki Muriithi2024-01-10 04:44:53 +0300
commit9322da0f79dfa4c3f9f899f5a861ce302ce21e9c (patch)
treead3ac4b8d5791219392eba77067c2c0ce71e25e1 /r_qtl
parent21078fecb698972062af3157a9a0f6e84bb8fd0d (diff)
downloadgn-uploader-9322da0f79dfa4c3f9f899f5a861ce302ce21e9c.tar.gz
Make identifier column name explicit
Since the R/qtl2 bundle generator could name the identifier column anything, this commit converts the incoming identifier column name into something explicit that we know and can use.
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index d3a3805..d8231bb 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -48,12 +48,26 @@ def with_non_transposed(zfile: ZipFile,
def not_comment_line(line):
return not line.startswith(cdata.get("comment.char", "#"))
+ sep = cdata.get("sep", ",")
with zfile.open(cdata[member_key]) as innerfile:
- reader = csv.DictReader(
- filter(not_comment_line, io.TextIOWrapper(innerfile)),
- delimiter=cdata.get("sep", ","))
+ wrapped_file = io.TextIOWrapper(innerfile)
+ firstrow = tuple(
+ field.strip() for field in
+ next(filter(not_comment_line, wrapped_file)).strip().split(sep))
+ id_key = firstrow[0]
+ wrapped_file.seek(0)
+ reader = csv.DictReader(filter(not_comment_line, wrapped_file),
+ delimiter=sep)
for row in reader:
- yield process_value(row)
+ processed = process_value(row)
+ yield {
+ "id": processed[id_key],
+ **{
+ key: value
+ for key, value in processed.items()
+ if key != id_key
+ }
+ }
def __make_organise_by_id__(id_key):
"""Return a function to use with `reduce` to organise values by some
@@ -101,7 +115,13 @@ def with_transposed(zfile: ZipFile,
for line in batch
for row in process_value(id_key, headers, line)),
{}).items():
- yield row
+ yield {
+ "id": row[id_key],
+ **{
+ key: value
+ for key, value in row.items()
+ if key != id_key
+ }}
except StopIteration:
pass