aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-23 09:03:12 +0300
committerMuriithi Frederick Muriuki2021-07-23 09:03:12 +0300
commit7e8a3347cc04433c55a5f6a3f528e9163fee6543 (patch)
treeaa4c874e9e0ff102a82a502e95c52cccb7ace020 /gn3/computations
parent5493c890c27373530a0212361d4632df613d8afd (diff)
downloadgenenetwork3-7e8a3347cc04433c55a5f6a3f528e9163fee6543.tar.gz
Iterate through all valid pairs
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/slink.py: Fix the iteration construct. Given two lists of member coordinates, such as [0, 1] and [3, 5], the initial code would iterate over the pairs [0, 3] and [1, 5]. This commit fixes the iteration constructs such that the new code iterates over the pairs [0, 3], [0, 5], [1, 3] and [1, 5].
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/slink.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index 7ee9b5e..59d0975 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -115,9 +115,9 @@ def nearest(lists, i, j):
elif type(j) == int and __is_list_or_tuple(i):
return min(map(lambda i_new: nearest(lists, i_new, j), i[:-1]))
elif __is_list_or_tuple(i) and __is_list_or_tuple(j):
- partial_i = map(lambda x:partial(nearest, lists, x), i[:-1])
- ns = list(map(lambda f, x: f(x), partial_i, j[:1]))
- return min(ns)
+ coordinate_pairs = __flatten_list_of_lists(
+ [[(itemi, itemj) for itemj in j[:-1]] for itemi in i[:-1]])
+ return min(map(lambda x: nearest(lists, x[0], x[1]), coordinate_pairs))
else:
raise ValueError("member values (i or j) should be lists/tuples of integers or integers")