From 1a46021a37ca23fe9893fd4ac9ac9c1d4066884b Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 14 Dec 2021 04:37:15 +0300 Subject: Remove any items with less than 3 samples Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * pingouin raises an exception whenever one attempts to use it to compute the partial correlation with data that has less than 3 samples. --- gn3/computations/partial_correlations.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index 87d0201..fbff4df 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -306,6 +306,9 @@ def compute_partial( prim for targ, prim in zip(targ_vals, primary_vals) if targ is not None] + if len(primary) < 3: + return None + def __remove_controls_for_target_nones(cont_targ): return tuple(cont for cont,targ in cont_targ if targ is not None) @@ -338,8 +341,10 @@ def compute_partial( zero_order_corr["r"][0], zero_order_corr["p-val"][0]) return tuple( - __compute_trait_info__(target) + result for result in ( + __compute_trait_info__(target) for target in zip(target_vals, target_names)) + if result is not None) def partial_correlations_normal(# pylint: disable=R0913 primary_vals, control_vals, input_trait_gene_id, trait_database, -- cgit v1.2.3