diff options
Diffstat (limited to 'r_qtl/r_qtl2.py')
-rw-r--r-- | r_qtl/r_qtl2.py | 31 |
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, ...], |