aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations/slink.py
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-22 15:44:59 +0300
committerMuriithi Frederick Muriuki2021-07-22 15:46:41 +0300
commitf334b5ec5d51235d0daddc0c4fe700cb65bd825d (patch)
tree424d91f2d129cd73983c6452f4a30ba5ccc0af5c /gn3/computations/slink.py
parent5751aa26829fd01b222b658e63c0a6c2214d4c71 (diff)
downloadgenenetwork3-f334b5ec5d51235d0daddc0c4fe700cb65bd825d.tar.gz
Extract common `is_list_or_tuple' function
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Extract the common function `is_list_or_tuple' making it accessible to later parts of the code.
Diffstat (limited to 'gn3/computations/slink.py')
-rw-r--r--gn3/computations/slink.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index 3156b31..b15c058 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -4,10 +4,11 @@ class LengthError(BaseException):
class MirrorError(BaseException):
pass
+def is_list_or_tuple(item):
+ return type(item) in [list, tuple]
+
def raise_valueerror_if_data_is_not_lists_or_tuples(lists):
"""Check that `lists` is a list of lists: If not, raise an exception."""
- def is_list_or_tuple(item):
- return type(item) == type([]) or type(item) == type(tuple)
if (not is_list_or_tuple(lists)) or (not all(map(is_list_or_tuple, lists))):
raise ValueError("Expected list or tuple")
@@ -72,7 +73,7 @@ This description should be updated once the form/type of 'distance' identified."
#### END: Guard Functions ####
if type(i) == int and type(j) == int: # From member i to member j
return lists[i][j]
- elif type(i) == int and (type(j) in [list, tuple]):
+ elif type(i) == int and is_list_or_tuple(j):
return min(map(lambda j_new: nearest(lists, i, j_new), j))
- elif type(j) == int and (type(i) in [list, tuple]):
+ elif type(j) == int and is_list_or_tuple(i):
return min(map(lambda i_new: nearest(lists, i_new, j), i))