From 557e482c88ba3d44ae7d278b7222f37fa043b4d0 Mon Sep 17 00:00:00 2001 From: Muriithi Frederick Muriuki Date: Fri, 27 Aug 2021 15:47:52 +0300 Subject: Rework strains and trait values retrieval Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Rework the strains and values retrieval function to more closely correspond to the working of the original code in GN1 --- gn3/computations/heatmap.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'gn3') diff --git a/gn3/computations/heatmap.py b/gn3/computations/heatmap.py index c9c2b8a..da13ceb 100644 --- a/gn3/computations/heatmap.py +++ b/gn3/computations/heatmap.py @@ -204,21 +204,28 @@ def compute_heatmap_order( return __order_maker(neworder, slink_data) -def retrieve_strains_and_values(strainlist, trait_data): +def retrieve_strains_and_values(orders, strainlist, traits_data_list): """ Get the strains and their corresponding values from `strainlist` and - `trait_data`. + `traits_data_list`. This migrates the code in https://github.com/genenetwork/genenetwork1/blob/master/web/webqtl/heatmap/Heatmap.py#L215-221 """ - def __strains_and_values(acc, i): - if trait_data[i] is None: - return acc - if len(acc) == 0: - return ((strainlist[i], ), (trait_data[i], )) - _strains = acc[0] - _vals = acc[1] - return (_strains + (strainlist[i], ), _vals + (trait_data[i], )) - return reduce( - __strains_and_values, range(len(strainlist)), (tuple(), tuple())) + # This feels nasty! There's a lot of mutation of values here, that might + # indicate something untoward in the design of this function and its + # dependents ==> Review + strains = [] + values = [] + rets = [] + for order in orders: + temp_val = traits_data_list[order[1]] + for i in range(len(strainlist)): + if temp_val[i] != None: + strains.append(strainlist[i]) + values.append(temp_val[i]) + rets.append([order, strains[:], values[:]]) + strains = [] + values = [] + + return rets -- cgit v1.2.3