From 4e790f08000825931cb5edec1738d2b7d073f73e Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 11 Nov 2021 15:45:22 +0530 Subject: Reimplement __items_with_values using list comprehension. * gn3/computations/correlations2.py: Remove import of reduce from functools. (__items_with_values): Reimplement using list comprehension. --- gn3/computations/correlations2.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'gn3/computations') diff --git a/gn3/computations/correlations2.py b/gn3/computations/correlations2.py index 93db3fa..69921b1 100644 --- a/gn3/computations/correlations2.py +++ b/gn3/computations/correlations2.py @@ -7,24 +7,13 @@ compute_correlation: TODO: Describe what the function does...""" from math import sqrt -from functools import reduce ## From GN1: mostly for clustering and heatmap generation def __items_with_values(dbdata, userdata): """Retains only corresponding items in the data items that are not `None` values. This should probably be renamed to something sensible""" - def both_not_none(item1, item2): - """Check that both items are not the value `None`.""" - if (item1 is not None) and (item2 is not None): - return (item1, item2) - return None - def split_lists(accumulator, item): - """Separate the 'x' and 'y' items.""" - return [accumulator[0] + [item[0]], accumulator[1] + [item[1]]] - return reduce( - split_lists, - filter(lambda x: x is not None, map(both_not_none, dbdata, userdata)), - [[], []]) + filtered = [x for x in zip(dbdata, userdata) if x[0] is not None and x[1] is not None] + return tuple(zip(*filtered)) if filtered else ([], []) def compute_correlation(dbdata, userdata): """Compute some form of correlation. -- cgit v1.2.3