From 2931d48a5fd982f83c084c7db723bef6af34b21d Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 16 Feb 2024 14:04:07 +0300 Subject: Read raw text data from a file in the zip bundle --- r_qtl/r_qtl2.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'r_qtl/r_qtl2.py') 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() -- cgit v1.2.3