about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-02-20 05:15:00 +0300
committerFrederick Muriuki Muriithi2024-02-20 05:15:00 +0300
commit8e692b0c372db3999dfc3989f361676c579fb9cd (patch)
treefb27e07761b00bb36a19988c539d58e99d672cab
parentaefa19252cf0dfe1cc02b2f87a4f66dc807f4f74 (diff)
downloadgn-uploader-8e692b0c372db3999dfc3989f361676c579fb9cd.tar.gz
Stand-alone function to read control file
Add a function that, given the path to the zip file, will read the
control data. It creates its own context manager.
-rw-r--r--r_qtl/r_qtl2.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index 96776b7..93b8c8e 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -318,3 +318,19 @@ def missing_value_codes_to_none(value: str,
 def replace_genotype_codes(value: str, genocodes: dict):
     """Convert genotype codes into values specified in control file."""
     return genocodes.get(value, value)
+
+def read_control_file(zipfilepath: Union[str, Path]) -> dict:
+    """Read control data."""
+    with ZipFile(str(zipfilepath), "r") as zfile:
+        # move `control_data` code here and replace existing function.
+        cdata = control_data(zfile)
+        return {
+            **cdata,
+            **{
+                ftype: ([cdata[ftype]]
+                        if isinstance(cdata[ftype], str)
+                        else cdata[ftype])
+                for ftype in FILE_TYPES
+                if bool(cdata.get(ftype))
+            }
+        }