aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-09-23 03:45:19 +0300
committerFrederick Muriuki Muriithi2021-09-23 03:45:19 +0300
commit95c5c0e73bffbf0287a17309e703063ee54d25ba (patch)
tree23c3197072d19f4aa9bbb80023ca31780235207b
parent56c73324c285d896567268370f3955bbd15754b0 (diff)
downloadgenenetwork3-95c5c0e73bffbf0287a17309e703063ee54d25ba.tar.gz
Refactor: Move common sample data to separate file
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/clustering.gmi * Move common sample test data into a separate file where it can be imported from, to prevent pylint error R0801 which proved tricky to silence in any other way.
-rw-r--r--tests/unit/computations/test_qtlreaper.py68
-rw-r--r--tests/unit/db/test_traits.py15
-rw-r--r--tests/unit/sample_test_data.py111
-rw-r--r--tests/unit/test_heatmaps.py96
4 files changed, 134 insertions, 156 deletions
diff --git a/tests/unit/computations/test_qtlreaper.py b/tests/unit/computations/test_qtlreaper.py
index d420470..742d106 100644
--- a/tests/unit/computations/test_qtlreaper.py
+++ b/tests/unit/computations/test_qtlreaper.py
@@ -4,6 +4,7 @@ from gn3.computations.qtlreaper import (
parse_reaper_main_results,
organise_reaper_main_results,
parse_reaper_permutation_results)
+from tests.unit.sample_test_data import organised_trait_1
class TestQTLReaper(TestCase):
"""Class for testing qtlreaper interface functions."""
@@ -81,99 +82,54 @@ class TestQTLReaper(TestCase):
self.assertEqual(
organise_reaper_main_results([
{
- "ID": "T1", "Locus": "rs31443144", "Chr": 1, "cM": 1.500,
+ "ID": "1", "Locus": "rs31443144", "Chr": 1, "cM": 1.500,
"Mb": 3.010, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs6269442", "Chr": 1, "cM": 1.500,
+ "ID": "1", "Locus": "rs6269442", "Chr": 1, "cM": 1.500,
"Mb": 3.492, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs32285189", "Chr": 1, "cM": 1.630,
+ "ID": "1", "Locus": "rs32285189", "Chr": 1, "cM": 1.630,
"Mb": 3.511, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs258367496", "Chr": 1, "cM": 1.630,
+ "ID": "1", "Locus": "rs258367496", "Chr": 1, "cM": 1.630,
"Mb": 3.660, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs32430919", "Chr": 1, "cM": 1.750,
+ "ID": "1", "Locus": "rs32430919", "Chr": 1, "cM": 1.750,
"Mb": 3.777, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs36251697", "Chr": 1, "cM": 1.880,
+ "ID": "1", "Locus": "rs36251697", "Chr": 1, "cM": 1.880,
"Mb": 3.812, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs30658298", "Chr": 1, "cM": 2.010,
+ "ID": "1", "Locus": "rs30658298", "Chr": 1, "cM": 2.010,
"Mb": 4.431, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs51852623", "Chr": 2, "cM": 2.010,
+ "ID": "1", "Locus": "rs51852623", "Chr": 2, "cM": 2.010,
"Mb": 4.447, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs31879829", "Chr": 2, "cM": 2.140,
+ "ID": "1", "Locus": "rs31879829", "Chr": 2, "cM": 2.140,
"Mb": 4.519, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
},
{
- "ID": "T1", "Locus": "rs36742481", "Chr": 2, "cM": 2.140,
+ "ID": "1", "Locus": "rs36742481", "Chr": 2, "cM": 2.140,
"Mb": 4.776, "LRS": 0.500, "Additive": -0.074,
"pValue": 1.000
}
]),
- {"T1": {"ID": "T1",
- "chromosomes": {
- 1: {"Chr": 1,
- "loci": [
- {
- "Locus": "rs31443144", "cM": 1.500, "Mb": 3.010,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs6269442", "cM": 1.500, "Mb": 3.492,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs32285189", "cM": 1.630, "Mb": 3.511,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs258367496", "cM": 1.630, "Mb": 3.660,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs32430919", "cM": 1.750, "Mb": 3.777,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs36251697", "cM": 1.880, "Mb": 3.812,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs30658298", "cM": 2.010, "Mb": 4.431,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- }]},
- 2: {"Chr": 2,
- "loci": [
- {
- "Locus": "rs51852623", "cM": 2.010, "Mb": 4.447,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs31879829", "cM": 2.140, "Mb": 4.519,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs36742481", "cM": 2.140, "Mb": 4.776,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- }]}}}})
+ organised_trait_1)
diff --git a/tests/unit/db/test_traits.py b/tests/unit/db/test_traits.py
index baa2af3..8af8e82 100644
--- a/tests/unit/db/test_traits.py
+++ b/tests/unit/db/test_traits.py
@@ -170,12 +170,15 @@ class TestTraitsDBFunctions(TestCase):
db_mock = mock.MagicMock()
STRAIN_ID_SQL: str = "UPDATE Strain SET Name = %s WHERE Id = %s"
- PUBLISH_DATA_SQL: str = ("UPDATE PublishData SET value = %s "
- "WHERE StrainId = %s AND Id = %s")
- PUBLISH_SE_SQL: str = ("UPDATE PublishSE SET error = %s "
- "WHERE StrainId = %s AND DataId = %s")
- N_STRAIN_SQL: str = ("UPDATE NStrain SET count = %s "
- "WHERE StrainId = %s AND DataId = %s")
+ PUBLISH_DATA_SQL: str = (
+ "UPDATE PublishData SET value = %s "
+ "WHERE StrainId = %s AND Id = %s")
+ PUBLISH_SE_SQL: str = (
+ "UPDATE PublishSE SET error = %s "
+ "WHERE StrainId = %s AND DataId = %s")
+ N_STRAIN_SQL: str = (
+ "UPDATE NStrain SET count = %s "
+ "WHERE StrainId = %s AND DataId = %s")
with db_mock.cursor() as cursor:
type(cursor).rowcount = 1
diff --git a/tests/unit/sample_test_data.py b/tests/unit/sample_test_data.py
new file mode 100644
index 0000000..407d074
--- /dev/null
+++ b/tests/unit/sample_test_data.py
@@ -0,0 +1,111 @@
+"""
+This module holds a collection of sample data variables, used in more than one
+ test.
+
+This is mostly to avoid the `duplicate-code` pylint error that gets raised if
+the same data is defined in more than one file. It has been found that adding
+the `# pylint: disable=R0801` or `# pylint: disable=duplicate-code` to the top
+of the file seems to not work as expected.
+
+Adding these same declarations to .pylintrc is not an option, since that,
+seemingly, would deactivate the warnings for all code in the project: We do not
+want that.
+"""
+
+organised_trait_1 = {
+ "1": {
+ "ID": "1",
+ "chromosomes": {
+ 1: {"Chr": 1,
+ "loci": [
+ {
+ "Locus": "rs31443144", "cM": 1.500, "Mb": 3.010,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs6269442", "cM": 1.500, "Mb": 3.492,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs32285189", "cM": 1.630, "Mb": 3.511,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs258367496", "cM": 1.630, "Mb": 3.660,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs32430919", "cM": 1.750, "Mb": 3.777,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs36251697", "cM": 1.880, "Mb": 3.812,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs30658298", "cM": 2.010, "Mb": 4.431,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ }]},
+ 2: {"Chr": 2,
+ "loci": [
+ {
+ "Locus": "rs51852623", "cM": 2.010, "Mb": 4.447,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs31879829", "cM": 2.140, "Mb": 4.519,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs36742481", "cM": 2.140, "Mb": 4.776,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ }]}}}}
+
+organised_trait_2 = {
+ "2": {
+ "ID": "2",
+ "chromosomes": {
+ 1: {"Chr": 1,
+ "loci": [
+ {
+ "Locus": "rs31443144", "cM": 1.500, "Mb": 3.010,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs6269442", "cM": 1.500, "Mb": 3.492,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs32285189", "cM": 1.630, "Mb": 3.511,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs258367496", "cM": 1.630, "Mb": 3.660,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs32430919", "cM": 1.750, "Mb": 3.777,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs36251697", "cM": 1.880, "Mb": 3.812,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs30658298", "cM": 2.010, "Mb": 4.431,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ }]},
+ 2: {"Chr": 2,
+ "loci": [
+ {
+ "Locus": "rs51852623", "cM": 2.010, "Mb": 4.447,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs31879829", "cM": 2.140, "Mb": 4.519,
+ "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
+ },
+ {
+ "Locus": "rs36742481", "cM": 2.140, "Mb": 4.776,
+ "LRS": 0.579, "Additive": -0.074, "pValue": 1.000
+ }]}}}}
diff --git a/tests/unit/test_heatmaps.py b/tests/unit/test_heatmaps.py
index c0a496b..fd91cf9 100644
--- a/tests/unit/test_heatmaps.py
+++ b/tests/unit/test_heatmaps.py
@@ -7,6 +7,7 @@ from gn3.heatmaps import (
compute_traits_order,
retrieve_strains_and_values,
process_traits_data_for_heatmap)
+from tests.unit.sample_test_data import organised_trait_1, organised_trait_2
strainlist = ["B6cC3-1", "BXD1", "BXD12", "BXD16", "BXD19", "BXD2"]
trait_data = {
@@ -206,100 +207,7 @@ class TestHeatmap(TestCase):
"""Check for correct processing of data for heatmap generation."""
self.assertEqual(
process_traits_data_for_heatmap(
- {"1": {
- "ID": "T1",
- "chromosomes": {
- 1: {"Chr": 1,
- "loci": [
- {
- "Locus": "rs31443144", "cM": 1.500, "Mb": 3.010,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs6269442", "cM": 1.500, "Mb": 3.492,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs32285189", "cM": 1.630, "Mb": 3.511,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs258367496", "cM": 1.630, "Mb": 3.660,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs32430919", "cM": 1.750, "Mb": 3.777,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs36251697", "cM": 1.880, "Mb": 3.812,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs30658298", "cM": 2.010, "Mb": 4.431,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- }]},
- 2: {"Chr": 2,
- "loci": [
- {
- "Locus": "rs51852623", "cM": 2.010, "Mb": 4.447,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs31879829", "cM": 2.140, "Mb": 4.519,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs36742481", "cM": 2.140, "Mb": 4.776,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- }]}}},
- "2": {
- "ID": "T1",
- "chromosomes": {
- 1: {"Chr": 1,
- "loci": [
- {
- "Locus": "rs31443144", "cM": 1.500, "Mb": 3.010,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs6269442", "cM": 1.500, "Mb": 3.492,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs32285189", "cM": 1.630, "Mb": 3.511,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs258367496", "cM": 1.630, "Mb": 3.660,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs32430919", "cM": 1.750, "Mb": 3.777,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs36251697", "cM": 1.880, "Mb": 3.812,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs30658298", "cM": 2.010, "Mb": 4.431,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- }]},
- 2: {"Chr": 2,
- "loci": [
- {
- "Locus": "rs51852623", "cM": 2.010, "Mb": 4.447,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs31879829", "cM": 2.140, "Mb": 4.519,
- "LRS": 0.500, "Additive": -0.074, "pValue": 1.000
- },
- {
- "Locus": "rs36742481", "cM": 2.140, "Mb": 4.776,
- "LRS": 0.579, "Additive": -0.074, "pValue": 1.000
- }]}}}},
+ {**organised_trait_1, **organised_trait_2},
["2", "1"],
[1, 2]),
[[[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5],