From 8278532da6c9b19a8ff8ac7b43f799443a8b05b6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 13 Dec 2021 16:00:13 +0300 Subject: Fix the removal of controls for corresponding Nones in targets Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * Fix the code, so that it removes all control values, whose corresponding target values are None, without throwing an error. --- gn3/computations/partial_correlations.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'gn3/computations') diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index d05011a..7704b02 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -305,11 +305,16 @@ def compute_partial( prim for targ, prim in zip(targ_vals, primary_vals) if targ is not None] + def __remove_controls_for_target_nones(cont_targ): + return tuple(cont for cont,targ in cont_targ if targ is not None) + + conts_targs = tuple(tuple( + zip(control, targ_vals)) for control in control_vals) datafrm = build_data_frame( primary, - tuple(targ for targ in targ_vals if targ is not None), - tuple(cont for i, cont in enumerate(control_vals) - if target[0][i] is not None)) + [targ for targ in targ_vals if targ is not None], + [__remove_controls_for_target_nones(cont_targ) + for cont_targ in conts_targs]) covariates = "z" if datafrm.shape[1] == 3 else [ col for col in datafrm.columns if col not in ("x", "y")] ppc = pingouin.partial_corr( -- cgit v1.2.3