aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2021-02-18 16:45:30 +0300
committerBonfaceKilz2021-02-24 14:20:29 +0300
commit96bc4c74f2e5b7a8ffa2bf25bdb6680197fd53ed (patch)
treee5c9e668eabfdf583a3612972d607f756932c213
parent234864dd171c1a1c42da3ac9cca40dd65984081a (diff)
downloadgenenetwork3-96bc4c74f2e5b7a8ffa2bf25bdb6680197fd53ed.tar.gz
Create a new method for generating a valid phenotype file on the fly
-rw-r--r--gn3/computations/__init__.py0
-rw-r--r--gn3/computations/gemma.py14
-rw-r--r--tests/unit/computations/__init__.py0
-rw-r--r--tests/unit/computations/test_gemma.py24
4 files changed, 38 insertions, 0 deletions
diff --git a/gn3/computations/__init__.py b/gn3/computations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gn3/computations/__init__.py
diff --git a/gn3/computations/gemma.py b/gn3/computations/gemma.py
new file mode 100644
index 0000000..9a972ba
--- /dev/null
+++ b/gn3/computations/gemma.py
@@ -0,0 +1,14 @@
+"""Procedures related gemma computations"""
+
+
+def generate_pheno_txt_file(trait_filename: str,
+ values: str,
+ tmpdir: str = "/tmp") -> str:
+ """Given VALUES, and TMPDIR, generate a valide traits file"""
+ with open(f"{tmpdir}/gn2/{trait_filename}", "w") as _file:
+ for value in values:
+ if value == "x":
+ _file.write("NA\n")
+ else:
+ _file.write(f"{value}\n")
+ return f"{tmpdir}/gn2/{trait_filename}"
diff --git a/tests/unit/computations/__init__.py b/tests/unit/computations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/unit/computations/__init__.py
diff --git a/tests/unit/computations/test_gemma.py b/tests/unit/computations/test_gemma.py
new file mode 100644
index 0000000..89c8d00
--- /dev/null
+++ b/tests/unit/computations/test_gemma.py
@@ -0,0 +1,24 @@
+"""Test cases for procedures defined in computations.gemma"""
+import unittest
+
+from unittest import mock
+from gn3.computations.gemma import generate_pheno_txt_file
+
+
+class TestGemma(unittest.TestCase):
+ """Test cases for computations.gemma module"""
+
+ def test_generate_pheno_txt_file(self):
+ """Test that the pheno text file is generated correctly"""
+ open_mock = mock.mock_open()
+ with mock.patch("gn3.computations.gemma.open",
+ open_mock, create=True):
+ _file = generate_pheno_txt_file(tmpdir="/tmp",
+ trait_filename="phenotype.txt",
+ values=["x", "x", "BXD07 438.700"])
+ self.assertEqual(_file, "/tmp/gn2/phenotype.txt")
+ open_mock.assert_called_with("/tmp/gn2/phenotype.txt", "w")
+ open_mock.return_value.write.assert_has_calls([
+ mock.call("NA\n"),
+ mock.call("NA\n"),
+ mock.call("BXD07 438.700\n")])