aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/computations
diff options
context:
space:
mode:
authorMuriithi Frederick Muriuki2021-08-20 13:21:31 +0300
committerMuriithi Frederick Muriuki2021-08-20 13:21:31 +0300
commitded960e3d32e4d7ebe590deda27fc47175be73d9 (patch)
tree6f51ff61ac6fd20f3b5ca65805b9f81ec65efce1 /tests/unit/computations
parent41fc5136914548710529cbed7ef370dfb5b4a5c8 (diff)
downloadgenenetwork3-ded960e3d32e4d7ebe590deda27fc47175be73d9.tar.gz
Add tests for ordering and implement function
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * gn3/computations/heatmap.py: implement new ordering function * tests/unit/computations/test_heatmap.py: add new tests Implement the ordering function to migrate the setup of the `neworder` variable from GN1 to GN3. This migration is incomplete, since there is dependence on the return from the `web.webqtl.heatmap.Heatmap.draw` function in form of the `d_1` variable in some of the paths. The thing is, this `d_1` variable, and the `xoffset` variable seem to be used for laying out things on the drawn heatmap, and might actually end up not being needed for the new system using plotly, which has other ways of laying out things on the drawing. For now though, this commit "shims" the presence of these values until when the use of these variables is confirmed as present or absent in the new GN3 system.
Diffstat (limited to 'tests/unit/computations')
-rw-r--r--tests/unit/computations/test_heatmap.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/unit/computations/test_heatmap.py b/tests/unit/computations/test_heatmap.py
index 650cb45..14807bb 100644
--- a/tests/unit/computations/test_heatmap.py
+++ b/tests/unit/computations/test_heatmap.py
@@ -1,6 +1,9 @@
"""Module contains tests for gn3.computations.heatmap"""
from unittest import TestCase
-from gn3.computations.heatmap import cluster_traits, export_trait_data
+from gn3.computations.heatmap import (
+ cluster_traits,
+ export_trait_data,
+ compute_heatmap_order)
strainlist = ["B6cC3-1", "BXD1", "BXD12", "BXD16", "BXD19", "BXD2"]
trait_data = {
@@ -34,6 +37,16 @@ trait_data = {
"C57BL/6J": {"strain_name": "C57BL/6J", "value": 7.50606, "variance": None, "ndata": None},
"DBA/2J": {"strain_name": "DBA/2J", "value": 7.72588, "variance": None, "ndata": None}}}
+slinked = (
+ (((0, 2, 0.16381088984330505),
+ ((1, 7, 0.06024619831474998), 5, 0.19179284676938602),
+ 0.20337048635536847),
+ 9,
+ 0.23451785425383564),
+ ((3, (6, 8, 0.2140799896286565), 0.25879514152086425),
+ 4, 0.8968250491499363),
+ 0.9313185954797953)
+
class TestHeatmap(TestCase):
"""Class for testing heatmap computation functions"""
@@ -141,3 +154,13 @@ class TestHeatmap(TestCase):
0.9313185954797953, 1.1683723389247052, 0.23451785425383564,
1.7413442197913358, 0.33370067057028485, 1.3256191648260216,
0.0)))
+
+ def test_compute_heatmap_order(self):
+ """Test the orders."""
+ for xoff, expected in [
+ (40, ((60, 9), (60, 4))),
+ (30, ((50, 9), (50, 4))),
+ (20, ((40, 9), (40, 4)))]:
+ with self.subTest(xoffset=xoff):
+ self.assertEqual(
+ compute_heatmap_order(slinked, xoffset=xoff), expected)