From a826daa77fa56afddb4920ae7ff9dec334f6e646 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Thu, 22 Jul 2021 12:34:51 +0300 Subject: Check that child distance from itself is zero Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/slink.py: Check that a child's distance from itself is zero. If not, throw an exception. The children lists are a list of distances of "something" from other "somethings". There is still some need to establish what those "somethings" are, so that the test names can reflect the ideas that are actually being tested for. * tests/unit/computations/test_slink.py: Change the name of the test so that it more closely corresponds to the business logic it is actually testing, and not the mechanics of testing the idea. --- gn3/computations/slink.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gn3/computations/slink.py') diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py index 5288908..f3a6951 100644 --- a/gn3/computations/slink.py +++ b/gn3/computations/slink.py @@ -25,6 +25,16 @@ def raise_lengtherror_if_child_lists_are_not_same_as_parent(lists): if not all(map(len_is_same_as_parent, lists)): raise LengthError("All children lists should be same length as the parent.") +def raise_valueerror_if_child_list_distance_from_itself_is_not_zero(lists): + def get_child_distance(child): + idx = lists.index(child) + return lists[idx][idx] + def distance_is_zero(dist): + return dist == 0 + children_distances = map(get_child_distance, lists) + if not all(map(distance_is_zero, children_distances)): + raise ValueError("Distance of each child list/tuple from itself should be zero!") + 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. @@ -35,5 +45,6 @@ This description should be updated once the form/type of 'distance' identified." 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) + raise_valueerror_if_child_list_distance_from_itself_is_not_zero(lists) #### END: Guard Functions #### return None -- cgit v1.2.3