aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-07-22 12:32:30 +0300
committerMuriithi Frederick Muriuki2021-07-22 12:32:30 +0300
commit47eefa0ccedffcaf6f93d3f55add41b4bdcc60c9 (patch)
tree20406ace1e6fbe436c049cfd325ece14755b9148
parent89a4a7dad91be22fe617e0b42cffa1b08395eb82 (diff)
downloadgenenetwork3-47eefa0ccedffcaf6f93d3f55add41b4bdcc60c9.tar.gz
Check the child lengths are same as length of parent
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Check that the child lists/tuples are the same length as the parent list/tuple. If any of the children is not the same length as the parent, throw and exception.
-rw-r--r--gn3/computations/slink.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py
index dc71815..5288908 100644
--- a/gn3/computations/slink.py
+++ b/gn3/computations/slink.py
@@ -19,6 +19,12 @@ def raise_valueerror_if_lists_empty(lists):
if (empty(lists)) or not all(map(lambda x: not empty(x), lists)):
raise ValueError("List/Tuple should NOT be empty!")
+def raise_lengtherror_if_child_lists_are_not_same_as_parent(lists):
+ def len_is_same_as_parent(lst):
+ return len(lst) == len(lists)
+ if not all(map(len_is_same_as_parent, lists)):
+ raise LengthError("All children lists should be same length as the parent.")
+
def nearest(lists, i, j):
"""Computes some form of distance.
This is 'copied' over from genenetwork1, from https://github.com/genenetwork/genenetwork1/blob/master/web/webqtl/heatmap/slink.py#L42-L64.
@@ -28,5 +34,6 @@ This description should be updated once the form/type of 'distance' identified."
#### Guard Functions: Should we do this a different way? ####
raise_valueerror_if_data_is_not_lists_or_tuples(lists)
raise_valueerror_if_lists_empty(lists)
+ raise_lengtherror_if_child_lists_are_not_same_as_parent(lists)
#### END: Guard Functions ####
return None