aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/db
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-18 12:27:32 +0300
committerFrederick Muriuki Muriithi2021-10-18 12:27:32 +0300
commit94ca79045baf978d6aab964c7c70b84911c1124f (patch)
tree35627e25d9d7073c9c06258e3fafb114b69e9dd4 /tests/unit/db
parent157df453cdb84591cb44af9f1d2677cd0b2c0380 (diff)
downloadgenenetwork3-94ca79045baf978d6aab964c7c70b84911c1124f.tar.gz
Move `export_informative` function to `gn3.db.traits` module
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/db/traits.py: Move `export_informative` function here * gn3/partial_correlations.py: Remove `export_informative` function * tests/unit/db/test_traits.py: Move `export_informative` function tests here * tests/unit/test_partial_correlations.py: Remove `export_informative` function tests The `export_informative` function relates more to the traits than to the partial correlations, and could find use in more than just the partial correlations stuff. This commit moves the function to the more traits-specific `gn3.db.traits` module.
Diffstat (limited to 'tests/unit/db')
-rw-r--r--tests/unit/db/test_traits.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/unit/db/test_traits.py b/tests/unit/db/test_traits.py
index 0c4ef78..67f0c6f 100644
--- a/tests/unit/db/test_traits.py
+++ b/tests/unit/db/test_traits.py
@@ -3,6 +3,7 @@ from unittest import mock, TestCase
from gn3.db.traits import (
build_trait_name,
export_trait_data,
+ export_informative,
set_haveinfo_field,
update_sample_data,
retrieve_trait_info,
@@ -315,3 +316,88 @@ class TestTraitsDBFunctions(TestCase):
trait_data, samplelist, dtype=dtype, var_exists=vflag,
n_exists=nflag),
expected)
+
+ 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)