aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-23 09:01:12 +0300
committerMuriithi Frederick Muriuki2021-07-23 09:01:12 +0300
commit5493c890c27373530a0212361d4632df613d8afd (patch)
tree6222723c157fd83da80fdf5ed867a5709cef0073 /gn3
parenteb5bf7fbd66abfc798bc272a4aefcb972f61c55f (diff)
downloadgenenetwork3-5493c890c27373530a0212361d4632df613d8afd.tar.gz
Extract function to flatten list of lists
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/slink.py: Extract the `__flatten_list_of_lists` function since it is used in more than one place.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/computations/slink.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index 0c74789..7ee9b5e 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -64,10 +64,13 @@ raise an exception."""
def zero_or_positive(val):
return val >= 0;
# flatten lists
- flattened = [distance for child in lists for distance in child]
+ flattened = __flatten_list_of_lists(lists)
if not all(map(zero_or_positive, flattened)):
raise ValueError("Distances should be positive.")
+def __flatten_list_of_lists(parent):
+ return [item for child in parent for item in child]
+
def nearest(lists, i, j):
"""
Computes shortest distance between member(s) in `i` and member(s) in `j`.