diff options
author | Muriithi Frederick Muriuki | 2021-07-22 15:01:27 +0300 |
---|---|---|
committer | Muriithi Frederick Muriuki | 2021-07-22 15:01:27 +0300 |
commit | 5751aa26829fd01b222b658e63c0a6c2214d4c71 (patch) | |
tree | 88c40230c6461c39d91f11c10b808b627417cb6c /gn3/computations | |
parent | 598d17fd415e905ede6ad4457a3283dcf2ef350a (diff) | |
download | genenetwork3-5751aa26829fd01b222b658e63c0a6c2214d4c71.tar.gz |
Test for shortest distance between members in a list and coordinate
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi
* gn3/computations/slink.py: add code to pass new test
* tests/unit/computations/test_slink.py: new test
Given a list of members in a group, and a coordinate for a member in the
same group, find the distance of the closest member from the given
coordinate in the group.
Diffstat (limited to 'gn3/computations')
-rw-r--r-- | gn3/computations/slink.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/gn3/computations/slink.py b/gn3/computations/slink.py index 7b4016a..3156b31 100644 --- a/gn3/computations/slink.py +++ b/gn3/computations/slink.py @@ -70,6 +70,9 @@ This description should be updated once the form/type of 'distance' identified." raise_mirrorerror_of_distances_one_way_are_not_same_other_way(lists) raise_valueerror_on_negative_distances(lists) #### END: Guard Functions #### - return None 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]): + return min(map(lambda j_new: nearest(lists, i, j_new), j)) + elif type(j) == int and (type(i) in [list, tuple]): + return min(map(lambda i_new: nearest(lists, i_new, j), i)) |