about summary refs log tree commit diff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/computations/test_partial_correlations.py16
-rw-r--r--tests/unit/db/test_correlation.py96
2 files changed, 105 insertions, 7 deletions
diff --git a/tests/unit/computations/test_partial_correlations.py b/tests/unit/computations/test_partial_correlations.py
index 3e1b6e1..3690ca4 100644
--- a/tests/unit/computations/test_partial_correlations.py
+++ b/tests/unit/computations/test_partial_correlations.py
@@ -193,7 +193,7 @@ class TestPartialCorrelations(TestCase):
 
         Given:
             - the name of a primary trait
-            - the value of a primary trait
+            - a sequence of values for the primary trait
             - a sequence of names of control traits
             - a sequence of values of control traits
         When:
@@ -204,12 +204,14 @@ class TestPartialCorrelations(TestCase):
               decimal places are considered
         """
         for primn, primv, contn, contv, expected in (
-                ("pt", 12.98395, ("ct0", "ct1", "ct2"),
-                 (0.1234, 2.3456, 3.4567), tuple()),
-                ("pt", 12.98395, ("ct0", "ct1", "ct2"),
-                 (12.98354, 2.3456, 3.4567), ("pt", "ct0")),
-                ("pt", 12.98395, ("ct0", "ct1", "ct2", "ct3"),
-                 (0.1234, 2.3456, 0.1233, 4.5678), ("ct0", "ct2"))
+                ("pt", (12.98395,), ("ct0", "ct1", "ct2"),
+                 ((0.1234, 2.3456, 3.4567),), tuple()),
+                ("pt", (12.98395, 2.3456, 3.4567), ("ct0", "ct1", "ct2"),
+                 ((12.98354, 2.3456, 3.4567), (64.2334, 6.3256, 64.2364),
+                  (4.2374, 67.2345, 7.48234)), ("pt", "ct0")),
+                ("pt", (12.98395, 75.52382), ("ct0", "ct1", "ct2", "ct3"),
+                 ((0.1234, 2.3456), (0.3621, 6543.572), (0.1234, 2.3456),
+                  (0.1233, 4.5678)), ("ct0", "ct2"))
         ):
             with self.subTest(
                     primary_name=primn, primary_value=primv,
diff --git a/tests/unit/db/test_correlation.py b/tests/unit/db/test_correlation.py
new file mode 100644
index 0000000..3f940b2
--- /dev/null
+++ b/tests/unit/db/test_correlation.py
@@ -0,0 +1,96 @@
+"""
+Tests for the gn3.db.correlations module
+"""
+
+from unittest import TestCase
+
+from gn3.db.correlations import (
+    build_query_sgo_lit_corr,
+    build_query_tissue_corr)
+
+class TestCorrelation(TestCase):
+    """Test cases for correlation data fetching functions"""
+    maxDiff = None
+
+    def test_build_query_sgo_lit_corr(self):
+        """
+        Test that the literature correlation query is built correctly.
+        """
+        self.assertEqual(
+            build_query_sgo_lit_corr(
+                "Probeset",
+                "temp_table_xy45i7wd",
+                "T1.value, T2.value, T3.value",
+                (("LEFT JOIN ProbesetData AS T1 "
+                  "ON T1.Id = ProbesetXRef.DataId "
+                  "AND T1.StrainId=%(T1_sample_id)s"),
+                 (
+                     "LEFT JOIN ProbesetData AS T2 "
+                     "ON T2.Id = ProbesetXRef.DataId "
+                     "AND T2.StrainId=%(T2_sample_id)s"),
+                 (
+                     "LEFT JOIN ProbesetData AS T3 "
+                     "ON T3.Id = ProbesetXRef.DataId "
+                     "AND T3.StrainId=%(T3_sample_id)s"))),
+            (("SELECT Probeset.Name, temp_table_xy45i7wd.value, "
+              "T1.value, T2.value, T3.value "
+              "FROM (Probeset, ProbesetXRef, ProbesetFreeze) "
+              "LEFT JOIN temp_table_xy45i7wd ON temp_table_xy45i7wd.GeneId2=ProbeSet.GeneId "
+              "LEFT JOIN ProbesetData AS T1 "
+              "ON T1.Id = ProbesetXRef.DataId "
+              "AND T1.StrainId=%(T1_sample_id)s "
+              "LEFT JOIN ProbesetData AS T2 "
+              "ON T2.Id = ProbesetXRef.DataId "
+              "AND T2.StrainId=%(T2_sample_id)s "
+              "LEFT JOIN ProbesetData AS T3 "
+              "ON T3.Id = ProbesetXRef.DataId "
+              "AND T3.StrainId=%(T3_sample_id)s "
+              "WHERE ProbeSet.GeneId IS NOT NULL "
+              "AND temp_table_xy45i7wd.value IS NOT NULL "
+              "AND ProbesetXRef.ProbesetFreezeId = ProbesetFreeze.Id "
+              "AND ProbesetFreeze.Name = %(db_name)s "
+              "AND Probeset.Id = ProbesetXRef.ProbesetId "
+              "ORDER BY Probeset.Id"),
+             2))
+
+    def test_build_query_tissue_corr(self):
+        """
+        Test that the tissue correlation query is built correctly.
+        """
+        self.assertEqual(
+            build_query_tissue_corr(
+                "Probeset",
+                "temp_table_xy45i7wd",
+                "T1.value, T2.value, T3.value",
+                (("LEFT JOIN ProbesetData AS T1 "
+                  "ON T1.Id = ProbesetXRef.DataId "
+                  "AND T1.StrainId=%(T1_sample_id)s"),
+                 (
+                     "LEFT JOIN ProbesetData AS T2 "
+                     "ON T2.Id = ProbesetXRef.DataId "
+                     "AND T2.StrainId=%(T2_sample_id)s"),
+                 (
+                     "LEFT JOIN ProbesetData AS T3 "
+                     "ON T3.Id = ProbesetXRef.DataId "
+                     "AND T3.StrainId=%(T3_sample_id)s"))),
+            (("SELECT Probeset.Name, temp_table_xy45i7wd.Correlation, "
+              "temp_table_xy45i7wd.PValue, "
+              "T1.value, T2.value, T3.value "
+              "FROM (Probeset, ProbesetXRef, ProbesetFreeze) "
+              "LEFT JOIN temp_table_xy45i7wd ON temp_table_xy45i7wd.Symbol=ProbeSet.Symbol "
+              "LEFT JOIN ProbesetData AS T1 "
+              "ON T1.Id = ProbesetXRef.DataId "
+              "AND T1.StrainId=%(T1_sample_id)s "
+              "LEFT JOIN ProbesetData AS T2 "
+              "ON T2.Id = ProbesetXRef.DataId "
+              "AND T2.StrainId=%(T2_sample_id)s "
+              "LEFT JOIN ProbesetData AS T3 "
+              "ON T3.Id = ProbesetXRef.DataId "
+              "AND T3.StrainId=%(T3_sample_id)s "
+              "WHERE ProbeSet.Symbol IS NOT NULL "
+              "AND temp_table_xy45i7wd.Correlation IS NOT NULL "
+              "AND ProbesetXRef.ProbesetFreezeId = ProbesetFreeze.Id "
+              "AND ProbesetFreeze.Name = %(db_name)s "
+              "AND Probeset.Id = ProbesetXRef.ProbesetId "
+              "ORDER BY Probeset.Id"),
+             3))