aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-16 14:04:07 +0300
committerFrederick Muriuki Muriithi2024-02-16 16:48:39 +0300
commit2931d48a5fd982f83c084c7db723bef6af34b21d (patch)
tree1c234f9c8e248ba1e6148cbd78579e434ad06186
parent4406c59eb37a28a7e499443427dc05ef46dc9da9 (diff)
downloadgn-uploader-2931d48a5fd982f83c084c7db723bef6af34b21d.tar.gz
Read raw text data from a file in the zip bundle
-rw-r--r--r_qtl/r_qtl2.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index 0241458..93ce56c 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -2,6 +2,7 @@
import io
import csv
import json
+from pathlib import Path
from zipfile import ZipFile
from functools import reduce, partial
from typing import Iterator, Iterable, Callable, Optional
@@ -292,3 +293,12 @@ def genotype_data(zfile: ZipFile):
"""Convenience function to genotype data from R/qtl2 bundle."""
cdata = control_data(zfile)
return file_data(zfile, "geno", cdata, *make_process_data_geno(cdata))
+
+def raw_file_data(zipfilepath: Union[str, Path],
+ memberfilename: str) -> Iterator[str]:
+ """Read the raw text from a file in the R/qtl2 bundle."""
+ with (ZipFile(str(zipfilepath), "r") as zfile,
+ zfile.open(memberfilename) as innerfile):
+ wrappedfile = io.TextIOWrapper(innerfile)
+ for line in wrappedfile:
+ yield line.strip()