diff options
author | Arun Isaac | 2021-11-11 15:45:22 +0530 |
---|---|---|
committer | BonfaceKilz | 2021-11-11 20:49:30 +0300 |
commit | 4e790f08000825931cb5edec1738d2b7d073f73e (patch) | |
tree | 0ec609762f77c6768c730a567ee2712ab6a4f59b | |
parent | fb92e75b8e9984fbbf9b26f87b53ea516a8819da (diff) | |
download | genenetwork3-4e790f08000825931cb5edec1738d2b7d073f73e.tar.gz |
Reimplement __items_with_values using list comprehension.
* gn3/computations/correlations2.py: Remove import of reduce from functools.
(__items_with_values): Reimplement using list comprehension.
-rw-r--r-- | gn3/computations/correlations2.py | 15 |
1 files changed, 2 insertions, 13 deletions
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. |