aboutsummaryrefslogtreecommitdiff
path: root/gn3/computations
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-08-27 15:47:52 +0300
committerMuriithi Frederick Muriuki2021-08-27 15:47:52 +0300
commit557e482c88ba3d44ae7d278b7222f37fa043b4d0 (patch)
tree2869756be00c5adff8b452feb589611b61220649 /gn3/computations
parentbe4445e91f4a752ef7bbb99ed7d813c5fc88f467 (diff)
downloadgenenetwork3-557e482c88ba3d44ae7d278b7222f37fa043b4d0.tar.gz
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
Diffstat (limited to 'gn3/computations')
-rw-r--r--gn3/computations/heatmap.py31
1 files changed, 19 insertions, 12 deletions
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