From 9eab14f7f6c40c401c29d11d69ac54303415ab87 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 4 Jan 2024 11:50:04 +0300 Subject: Process sex and cross information data in "covar" files. --- r_qtl/r_qtl2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'r_qtl') 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, ...], -- cgit v1.2.3