aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-12-13 16:00:13 +0300
committerFrederick Muriuki Muriithi2021-12-13 16:04:38 +0300
commit8278532da6c9b19a8ff8ac7b43f799443a8b05b6 (patch)
tree856bc1d701f647c7ba5f1c203be2e7751005dff5 /gn3/computations
parent397316b5cd5c3572962bd53a331f5d23429d8ddc (diff)
downloadgenenetwork3-8278532da6c9b19a8ff8ac7b43f799443a8b05b6.tar.gz
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.
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/partial_correlations.py11
1 files changed, 8 insertions, 3 deletions
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(