aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/db/test_correlation.py
blob: 5afe55f89aedaa810b8d253f359d34b8e4a89a3c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Tests for the gn3.db.correlations module
"""

from unittest import TestCase

import pytest

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

    @pytest.mark.unit_test
    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))

    @pytest.mark.unit_test
    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))