aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_wgcna.py37
-rw-r--r--tests/unit/computations/test_wgcna.py62
2 files changed, 99 insertions, 0 deletions
diff --git a/tests/integration/test_wgcna.py b/tests/integration/test_wgcna.py
new file mode 100644
index 0000000..39dabb2
--- /dev/null
+++ b/tests/integration/test_wgcna.py
@@ -0,0 +1,37 @@
+"""integration tests for wgcna"""
+
+from unittest import TestCase
+from unittest import mock
+
+from gn3.app import create_app
+
+
+class WgcnaIntegrationTest(TestCase):
+ """class contains wgcna integration tests"""
+
+ def setUp(self):
+ self.app = create_app().test_client()
+
+ @mock.patch("gn3.api.wgcna.call_wgcna_script")
+ def test_wgcna_endpoint(self, mock_wgcna_api):
+ """test /api/wgcna/run_wgcna endpoint"""
+
+ wgcna_api_data = {
+ "eigengenes": ["1224_at", "121412_at", "32342342-at"],
+ "dendrogram_file_location": "/tmp/dend1.png"
+
+ }
+ mock_wgcna_api.return_value = wgcna_api_data
+
+ request_data = {
+
+ "trait_sample_data": [],
+
+
+ }
+
+ response = self.app.post("/api/wgcna/run_wgcna",
+ json=request_data, follow_redirects=True)
+
+ self.assertEqual(response.status_code, 401)
+ self.assertEqual(response.get_json(), wgcna_api_data)
diff --git a/tests/unit/computations/test_wgcna.py b/tests/unit/computations/test_wgcna.py
new file mode 100644
index 0000000..64f6c14
--- /dev/null
+++ b/tests/unit/computations/test_wgcna.py
@@ -0,0 +1,62 @@
+"""module contains python code for wgcna"""
+from unittest import skip
+from unittest import TestCase
+from unittest import mock
+
+from gn3.computations.wgcna import dump_wgcna_data
+from gn3.computations.wgcna import compose_wgcna_cmd
+from gn3.computations.wgcna import call_wgcna_script
+
+
+class TestWgcna(TestCase):
+ """test class for wgcna"""
+
+ @mock.patch("gn3.computations.wgcna.dump_wgcna_data")
+ def test_call_wgcna_script(self, mock_dump):
+ """call wgcna script"""
+
+ mock_dump.return_value = "/tmp/QmQPeNsJPyVWPFDVHb77w8G42Fvo15z4bG2X8D2GhfbSXc-test.json"
+
+ results = call_wgcna_script(
+ "/home/kabui/project/genenetwork3/scripts/wgcna_analysis.R", {})
+
+ self.assertEqual(results, "dsedf")
+
+ def test_compose_wgcna_cmd(self):
+ """test for composing wgcna cmd"""
+ wgcna_cmd = compose_wgcna_cmd(
+ "wgcna.r", "/tmp/wgcna.json")
+ self.assertEqual(
+ wgcna_cmd, "Rscript ./scripts/wgcna.r /tmp/wgcna.json")
+
+ @skip("to update tests")
+ def test_create_json_file(self):
+ """test for writing the data to a csv file"""
+ # # All the traits we have data for (should not contain duplicates)
+ # All the strains we have data for (contains duplicates)
+
+ trait_sample_data = {"1425642_at": {"129S1/SvImJ": 7.142,
+ "A/J": 7.31, "AKR/J": 7.49,
+ "B6D2F1": 6.899, "BALB/cByJ": 7.172,
+ "BALB/cJ": 7.396},
+ "1457784_at": {"129S1/SvImJ": 7.071, "A/J": 7.05,
+ "AKR/J": 7.313,
+ "B6D2F1": 6.999, "BALB/cByJ": 7.293,
+ "BALB/cJ": 7.117},
+ "1444351_at": {"129S1/SvImJ": 7.221, "A/J": 7.246,
+ "AKR/J": 7.754,
+ "B6D2F1": 6.866, "BALB/cByJ": 6.752,
+ "BALB/cJ": 7.269}
+
+ }
+
+ expected_input = {
+ "trait_sample_data": trait_sample_data,
+ "TOMtype": "unsigned",
+ "minModuleSize": 30
+ }
+
+ results = dump_wgcna_data(
+ expected_input)
+
+ self.assertEqual(results, {})