aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexanderkabui2020-12-12 23:09:04 +0300
committerBonfaceKilz2021-01-06 01:26:38 +0300
commit0adae692f2f0ce509b32d6654438213deb3da89b (patch)
tree4343ee2c7f1792df140795a4876145ce65ea92cc
parente80e793455d2fc6b51dbe95414a3ba8e72652a83 (diff)
downloadgenenetwork2-0adae692f2f0ce509b32d6654438213deb3da89b.tar.gz
add test for calculating correlation results
-rw-r--r--wqflask/tests/unit/wqflask/api/test_correlation.py44
1 files changed, 31 insertions, 13 deletions
diff --git a/wqflask/tests/unit/wqflask/api/test_correlation.py b/wqflask/tests/unit/wqflask/api/test_correlation.py
index 077f7fa9..11c7d82b 100644
--- a/wqflask/tests/unit/wqflask/api/test_correlation.py
+++ b/wqflask/tests/unit/wqflask/api/test_correlation.py
@@ -1,10 +1,12 @@
import unittest
from unittest import mock
from wqflask import app
+from collections import OrderedDict
from wqflask.api.correlation import init_corr_params
from wqflask.api.correlation import convert_to_mouse_gene_id
from wqflask.api.correlation import do_literature_correlation_for_all_traits
from wqflask.api.correlation import get_sample_r_and_p_values
+from wqflask.api.correlation import calculate_results
class AttributeSetter:
@@ -12,6 +14,17 @@ class AttributeSetter:
for k, v in obj.items():
setattr(self, k, v)
+class MockDataset(AttributeSetter):
+ def get_trait_data(self):
+ return None
+ def retrieve_genes(self,id=None):
+ return {
+ "TT-1":"GH-1",
+ "TT-2":"GH-2",
+ "TT-3":"GH-3"
+
+ }
+
class TestCorrelations(unittest.TestCase):
def setUp(self):
@@ -101,19 +114,24 @@ class TestCorrelations(unittest.TestCase):
self.assertEqual(results_spearmanr,[-0.11595420713048969, 0.826848213385815, 6])
self.assertEqual(results_num_overlap,None)
- def test_calculate_results(self):
- corr_params={
- "type":"pearson"
- }
- trait_data={
- "T1":3.4,
- "T2":6.2,
- "T3":4.1,
- "T4":3.4,
- "T5":1.2,
- "T6":5.6
- }
- target_vals=[3.4, 6.2, 4.1,3.4,1.2,5.6]
+ @mock.patch("wqflask.api.correlation.do_literature_correlation_for_all_traits")
+ def test_calculate_results(self,literature_correlation):
+
+ literature_correlation.return_value={'TT-1': ['GH-1', 0], 'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1]}
+
+
+
+ this_dataset=MockDataset({"group":AttributeSetter({"species":"rat"})})
+ target_dataset=MockDataset({"group":AttributeSetter({"species":"rat"})})
+ this_trait=AttributeSetter({"geneid":"GH-1"})
+ corr_params={"type":"literature"}
+ sorted_results=calculate_results(this_trait=this_trait,this_dataset=this_dataset,target_dataset=target_dataset,corr_params=corr_params)
+ expected_results={'TT-2': ['GH-2', 3], 'TT-3': ['GH-3', 1], 'TT-1': ['GH-1', 0]}
+
+ self.assertTrue(isinstance(sorted_results,OrderedDict))
+ self.assertEqual(type(sorted_results),OrderedDict)
+
+