From 6f55abf57cef25d8c438e6bdf2d2c621498d6b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draic=20Corcoran?= Date: Fri, 19 Apr 2024 21:05:21 +0200 Subject: [PATCH] fix: handle col creation when no trios present --- scripts/extract_samples_info.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/extract_samples_info.py b/scripts/extract_samples_info.py index ac16b8a..0376093 100644 --- a/scripts/extract_samples_info.py +++ b/scripts/extract_samples_info.py @@ -94,9 +94,13 @@ def main(samples_file, units_file, order_file, replacement_file): samples["sex"] = samples["sex"].apply(translate_sex) # split trio col - samples[["trioid", "trio_member"]] = samples.trio.str.split( - "-", expand=True) - + try: + samples[["trioid", "trio_member"]] = samples.trio.str.split( + "-", expand=True) + except ValueError: # manually create cols with NAs when no trio present + samples["trioid"] = ["NA"] * samples.shape[0] + samples["trio_member"] = ["NA"] * samples.shape[0] + # get the trio member in english samples["trio_member"] = samples.apply( lambda x: translate_trio_member(x.trio_member, x.sex), axis=1)