aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-18 05:47:45 +0300
committerFrederick Muriuki Muriithi2021-10-18 05:59:54 +0300
commit27cca4c118cba6a5f8e8b03d152070f83a44a9e5 (patch)
tree3c24dc254f0efd29f2fc9f5f7f064e7f31e48f05 /tests
parent77099cac68e8f4792bf54d8e1f7ce6f315bedfa7 (diff)
downloadgenenetwork3-27cca4c118cba6a5f8e8b03d152070f83a44a9e5.tar.gz
Migrate `export_informative` function
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/partial_correlations.py: Implement a mostly, bug-compatible `export_informative` function as part of migrating the partial correlations feature over to GN3 from GN1 * tests/unit/test_partial_correlations.py: Implement tests to ensure the code work in a similar manner as that one in GN1.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_partial_correlations.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/unit/test_partial_correlations.py b/tests/unit/test_partial_correlations.py
new file mode 100644
index 0000000..6eea078
--- /dev/null
+++ b/tests/unit/test_partial_correlations.py
@@ -0,0 +1,92 @@
+"""Module contains tests for gn3.partial_correlations"""
+
+from unittest import TestCase
+from gn3.partial_correlations import export_informative
+
+class TestPartialCorrelations(TestCase):
+ """Class for testing partial correlations computation functions"""
+
+ def test_export_informative(self):
+ """Test that the function exports appropriate data."""
+ for trait_data, inc_var, expected in [
+ [{"data": {
+ "sample1": {
+ "sample_name": "sample1", "value": 9, "variance": None,
+ "ndata": 13
+ },
+ "sample2": {
+ "sample_name": "sample2", "value": 8, "variance": None,
+ "ndata": 13
+ },
+ "sample3": {
+ "sample_name": "sample3", "value": 7, "variance": None,
+ "ndata": 13
+ },
+ "sample4": {
+ "sample_name": "sample4", "value": 6, "variance": None,
+ "ndata": 13
+ },
+ }}, 0, (
+ ("sample1", "sample2", "sample3", "sample4"), (9, 8, 7, 6),
+ (None, None, None, None))],
+ [{"data": {
+ "sample1": {
+ "sample_name": "sample1", "value": 9, "variance": None,
+ "ndata": 13
+ },
+ "sample2": {
+ "sample_name": "sample2", "value": 8, "variance": None,
+ "ndata": 13
+ },
+ "sample3": {
+ "sample_name": "sample3", "value": None, "variance": None,
+ "ndata": 13
+ },
+ "sample4": {
+ "sample_name": "sample4", "value": 6, "variance": None,
+ "ndata": 13
+ },
+ }}, 0, (
+ ("sample1", "sample2", "sample4"), (9, 8, 6),
+ (None, None, None))],
+ [{"data": {
+ "sample1": {
+ "sample_name": "sample1", "value": 9, "variance": None,
+ "ndata": 13
+ },
+ "sample2": {
+ "sample_name": "sample2", "value": 8, "variance": None,
+ "ndata": 13
+ },
+ "sample3": {
+ "sample_name": "sample3", "value": 7, "variance": None,
+ "ndata": 13
+ },
+ "sample4": {
+ "sample_name": "sample4", "value": 6, "variance": None,
+ "ndata": 13
+ },
+ }}, True, (tuple(), tuple(), tuple())],
+ [{"data": {
+ "sample1": {
+ "sample_name": "sample1", "value": 9, "variance": None,
+ "ndata": 13
+ },
+ "sample2": {
+ "sample_name": "sample2", "value": 8, "variance": 0.657,
+ "ndata": 13
+ },
+ "sample3": {
+ "sample_name": "sample3", "value": 7, "variance": None,
+ "ndata": 13
+ },
+ "sample4": {
+ "sample_name": "sample4", "value": 6, "variance": None,
+ "ndata": 13
+ },
+ }}, 0, (
+ ("sample1", "sample2", "sample3", "sample4"), (9, 8, 7, 6),
+ (None, 0.657, None, None))]]:
+ with self.subTest(trait_data=trait_data):
+ self.assertEqual(
+ export_informative(trait_data, inc_var), expected)