aboutsummaryrefslogtreecommitdiff
path: root/r_qtl
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-04 11:50:04 +0300
committerFrederick Muriuki Muriithi2024-01-04 11:50:04 +0300
commit9eab14f7f6c40c401c29d11d69ac54303415ab87 (patch)
tree7f50a11edfec1c498f5a2b48b0d3f497c405c73f /r_qtl
parent9963d0c3318caa931061d4e9b8c9f129f8860cce (diff)
downloadgn-uploader-9eab14f7f6c40c401c29d11d69ac54303415ab87.tar.gz
Process sex and cross information data in "covar" files.
Diffstat (limited to 'r_qtl')
-rw-r--r--r_qtl/r_qtl2.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/r_qtl/r_qtl2.py b/r_qtl/r_qtl2.py
index 26e8c76..682542b 100644
--- a/r_qtl/r_qtl2.py
+++ b/r_qtl/r_qtl2.py
@@ -134,6 +134,37 @@ def make_process_data_geno(cdata) -> tuple[
for items in zip(ids, vals[1:]))
return (__non_transposed__, __transposed__)
+def make_process_data_covar(cdata) -> tuple[
+ Callable[[dict], dict],
+ Callable[[str, tuple[str, ...], tuple[str, ...]],
+ tuple[dict, ...]]]:
+ """Build functions to process sex and cross information in covar files."""
+ def replace_sex_code(val):
+ sex_info = cdata.get("sex", False)
+ if bool(sex_info):
+ return sex_info.get(val, val)
+ return val
+ def replace_cross_info(val):
+ cross_info = cdata.get("cross_info", False)
+ if bool(cross_info):
+ return cross_info.get(val, val)
+ return val
+ def non_transposed(row: dict) -> dict:
+ return {
+ key: thread_op(value, replace_sex_code, replace_cross_info)
+ for key,value in row.items()
+ }
+ def transposed(id_key: str,
+ ids: tuple[str, ...],
+ vals: tuple[str, ...]) -> tuple[dict, ...]:
+ return tuple(
+ dict(zip(
+ [id_key, vals[0]],
+ (thread_op(item, replace_sex_code, replace_cross_info)
+ for item in items)))
+ for items in zip(ids, vals[1:]))
+ return (non_transposed, transposed)
+
def __default_process_value_transposed__(
id_key: str,
ids: tuple[str, ...],